2011年2月25日 星期五

[linux][C/C++]input and output part1

//2011/02/25 point day8
//create by lichain
#include <iostream>
using namespace std;
 
int main(int argc, char *argv[])
{
        const int bufferSize=4;
        char buffer[bufferSize +1];
        char word[bufferSize +1];
        int wordOffset=0;
        
        cout << "Enter a string: " ;
        //cin.getline(buffer,5);
        cin >> word;
        
        cout << "word is " << word << "\n";
                        
        return 0;
        

}

[linux][C/C++]Command_line argument

//2011/02/25 point day8
//create by lichain
#include <iostream>
using namespace std;
 
int main(int argc, char *argv[])
{

        cout << "argument count is " << argc << "\n";
        
        for(int i = 0; i < argc; i++) {
                char *arg = argv[i];
                cout << "arg[" << i  <<"] is " << argv[i] << "\n";
                
            /*switch(arg[0]) { 
                case '-': 
                    // 處理參數,設定執行選項,例如-o、-p、-r等等 
                default: */
                    // 執行對應功能 
            }         
        return 0;
}

[linux][day 8][Pointer]C++

//2011/02/25 point day8
//create by lichain
#include <iostream>
 using namespace std;
 
int main(void)
{
        int a = 12;
        int b = 24;
        cout << "===================================\n";
        cout << "variable a's value is " << a << "\n";
        cout << "variable a's address is " << &a << "\n";
        cout << "variable *&a is " << *&a << "\n";
        cout << "===================================\n";
        cout << "variable b's value is " << b << "\n";
        cout << "variable b's address is " << &b << "\n";
        cout << "variable *&b is " << *&b << "\n";
        cout << "===================================\n\n";
        

        unsigned short int howOld =27;
        unsigned short int *pAge=NULL;
        pAge=&howOld;
        cout << "howOld is " << howOld << "\n";
        //cout << "*howOld is " << *howOld << "\n";
        cout << "&howOld is " << &howOld << "\n";        
        
        cout << "pAge is " << pAge << "\n";
        cout << "*pAge is " << *pAge << "\n";
        cout << "&pAge is " << &pAge << "\n";
        
        cout << "===================================\n";
        
        *pAge=100;        
        
        cout << "howOld is " << howOld << "\n";
        //cout << "*howOld is " << *howOld << "\n";
        cout << "&howOld is " << &howOld << "\n";        
        
        cout << "pAge is " << pAge << "\n";
        cout << "*pAge is " << *pAge << "\n";
        cout << "&pAge is " << &pAge << "\n";
        
        return 0;
}

2011年2月24日 星期四

[perl]References(Pointer)[1]

#!/usr/bin/perl
#2011/02/24
#References(Pointer)
$mytest1="abc1";
$mytest2="abc2";
print "$mytest1\n";
print "$mytest2\n";
print \$mytest1."\n";
print \$mytest2."\n";

[perl]Hash Array(Associative Array)

#!/usr/bin/perl
#2011/02/24
#Hash Array(Associative Array):
#ref http://ind.ntou.edu.tw/~dada/cgi/Perlsynx.htm#hash
# 相關陣列是以 % 符號開頭的。
#my %hash;

# => 這個符號是Perl5新增的,是為了相關陣列量身定做的,
# 因為索引和元素值都是純量,若使用 => 這個符號,
# (索引=>元素值) 兩兩對應,就不容易發生失誤。
#my %hash=("i1"=>"aaa","i2"=>"bbb","i3"=>"ccc");

# 上面這行的效果和下面這行是一樣的。
#my %hash=("i1","aaa","i2","bbb","i3","ccc");

# 下面是存取每個元素的方法,注意是用大括號把索引括起來哦。
# 習慣上索引值用單引號、元素值用雙引號括起來。
# $hash{'i1'}="aaa"; $hash{'i2'}="bbb"; $hash{'i3'}="ccc";
my %hash=("i1"=>"aaa","i2"=>"bbb","i3"=>"ccc");

foreach $key (sort keys %hash){
        print "$hash{$key}\n";
}
#foreach $value (values %hash)
#while(($key,$value)=each %has

[perl]Scalar Array

#!/usr/bin/perl
$i=0;
$array[0]="a"; $array[1]="b"; $array[2]="c"; $array[3]="d";
while ($i<=$#array){
        print "i=$i  array= $array[$i]\n";
        $i++;
}

[Shell]The file exist or not exist.

#!/bin/bash
#2011/02/24
read -p "Input a filename : " filename
test -e ./$filename && echo "exist" || echo "Not exist"

2011年2月23日 星期三

好用的blog code view

