2009年5月1日 星期五

關閉linux下討厭的蜂鳴器

當我們使用虛擬終端機(console)時候,常常聽到蜂鳴器討人厭的聲音
是否想關掉他呢?以下是關閉蜂鳴器的方法:

方案一: 移除kernel模組 pcspkr

sudo rmmod pcspkr


pcspkr全名為pc speaker,是負責管理蜂鳴器的模組,此方法只在關機前有效
重開後必須再手動一次

方案二:預設不載入pcspkr模組
Gentoo/Sabayon/Debian/Ubuntu Linux

sudo echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist



Redhat/CentOS/RHEL/Fedora

sudo echo "blacklist pcspkr" >> /etc/modprobe.conf


這方法就是告訴kernel不載入此模組,請挑選自己的發行版做設定

方案三: 設定shell不要亂叫

echo "setterm -blength 0" >> ~/.bash_profile


這裡以Bash為例,簡單說就是放到profile,當bash啟動讀到profile時,會知道你要他閉嘴

總結:其實個人認為方案三最佳....

2009年4月13日 星期一

1.2 用 graphviz 畫有向圖

有向圖的語法:

digraph name {
......
}



編譯指令:

dot -Tpng xxx.dot > xxx.png


其中 -Tpng 指輸出成PNG的格式

範例:

digraph flow {
"a" -> "b" ;
"a" -> "c" ;

"d" -> "e" ;
"d" -> "f" ;
}


其中 -> 代表有向圖的指向


結果如圖:

1.1 用 graphviz 畫無向圖

無向圖的語法:

graph name {
......
}



編譯指令:

neato -Tpng xxx.dot > xxx.png


其中 -Tpng 指輸出成PNG的格式

範例:

graph flow {
"a" -- "b" ;
"a" -- "c" ;

"d" -- "a" ;
"d" -- "b" ;
}


其中 -- 代表無向圖的聯接


結果如圖:

完整的 鐘樓怪人 Youtube 版

晃 Youtube 時看到的
不知道什麼時候會被移除
根據我看過的印象,非常完整囉~~~

網址:
點我吧,我無毒

在右邊的『全部播放』點一下就會自動播放了

在 emacs 下輸入特殊符號

按下 C-x 8 C-h 可得到以下列表

Key translations Starting With C-x 8:
key binding
--- -------

C-x 8 SPC
C-x 8 ! ¡
C-x 8 " Prefix Command
C-x 8 $ ¤
C-x 8 ' Prefix Command
C-x 8 * Prefix Command
C-x 8 + ±
C-x 8 , Prefix Command
C-x 8 - ­
C-x 8 . ·
C-x 8 / Prefix Command
C-x 8 1 Prefix Command
C-x 8 3 Prefix Command
C-x 8 < « C-x 8 = ¯ C-x 8 > »
C-x 8 ? ¿
C-x 8 C ©
C-x 8 L £
C-x 8 P ¶
C-x 8 R ®
C-x 8 S §
C-x 8 Y ¥
C-x 8 ^ Prefix Command
C-x 8 _ Prefix Command
C-x 8 ` Prefix Command
C-x 8 c ¢
C-x 8 m µ
C-x 8 o °
C-x 8 u µ
C-x 8 x ×
C-x 8 | ¦
C-x 8 ~ Prefix Command

C-x 8 ~ SPC ~
C-x 8 ~ A Ã
C-x 8 ~ D Ð
C-x 8 ~ N Ñ
C-x 8 ~ O Õ
C-x 8 ~ T Þ
C-x 8 ~ a ã
C-x 8 ~ d ð
C-x 8 ~ n ñ
C-x 8 ~ o õ
C-x 8 ~ t þ
C-x 8 ~ ~ ¬

C-x 8 ` SPC `
C-x 8 ` A À
C-x 8 ` E È
C-x 8 ` I Ì
C-x 8 ` O Ò
C-x 8 ` U Ù
C-x 8 ` a à
C-x 8 ` e è
C-x 8 ` i ì
C-x 8 ` o ò
C-x 8 ` u ù

C-x 8 _ a ª
C-x 8 _ o º

C-x 8 ^ SPC ^
C-x 8 ^ 1 ¹
C-x 8 ^ 2 ²
C-x 8 ^ 3 ³
C-x 8 ^ A Â
C-x 8 ^ E Ê
C-x 8 ^ I Î
C-x 8 ^ O Ô
C-x 8 ^ U Û
C-x 8 ^ a â
C-x 8 ^ e ê
C-x 8 ^ i î
C-x 8 ^ o ô
C-x 8 ^ u û

C-x 8 3 / Prefix Command

C-x 8 1 / Prefix Command

C-x 8 / / ÷
C-x 8 / A Å
C-x 8 / E Æ
C-x 8 / O Ø
C-x 8 / a å
C-x 8 / e æ
C-x 8 / o ø

C-x 8 , , ¸
C-x 8 , C Ç
C-x 8 , c ç

C-x 8 ' SPC '
C-x 8 ' ' ´
C-x 8 ' A Á
C-x 8 ' E É
C-x 8 ' I Í
C-x 8 ' O Ó
C-x 8 ' U Ú
C-x 8 ' Y Ý
C-x 8 ' a á
C-x 8 ' e é
C-x 8 ' i í
C-x 8 ' o ó
C-x 8 ' u ú
C-x 8 ' y ý

C-x 8 " SPC "
C-x 8 " " ¨
C-x 8 " A Ä
C-x 8 " E Ë
C-x 8 " I Ï
C-x 8 " O Ö
C-x 8 " U Ü
C-x 8 " a ä
C-x 8 " e ë
C-x 8 " i ï
C-x 8 " o ö
C-x 8 " s ß
C-x 8 " u ü
C-x 8 " y ÿ

C-x 8 * SPC
C-x 8 * ! ¡
C-x 8 * $ ¤
C-x 8 * + ±
C-x 8 * - ­
C-x 8 * . ·
C-x 8 * < « C-x 8 * = ¯ C-x 8 * > »
C-x 8 * ? ¿
C-x 8 * C ©
C-x 8 * L £
C-x 8 * P ¶
C-x 8 * R ®
C-x 8 * S §
C-x 8 * Y ¥
C-x 8 * c ¢
C-x 8 * m µ
C-x 8 * o °
C-x 8 * u µ
C-x 8 * x ×
C-x 8 * | ¦

C-x 8 3 / 4 ¾

C-x 8 1 / 2 ½
C-x 8 1 / 4 ¼


Global Bindings Starting With C-x 8:
key binding
--- -------

C-x 8 RET ucs-insert



按照上面列表提示打就可以輸入特殊字元了

2009年3月22日 星期日

Project Euler 004.c


1 |/*///-----------------------------------------------------------------
2 | * Project Euler Problem 004
3 | * File Name : pe-004.c
4 | * Author : Yen-Chin,Lee
5 | * Email : coldnew.tw@gmail.com
6 | * Create Date : 2009/03/22 14:55:59
7 | * Description : This version I use malloc (though I do not need to use it),
8 | * if you don't know how to use malloc() and free(),
9 | * just remove it and add " char buffer[100] " in this file
10 | *
11 | * Problem :
12 | *
13 | * A palindromic number reads the same both ways.
14 | * The largest palindrome made from the product of two 2-digit numbers
15 | * is 9009 = 91 × 99.
16 | *
17 | * Find the largest palindrome made from the product of two 3-digit numbers.
18 | /*///---------------------------- Copyright (C) ,2009 coldnew --------
19 |
20 | #include <stdio.h>
21 | #include <stdlib.h>
22 | #include <string.h>
23 |
24 |
25 | int isPlain(int testNum)
26 | {
27 | char *buffer = (char *)malloc(sizeof(char) * 100);
28 | if (NULL == buffer) {
29 | fprintf(stderr,"Not enough memory\n");
30 | exit(1);
31 | }
32 |
33 | sprintf(buffer,"%d",testNum);
34 |
35 | int a = 0;
36 | int b = strlen(buffer)-1;
37 |
38 | while (a < b && buffer[a] == buffer[b]) {
39 | a++;
40 | b--;
41 | }
42 | free(buffer);
43 |
44 | return (a >= b);
45 | }
46 |
47 | int main( int argc, char **argv)
48 | {
49 | int i,j,k;
50 | int maxNum=0;
51 | for (i = 1;i < 1000;i++) {
52 | for (j = 1;j < 1000; j++) {
53 | k = i*j;
54 | if (k > maxNum && isPlain(k)) {
55 | maxNum = k;
56 | }
57 | }
58 | }
59 | printf("max=%d ",maxNum);
60 |
61 | return 0;
62 | }
63 |

2009年3月21日 星期六

Project Euler 003-1.c


  1 |  /*///-----------------------------------------------------------------
  2 |   *  Project Euler Problem 003
  3 |   *  File Name   : pe-003-1.c
  4 |   *  Author      : Yen-Chin,Lee
  5 |   *  Email       : coldnew.tw@gmail.com
  6 |   *  Create Date : 2009/03/21 19:05:37
  7 |   *  Description : The same way as pe-003.c without use c99 standard
  8 |   *                and stdbool.h
  9 |   *  Compile Opt : gcc pe-003-1.c -o 003-1
 10 |   *  
 11 |   *  Problem :
 12 |   *
 13 |   *  The prime factors of 13195 are 5, 7, 13 and 29.
 14 |   *  What is the largest prime factor of the number 600851475143 ?
 15 |  /*///---------------------------- Copyright (C) ,2009 coldnew --------
 16 |  
 17 |  #include <stdio.h>
 18 |  #include <stdlib.h>
 19 |  
 20 |  short isPrime (unsigned long long testNum)
 21 |  {
 22 |          int i = 2;
 23 |          if (1 == testNum){
 24 |                  return 0;
 25 |          }
 26 |          for(i =2 ; i <= (testNum / 2) ; i++){
 27 |                  if (0 == testNum % i) {
 28 |                          return 0;
 29 |                  } else {
 30 |                          return 1;
 31 |                  }                
 32 |          }
 33 |  }
 34 |  
 35 |  int main( int argc, char **argv)
 36 |  {
 37 |          int i = 2;
 38 |          unsigned long long num = 600851475143;
 39 |          unsigned long long max = 0;
 40 |  
 41 |          for(i = 2 ; (i * i) <= num ; i++){
 42 |                  if (0 ==  (num % i)) {
 43 |                          if (isPrime(i)) {
 44 |                                  if (i > max) {
 45 |                                          max = i;
 46 |                                  }
 47 |                          }
 48 |                  }
 49 |          }
 50 |          printf("The largest prime factor is %llu",max);
 51 |  
 52 |          return 0;
 53 |  }
 54 |  


Project Euler 003.c


  1 |  /*///-----------------------------------------------------------------
  2 |   *  Project Euler Problem 003
  3 |   *  File Name   : pe-003.c
  4 |   *  Author      : Yen-Chin,Lee
  5 |   *  Email       : coldnew.tw@gmail.com
  6 |   *  Create Date : 2009/03/21 19:05:37
  7 |   *  Description :
  8 |   *  Compile Opt : gcc pe-003.c -std=c99 -o 003
  9 |   *  Problem :
 10 |   *
 11 |   *  The prime factors of 13195 are 5, 7, 13 and 29.
 12 |   *  What is the largest prime factor of the number 600851475143 ?
 13 |  /*///---------------------------- Copyright (C) ,2009 coldnew --------
 14 |  
 15 |  #include <stdio.h>
 16 |  #include <stdlib.h>
 17 |  #include <stdbool.h>
 18 |  
 19 |  bool isPrime (unsigned long long testNum)
 20 |  {
 21 |          if (1 == testNum){
 22 |                  return false;
 23 |          }
 24 |          for(int i =2 ; i <= (testNum / 2) ; i++){
 25 |                  if (0 == testNum % i) {
 26 |                          return false;
 27 |                  } else {
 28 |                          return true;
 29 |                  }                
 30 |          }
 31 |  }
 32 |  
 33 |  int main( int argc, char **argv)
 34 |  {
 35 |          unsigned long long num = 600851475143;
 36 |          unsigned long long max = 0;
 37 |  
 38 |          for(int i = 2 ; (i * i) <= num ; i++){
 39 |                  if (0 ==  (num % i)) {
 40 |                          if (isPrime(i)) {
 41 |                                  if (i > max) {
 42 |                                          max = i;
 43 |                                  }
 44 |                          }
 45 |                  }
 46 |          }
 47 |          printf("The largest prime factor is %llu",max);
 48 |  
 49 |          return 0;
 50 |  }
 51 |  


2009年3月19日 星期四

Project Euler 002-1.c


1 | /*///-----------------------------------------------------------------
2 | * Project Euler Problem 002
3 | * File Name : pe-002-1.c
4 | * Author : Yen-Chin,Lee
5 | * Email : coldnew.tw@gmail.com
6 | * Create Date : 2009/03/19 16:06:04
7 | * Description : A better way than pe-002.c
8 | *
9 | * Problem :
10 | *
11 | * Each new term in the Fibonacci sequence is generated by adding
12 | * the previous two terms.
13 | * By starting with 1 and 2, the first 10 terms will be:
14 | * 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
15 | * Find the sum of all the even-valued terms in the sequence
16 | * which do not exceed four million.
17 | /*///---------------------------- Copyright (C) ,2009 coldnew --------
18 |
19 | #include <stdio.h>
20 | #include <stdlib.h>
21 |
22 | int main( int argc, char **argv)
23 | {
24 | int sum = 0;
25 | int x = 1, y = 1;
26 | int xtmp = 0 , ytmp = 0;
27 |
28 | while (sum < 4000000) {
29 | sum += x + y;
30 | xtmp = x + y*2;
31 | ytmp = x*2 + y*3;
32 | x = xtmp;
33 | y = ytmp;
34 | }
35 | printf("Sum = %d",sum);
36 | return 0;
37 | }
38 |

Project Euler 002.c


  1 |  /*///-----------------------------------------------------------------
  2 |   *  Project Euler Problem 002
  3 |   *  File Name   : pe-002.c
  4 |   *  Author      : Yen-Chin,Lee
  5 |   *  Email       : coldnew.tw@gmail.com
  6 |   *  Create Date : 2009/03/19 15:54:41
  7 |   *  Description :
  8 |   *
  9 |   *  Problem     :
 10 |   *  
 11 |   *  Each new term in the Fibonacci sequence is generated by  adding
 12 |   *  the previous two terms.
 13 |   *  By starting with 1 and 2, the first 10 terms will be:
 14 |   *        1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
 15 |   *  Find the sum of all the even-valued terms in the sequence
 16 |   *  which do not exceed four million.
 17 |  /*///---------------------------- Copyright (C) ,2009 coldnew --------
 18 |  
 19 |  #include <stdio.h>
 20 |  #include <stdlib.h>
 21 |  int Fib(int x)
 22 |  {
 23 |          if (1 == x)  return 1;
 24 |          if (2 == x)  return 2;
 25 |          else         return Fib(x-1) + Fib(x-2);
 26 |          
 27 |  }
 28 |  
 29 |  int main( int argc, char **argv)
 30 |  {
 31 |          int sum = 0;
 32 |          int i=1;
 33 |          
 34 |          while (1) {
 35 |                  if (0 == Fib(i) % 2) {
 36 |                          if (sum > 4000000) {
 37 |                                  printf("Sum = %d",sum);
 38 |                                  break;
 39 |                          } else {
 40 |                                  sum += Fib(i);
 41 |                          }
 42 |                  }
 43 |                  i++;      
 44 |          }
 45 |          return 0;
 46 |  }

Project Euler 001.c


  1 |  /*///-----------------------------------------------------------------
  2 |   *  Project Euler Problem 001
  3 |   *  File Name   : pe-001.c
  4 |   *  Author      : Yen-Chin,Lee
  5 |   *  Email       : coldnew.tw@gmail.com
  6 |   *  Create Date : 2009/03/12 18:22:32
  7 |   *  Description :
  8 |   *
  9 |   *  Problem     :
 10 |   *
 11 |   *  If we list all the natural numbers below 10 that are multiples
 12 |   *  of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
 13 |   *
 14 |   *  Find the sum of all the multiples of 3 or 5 below 1000.
 15 |   *
 16 |  /*///---------------------------- Copyright (C) ,2009 coldnew --------
 17 |  
 18 |  #include <stdio.h>
 19 |  #include <stdlib.h>
 20 |  
 21 |  int main( int argc, char **argv)
 22 |  {
 23 |          int i = 0;
 24 |          int sum = 0;
 25 |          for ( i = 0; i < 1000; i++) {
 26 |                  if (0 == i % 3 || 0 == i % 5 ) {
 27 |                          sum += i;
 28 |                  }
 29 |                          
 30 |          }
 31 |          printf("%d",sum);
 32 |       return 0;
 33 |  }
 34 |  

2009年3月6日 星期五

使用 getdelta 來減少下載至本地的原始碼大小

getdelta 是一款基於名為 deltup 的軟體,可以提供比較2個檔案的不同並進行存取,有點像 diff 和 patch ,但是是用於2進至檔案如 tar.gz 等壓縮檔。

deltup 很適合用於升級本地的原始碼,因為每個不同版本的更新,很可能只是有一小部份的程式碼不同,所以升級 foobar-0.1 至 foobar-0.2 只需要下載小小的 diff 檔案而不用下載完整的原始碼。
以 nano 為例

# emerge -u nano

These are the packages that would be merged, in order:

Calculating dependencies... done!

>>> Verifying ebuild manifests

>>> Emerging (1 of 1) app-editors/nano-2.1.9
>>> Downloading 'http://distfiles.gentoo.org/distfiles/nano-2.1.9.tar.gz'
Searching for a previously downloaded file in /usr/portage/distfiles

We have the following candidates to choose from
nano-2.1.7.tar.gz

The best of all is ... nano-2.1.7.tar.gz

Checking if this file is OK.

Trying to download nano-2.1.7.tar.gz-nano-2.1.9.tar.gz.dtu

--2009-03-07 09:12:03-- http://linux01.gwdg.de/~nlissne/deltup.php?have=nano-2.1.7.tar.gz&want=nano-2.1.9.tar.gz&url=http://www.nano-editor.org/dist/v2.1/nano-2.1.9.tar.gz&version=0.7&time=1236388323
Resolving linux01.gwdg.de... 134.76.13.21
Connecting to linux01.gwdg.de|134.76.13.21|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://dev.gentooexperimental.org/deltup/nano-2.1.7.tar.gz-nano-2.1.9.tar.gz.dtu [following]
--2009-03-07 09:12:05-- http://dev.gentooexperimental.org/deltup/nano-2.1.7.tar.gz-nano-2.1.9.tar.gz.dtu
Resolving dev.gentooexperimental.org... 81.93.240.53
Connecting to dev.gentooexperimental.org|81.93.240.53|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 88553 (86K) [application/octet-stream]
Saving to: `nano-2.1.7.tar.gz-nano-2.1.9.tar.gz.dtu'