ref http://formatmysourcecode.blogspot.com/

[perl]output pattern repeat by input number.

#!/usr/bin/env perl
#input a pattern adn a number
#output pattern repeat by input number.
$shell="clear";
print `$shell`;
print "===============================================\n";
print "2.11[5])\nPlease a patten and anumber.\n";
print "pattern string:";
$pattern=<STDIN>;
print "repeat num:";
$repeat=<STDIN>;
print "output string = \n".$pattern x $repeat ;
print "===============================================\n";

[perl]return num1*num2

#!/usr/bin/env perl
#input two number
#output num1*num2
$shell="clear";
print `$shell`;
print "===============================================\n";
print "2.11[4])\nPlease enter two number.\n";
print "num1:";
$num1=<STDIN>;
print "num2:";
$num2=<STDIN>;
print "output value = num1*num2 = ".$num1*$num2 ."\n";
print "===============================================\n";

[perl]return correct value of Circumfrence of a circle.

#!/usr/bin/env perl
#input radius
#if radius>=0 then return correct value of Circumfrence of a circle.
#else return 0
print "2.11[1])\nPlease enter radius:";
$radius=<STDIN>;
if($radius >= 0){
        $out=$radius *2*3.141592654;
        print "Circumfrence of a circle is:$out\n";
}
else{
        print "Error! return value = 0\n";
}

[perl]Circumfrence of a circle

#!/usr/bin/env perl
#input radius
#output Circumfrence of a circle
print "2.11[1])\nPlease enter radius:";
$radius=<STDIN>;
if($radius >= 0){
        $out=$radius *2*3.141592654;
        print "Circumfrence of a circle is:$out\n";
}
else{
        print "Please enter postive real number.";
}

2011年2月21日 星期一

[mediawiki]Setup Done

[linux][postgres]


postgres@redwing-nb:/$ psql
psql (8.4.7)
Type "help" for help.

postgres=# \du
            List of roles
 Role name | Attributes  | Member of
-----------+-------------+-----------
 postgres  | Superuser   | {}
           : Create role  
           : Create DB    

postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'youepassword';

ALTER ROLE




2011年2月16日 星期三

2011年2月13日 星期日

李開復的10個人生啟發


李開復的10個人生啟發

資料來源:http://jackandroid.javaeye.com/blog/494270




一、自信不失謙虛,謙虛不失自信;

二、興趣就是天賦,天賦就是興趣;

三、思考比傳道更重要,觀點比解惑更重要;

四、我不同意你,但是我支持你;

五、挫折不是懲罰,而是學習的機會;

六、創新不重要,有用的創新才重要;

七、用勇氣改變可以改變的事情,用胸懷接受不能接受的事情,用智慧分辨兩者的不同;

八、求知若飢,虛心若愚;

九、追隨你的心,用它引領你的一生,其他的一切都是次要的;

十、你的價值不是你擁有了多少,而是你留下多少.

2011年2月12日 星期六

夢想

我會一步一步,建築自己的夢想。

漂鳥集- 泰戈爾


漂鳥集:

若你因錯過太陽而流淚,
你也將錯過星辰。

向前走 
別只為了占有而駐足摘花。
因為一路上花兒自會為你綻放。

小草你的步履雖小 
卻在足下擁有整片大地。 

將鳥的羽翼鑲上黃金 
牠便再也無法翱翔於天際。 




Dans mes voyages, j'ai rencontré un homme timide en Inde, at-il dit,
J'étais errant ... m'a aussi dit qu'il aimait le poète indien Shengtaigeer l'[oiseaux dérive set] ...
Mon coeur a été surpris!
Parce que, Tagore est né en 1861 recueil de poèmes est un de mes préférés, et, dans certains endroits, se chevauchent ...
Alors, je lui ai demandé de me traduire, les oiseaux ensemble de la dérive de l'hindi ...
Après un certain temps, je Yaran, il a été descendants collatéraux de Tagore et universités de renom à Londres et Shakespeare astronomie majeur.
Maintenant, je partage ce poème chaque ami ... ...
 


Wandervogel Set ---
Oriental poète Rabindranath Tagore
 
Si vous manquez le soleil et les larmes,
Vous aurez également manquer les étoiles.

Forward,
Ne vous contentez pas s'arrêter et cueillir des fleurs pour l'occupation.
Parce que vous le long chemin de fleurs la fleur du Conseil.

Grass, votre démarche est faible,
Mais en une seule étape avec la pièce entière de la terre.

L'oiseau aux ailes d'or bordée
Il ne sera plus voler dans le ciel.

[生活語錄2]你想要成為怎樣的人?