100%[================================================================================>] 88,553 117K/s in 0.7s

2009-03-07 09:12:23 (117 KB/s) - `nano-2.1.7.tar.gz-nano-2.1.9.tar.gz.dtu' saved [88553/88553]

GOT nano-2.1.7.tar.gz-nano-2.1.9.tar.gz.dtu

Successfully fetched the dtu-file - let's build nano-2.1.9.tar.gz...

nano-2.1.7.tar.gz -> nano-2.1.9.tar.gz: OK
cleaning up
This dtu-file saved 1 MB (94%) download size.
* nano-2.1.9.tar.gz RMD160 SHA1 SHA256 size ;-) ... [ ok ]
* checking ebuild checksums ;-) ... [ ok ]
* checking auxfile checksums ;-) ... [ ok ]
* checking miscfile checksums ;-) ... [ ok ]

我們可以很清楚看到,如果他有找到 xxx.dtu 檔案(2進至的diff檔),會自動下載該檔案
以此範例來看,我們總共減少了1MB的下載量

2009年2月28日 星期六

更改Octave裡plot出來的背景顏色

因為Octave是調用GNU plot 來繪圖的,所以其實就是更改GNU plot 的顏色
步驟如下:

echo "gnuplot*background: white" >> ~/.Xresources

然後在用以下指令更新 .Xresources

xrdb -merge ~/.Xresources

好了,現在Octave話出來的圖背景顏色就是白色囉

2009年2月13日 星期五

安裝Gentoo linux on ASUS F6V (fingerprint)

lsusb
Bus 005 Device 002: ID 08ff:1600 AuthenTec, Inc.

為 AuthenTec aes1610 fingerprint reader.

The libraries and software for this model are still in an overlay, so installing them may be a bit involved. One can use the howto in the Asus M50SV fingerprint section to get the reader working for the tx2108ca.

As of July 12 2008, the aes1610 only works with the 0.0.x series of libfprint, not the 9999 series which is actually built from the latest source from git(a CVS-like system). The aes1610 driver has not yet been converted to the newer driver model. The combination of =app-misc/fprint_demo-0.4, =sys-auth/pam_fprint-0.2, and =media-libs/libfprint-0.0.5 works for fingerprint authentication.

安裝Gentoo linux on ASUS F6V (webcam)

Webcam
指令 : lsusb

Bus 002 Device 002: ID 04f2:b029 Chicony Electronics Co., Ltd

The webcam is fully supported by the Linux UVC driver and works like a charm! First make sure you have the appropriate kernel settings:
Linux Kernel Configuration: 2.6.24-tuxonice-r5 (tuxonice-sources)

Device Drivers --->
Multimedia Devices --->
<*> Video For Linux
[ ] Enable Video For Linux API 1 (DEPRECATED)
[ ] Enable Video For Linux API 1 compatible Layer
[*] Video capture adapters --->
[*] V4L USB devices

Last but not least add the uvcvideo-module to /etc/modules.autoload.d/kernel-2.6 to make sure it gets loaded when you boot. Optionally you can add v4l2 to /etc/make.conf.

2008年7月11日 星期五

給Gentoo bugzilla用的Firefox搜尋Plugin

切換到mozilla-firefox的目錄

#cd /usr/lib/mozilla-firefox/searchplugins

從Mozilla的搜尋Plugin檔案庫中下載兩個檔案。
#wget http://mycroft.mozdev.org/plugins/Gentoo-Bugs.{src,png}

done

http://mycroft.mozdev.org/search-engines.html?name=gentoo&submitform=Search

2008年6月3日 星期二

* gcc-config: Active gcc profile is invalid! 要怎麼辦?

首先先察看gcc 有的profile

gcc-config -l

顯示結果是:
* gcc-config: Active gcc profile is invalid!
[1] x86_64-pc-linux-gnu-4.2.4 *

使用新的profile就ok了

sudo gcc-config x86_64-pc-linux-gnu-4.2.4

2008年6月1日 星期日

gentoo-taiwan 的 overlay 連不上怎麽辦?

連不上應該是DNS解析不了,只要在 /etc/hosts 加上
163.32.119.161 wiki.gentoo.tw forums.gentoo.tw rsync.gentoo.tw
就ok了

代碼:

sudo echo "
163.32.119.161 wiki.gentoo.tw forums.gentoo.tw rsync.gentoo.tw" >> /etc/hosts

2008年4月18日 星期五

avi2mpg -- 將avi檔轉換成mpg


#!/bin/bash
#將目前路徑存入 current_directory 變數中
current_directory=$(pwd)

#檔名處理: 將空白字元替換成底線 ( _ )
for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done 2> /dev/null

#檔名處理: 將大寫字元轉成小寫
for i in *.[Ww][Mm][Aa]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done 2> /dev/null

for i in *.avi;do ffmpeg -i $i -target vcd $i.mpg ;done

2008年4月13日 星期日

mpg2mp4 --將mpg轉成mp4編碼的shell


#/bin/bash
function mpg2mp4_fun
{
VBITRATE=500

mencoder "$1" -ovc frameno -o frameno.avi -oac mp3lame -lameopts vbr=3
mencoder "$1" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$VBITRATE:vpass=1 -oac copy -o "$2"
mencoder "$1" -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$VBITRATE:vpass=2 -oac copy -o "$2"

rm -f frameno.avi
rm -f *.log
}

for i in *.[Mm][Pp][Gg]
do
mpg2mp4_fun "$i" "${i/.[Mm][Pp][Gg]/.mp4}"
rm "$i"
done