你想要成為怎樣的人?

   「如果討人喜歡與受人尊敬無法兩全,我寧願受人尊敬。」
這句話是已故的法務部長,前宜蘭縣長陳定南所說的一句話。

(關於陳定南的事蹟可以看一看多年前他與王永慶的辯論
二十年後的今天,也證實了陳定南的遠見
王永慶.陳定南辯六輕
http://www.youtube.com/watch?v=jOePb3o9pqk)

    如果一個人無法討好所有人,那他要做甚麼樣的選擇?也許我們都像《黑暗騎士》
裡的蝙蝠俠一樣,有著「痛恨自己被討厭」的缺陷,但後來明瞭更重要的價值後,
即便被誤解,即便被冷漠、也懂得靜靜地接受,因為已經找到自己想守護的價值了。
很多事情,很多時候,無法馬上被人懂,甚至無法討人喜歡,但就像陳定南的選擇一樣
他選擇了令人尊敬,他知道自己要為什麼價值而獻身。


from ptt skykissx

[生活語錄1]想成為什麼樣的人


除了拉長時序來俯瞰自己外,另一個重新思考現在的困境的方法就是凝視死亡。
Steve Jobs在史丹佛的演講裡,提到了得了癌症對他人生的啟發,也因為那一次
死裡逃生的經驗讓他體會到:

你們的時間有限,所以不要浪費時間活在別人的生活裡。不要被信條所惑-盲從信條
就是活在別人思考結果裡。不要讓別人的意見淹沒了你內在的心聲。最重要的,
擁有跟隨內心與直覺的勇氣,你的內心與直覺多少已經知道你真正想要成為什麼樣的人。
任何其他事物都是次要的。


from ptt skykissx

2011年2月11日 星期五

[ubuntu linux][apache2 & php install and setting]

1. apt-get install apache2
2.apt-get install php5

需要掛載module to mods-enabled

指令:a2enmod <module name>
ex:a2enmod userdir

心定

心定。

泰戈爾 《漂鳥集》


泰戈爾 《漂鳥集》

Do  not  linger  to  gather  flowers  to  keep  them,
but  walk  on ,
for  flowers  will  keep  themselves  blooming   all  your  way.
向前走,
別只為了占有而駐足摘花,
因為,一路上花兒 自會為你綻放。

[linux][vim]

2011年2月8日 星期二

[學習linux kernel][part1][開機]


(零)
*BIOS就是在開機的時候,電腦系統會主動執行的第一個程式。
接下來BIOS會去分析電腦裡面有哪些儲存設備,我們以硬碟為例,BIOS會依據使用者的設定去取得能夠開機的硬碟, 並且到該硬碟裡面去讀取第一個磁區的MBR位置。 MBR這個僅有446 bytes的硬碟容量裡面會放置最基本的開機管理程式, 此時BIOS就功成圓滿,而接下來就是MBR內的開機管理程式的工作了。

簡單的說,整個開機流程到作業系統之前的動作應該是這樣的:

1.BIOS:開機主動執行的韌體,會認識第一個可開機的裝置;
2.MBR:第一個可開機裝置的第一個磁區內的主要開機記錄區塊,內含開機管理程式;
3.開機管理程式(boot loader):一支可讀取核心檔案來執行的軟體;
4.核心檔案:開始作業系統的功能...

(一)開機流程
流程彙整如下:
1.載入 BIOS 的硬體資訊與進行自我測試,並依據設定取得第一個可開機的裝置。
2.讀取並執行第一個開機裝置內 MBR 的 boot Loader (亦即是 grub, spfdisk 等程式)。
3.依據 boot loader 的設定載入 Kernel ,Kernel 會開始偵測硬體與載入驅動程式。
4.在硬體驅動成功後,Kernel 會主動呼叫 init 程式,而 init 會取得 run-level 資訊。
5.init 執行 /etc/rc.d/rc.sysinit 檔案來準備軟體執行的作業環境 (如網路、時區等)。
6.init 執行 run-level 的各個服務之啟動 (script 方式)。
7.init 執行 /etc/rc.d/rc.local 檔案。
8.init 執行終端機模擬程式 mingetty 來啟動 login 程式,最後就等待使用者登入。

(二)開機管理程式(Boot Loader)
boot loader 主要的功能如下:
1.提供選單:使用者可以選擇不同的開機項目,這也是多重開機的重要功能!
2.載入核心檔案:直接指向可開機的程式區段來開始作業系統;
3.轉交其他 loader:將開機管理功能轉交給其他 loader 負責(表示你的電腦系統裡面可能具有兩個以上的開機管理程式呢!)