2013年8月15日 星期四

: error LNK2019: 无法解析的外部符号

使用 <winsock.h> 需要 WS2_32.LIB

◎在VS2012中link WS2_32.lib

方法一: Configuration properties - Linker - Input - Additional Dependencies.
方法二: #pragma comment(lib, "ws2_32.lib")




資料來源:
------------------------
1. http://bbs.csdn.net/topics/40238982
2. http://social.msdn.microsoft.com/Forums/vstudio/en-US/cfefa4a5-1f1a-4987-8bc7-f3197cb5826c/how-to-link-ws232lib

2013年8月8日 星期四

winsock2.h 和 windows.h ─ error C2375 重複定義



這兩個header檔案內部似乎有定義相同的東西,
 
順序沒弄好會有 "error C2375 : 重複定義 連結規範不相同"
 
盡量不要兩者include,
 
若一定得需要,
 
確認include的順序是:
 
先include <winsock2.h> , 再include <windows.h> !!!


-------------
資料來源:

2013年8月5日 星期一

ntohs, ntohl, htons,htonl的比較

ntohs =net to host short int 16位
htons=host to net short int 16位
ntohl =net to host long int 32位
htonl=host to net long int 32位
ntohs簡述:
將一個無符號短整形數從網絡字節順序轉換為主機字節順序。
    #include 
    u_short PASCAL FAR ntohs( u_short netshort); 
    netshort:一個以網絡字節順序表達的16位數。
註釋:
    本函數將一個16位數由網絡字節順序轉換為主機字節順序。
返回值:ntohs()返回一個以主機字節順序表達的數。
htons簡述:
將主機的無符號短整形數轉換成網絡字節順序。
    #include 
    u_short PASCAL FAR htons( u_short hostshort); 
    hostshort:主機字節順序表達的16位數。
註釋:
    本函數將一個16位數從主機字節順序轉換成網絡字節順序。
返回值: htons()返回一個網絡字節順序的值。
=================================================
這2個函數提供了主機字節順序與網絡字節順序的轉換
比如網絡字節為00 01
u_short a;如何直接對應的話a=0100; 為什麼呢?因為主機是從高字節到低字節的,所以應該轉化後
a= ntohs (0001);這樣a=0001;
首先,假設你已經有了一個sockaddr_in結構體ina,你有一個IP地址”132.241.5.10″要儲存在其中,你就要用到函數inet_addr(),將IP地址從點數格式轉換成無符號長整型。使用方法如下:
ina.sin_addr.s_addr = inet_addr(“132.241.5.10″); 
注意,inet_addr()返回的地址已經是網絡字節格式,所以你無需再調用函數htonl()。
我們現在發現上面的代碼片斷不是十分完整的,因為它沒有錯誤檢查。顯而易見,當inet_addr()發生錯誤時返回-1。記住這些二進制數字?(無符號數)-1僅和IP地址255.255.255.255相符合!這可是廣播地址!大錯特錯!記住要先進行錯誤檢查。
好了,現在你可以將IP地址轉換成長整型了。有沒有其相反的方法呢?它可以將一個in_addr結構體輸出成點數格式?這樣的話,你就要用到函數inet_ntoa()(“ntoa”的含義是”network to ascii”),就像這樣:
printf(“%s”,inet_ntoa(ina.sin_addr)); 
它將輸出IP地址。需要注意的是inet_ntoa()將結構體in-addr作為一個參數,不是長整形。同樣需要注意的是它返回的是一個指向一個字符的指針。它是一個由inet_ntoa()控制的靜態的固定的指針,所以每次調用inet_ntoa(),它就將覆蓋上次調用時所得的IP地址。例如:
char *a1, *a2; 
a1 = inet_ntoa(ina1.sin_addr); /*這是198.92.129.1 */ 
a2 = inet_ntoa(ina2.sin_addr); /*這是132.241.5.10 */ 
printf(“address 1 : %s “,a1); 
printf(“address 2: %s “,a2); 
輸出如下:
address 1: 132.241.5.10 
address 2: 132.241.5.10 
假如你需要保存這個IP地址,使用strcopy()函數來指向你自己的字符指針。
==================================================
htonl()表示將32位的主機字節順序轉化為32位的網絡字節順序htons()表示將16位的主機字節順序轉化為16位的網絡字節順序(ip地址是32位的端口號是16位的)
inet_ntoa() 
簡述:
    將網絡地址轉換成“.”點隔的字符串格式。
    #include
    char FAR* PASCAL FAR inet_ntoa( struct in_addr in);
    in:一個表示Internet主機地址的結構。
註釋:
    本函數將一個用in參數所表示的Internet地址結構轉換成以“.”間隔的諸如“abcd”的字符串形式。請注意inet_ntoa()返回的字符串存放在WINDOWS套接口實現所分配的內存中。應用程序不應假設該內存是如何分配的。在同一個線程的下一個WINDOWS套接口調用前,數據將保證是有效。
返回值:
    若無錯誤發生,inet_ntoa()返回一個字符指針。否則的話,返回NVLL。其中的數據應在下一個WINDOWS套接口調用前複製出來。
參見:
    inet_addr().
測試代碼如下
include 
#include 
#include 
#include 
#include 
int main(int aargc, char* argv[]) 

         struct in_addr addr1,addr2; 
         ulong l1,l2; 
         l1= inet_addr(“192.168.0.74″); 
         l2 = inet_addr (“211.100.21.179″); 
         memcpy(&addr1, &l1, 4); 
         memcpy(&addr2, &l2, 4); 
         printf(“%s : %s “, inet_ntoa(addr1), inet_ntoa(addr2)); //注意這一句的運行結果
         printf(“%s “, inet_ntoa(addr1)); 
         printf(“%s “, inet_ntoa(addr2)); 
         return 0; 

實際運行結果如下:
192.168.0.74 : 192.168.0.74 //從這裡可以看出,printf裡的inet_ntoa只運行了一次。
192.168.0.74 
211.100.21.179
inet_ntoa返回一個char *,而這個char *的空間是在inet_ntoa裡面靜態分配的,所以inet_ntoa後面的調用會覆蓋上一次的調用。第一句printf的結果只能說明在printf裡面的可變參數的求值是從右到左的,僅此而已。

資料來源:blog.chinaunix.net/
http://my.oschina.net/alphajay/blog/4277

2013年4月8日 星期一

Regular Expression: Regex 所使用的符號彙整


Regex 所使用的符號彙整

Regex 的 Notation 列表:
記號 說明
字元 代表該字元, 例如輸入 a 就代表那個地方應該出現 a 這個字元
^ 限制字串必須出現於行首, 例如 ^a 表這串字必須以 a 開頭; 如果 a 出現在其它地方, 都不算數
$ 限制字串必須出現於行末, 例如 a$ 表這串字必須以 a 結尾; 如果 a 出現在其它地方, 都不算數
\ 將特殊字元還原成字面意義的字元, 例如 \( 代表 ( 這個符號, \\ 代表 \ 這個符號; 這種表示法適用於 (, ), [, ] 等在 Regex 有特殊意義的字元
^ 某字元以外的任何字元, 必須包在中括號裡面。例如 [^a] 表示 a 除外的任何字元或符號, [^a\t] 表示 a 和 tab 除外的任何字元或符號
- 字元集合中可使用 - 來指定字元的區間, 必須包在中括號裡面。例如 [a-z] 表示從 a 到 z 的英文小寫字元, [1-3] 表示從 1 到 3 這三個數字之一
+ 其前的字元或字元集合出現一次或一次以上, 例如 a+
? 其前的字元或字元集合可出現一次或不出現, 例如 a?
* 其前的字元或字元集合可出現任何次數或不出現, 例如 a*
(...) 用以括住一群字元,且將之視成一個集合, 通常用來集合表示多個檢核式
{n} 重複 n 次
{n,m} 重複 n 到 m 次
{n,} 至少重複 n 次
[] 其中之一字元可出現可不出現, 例如 [abc] 表示不論出現 a 或 b 或 c 都算符合
| 代表「或」, 例如 (Sun|Mon|Tue|Wed|Thu|Fri|Sat), (日|一|二|三|四|五|六) ; 必須以左右括號括住
. (句點符號) 代表除了換行符號 (\n) 以外的任一字元。如果要包括換行符號, 請使用 [\s\S]
\w (\W) 代表任何英文(以外的) 字元 - 請注意, 數字字元也被承認
\s (\S) 代表空白 (以外的) 字元
\d (\D) 代表數字 (以外的) 字元
\b (\B) 代表位於文字邊界的 (以外的) 字元, 例如 \bA 可以檢核出 AB, A\b 可以檢核出 BA, \bAA\b 可以檢核出 AA
\r 代表換行字元 (或稱 CR, Carriage Return)
\n 代表換行字元 (或稱 LF, Line Feed; 通常和 \r 一同出現, 所以一般以 \r\n 代表換行, 但根據我的測試, 無論使用 \r 或 \n 或 \r\n 都會得到相同的結果, 但唯獨不能寫成 \n\r, 但建議使用 \r?\n)
\t 代表 TAB 字元 (或稱 HT, Horizontal Tab)
\( 代表左括號
\) 代表右括號
\x 以十六進位字元碼代表某個字元; 例如 [\x21-\x7E] 可代表所有看得到的字元 ([\x20-\x7E] 則包括空白字元)。不過注意 \x 之後要使用兩個數字, 不足兩個數字者請補 0, 例如 \x01
\1, \2... (Backreference Constructs) 表示出現過的群組; 例如 "(\d)(\D)" 樣式中有兩個群組, 若使用 "(\d)(\D)\1" 可檢出 "2A3"; 若使用 "(\d)(\D)\2+" 則可檢出 "2AB"; 餘此類推
\k<name> 同上, 但適用於命名的群組; 例如 "(?<Digit>\d)(?<NonDigit>\D)\k<Digit>" 亦可檢出 "2A3"
\p{Lu} (\P{Lu}) 檢出大寫(非大寫)的字母, 例如 (?-i:\p{Lu}) 可檢出字串中所有大寫字母, 而 (?-i:\P{Lu}) 可檢出所有非大寫 (包括數字、空白等) 的字母





資料來源:
Regex入門 http://www.dotblogs.com.tw/johnny/archive/2010/01/25/13301.aspx
Regex進階 http://www.dotblogs.com.tw/johnny/archive/2010/03/02/13855.aspx

2013年3月6日 星期三

Linux C

1.select
2.read
3.write
4.RS232 設計
http://www.vr.ncue.edu.tw/esa/EmbeddedSystemProgramming2010/ch06.htm

相關文章
教學文
http://www.vr.ncue.edu.tw/esa/EmbeddedSystemProgramming2010/

Source Insight 相關文章

Source Insight 3.5

相關文章
new project http://welkinchen.blogspot.tw/2009/10/source-insight.html
1.Source Insight 教學收集
http://huenlil.pixnet.net/blog/post/23271746

2.Source Insight - Trace Code的神兵利器http://www.wretch.cc/blog/hidex/8117748

3.sourceinsight使用技巧http://blog.csdn.net/flyyanqu/archive/2008/03/27/2222799.aspx

4.SourceInsight的实用技巧http://blog.csdn.net/jupin/archive/2007/10/19/1832536.aspx

5.Source Insight3.0: Linux源代码阅读的利器, http://www.itepub.net/html/kaifawendang/caozuoxitong/Linux/ruanjianshiyong/2006/0501/14338.html

Ubuntu root login

Terminal權限修改

  • sudo -i    //直接設定權限登入為root (需輸入該使用者密碼)
  • sudo passwd root  //設定root密碼
    su root //切換身份為root權限 (需輸入剛設定的root密碼)


系統登入畫面

  • version 12.10
    1.sudo passwd root  //設定root密碼
    2.sudo sh -c 'echo "greeter-show-manual-login=true" >> /etc/lightdm/lightdm.conf'   //修改登入畫面
    3.reboot 登入畫面多出"登入"選項
    4.點選"登入" >> 輸入root及剛設定的root密碼



相關文章

12.10
http://www.liberiangeek.net/2012/10/quickly-enable-root-login-in-ubuntu-12-10-quantal-quetzal/

12.04 / 11.10
http://ubuntuguide.net/enable-login-as-root-in-ubuntu-12-0411-10-with-lightdm

2013年3月5日 星期二

Ubuntu 常用指令


1. Terminal (終端機介面)

  • 啟用:[Ctrl] + [Shift] + [T]
  • 關閉:[Alt] + [F4]
  • 放大:[Ctrl] + [Shift] + [+]
  • 縮小:[Ctrl] + [-]


2. 關機: reboot

3. 切換身分: su [身份id]

4.samba
http://sean70653.pixnet.net/blog/post/30522188-%E5%9C%A8-ubuntu-11.10-%E6%9E%B6%E8%A8%AD-samba-server-%E5%8F%8Awindows-7%E4%B8%8A%E7%9A%84%E8%A8%AD

相關文章

http://ahhafree.blogspot.tw/2011/11/ubuntulinux.html

Ubuntu Root權限


相關文章

指定資料夾權限
http://qq0526.blogspot.tw/2007/04/ubuntu-root.html

開啟root使用者 & 登入後設定root權限
http://werdna1222coldcodes.blogspot.tw/2012/06/ubuntu-root.html
http://playubuntu.blogspot.tw/2008/09/root.html



2012年1月19日 星期四

what is the difference between GWT , SWT , Swing and AWT?


There are many websites nowadays which are used for different purposes and offers different sort of things. Some of them are social websites which increase the interaction between the people and allows them to share their thoughts and experience. Some websites provides entertainment while other are used to gain knowledge and to gather information. These all websites are written in the programming language and cannot be read by us. These websites are translated by our web browsers and make us able to read the information which is written on it. There are different types of browsers which are used for this purpose.
GWT
It is a product of Google and has the tools which are used to not only to make but also maintain the web written in java script it supports everything that is written in java language.
SWT
It is a graphical tool kit which is used to maintain the websites and is a product of IBM but now it is maintained and looked after by the Eclipse foundation.
Swing
It is also a graphical tool kit which is used by the users and is known primary for the java language. It is more compact and more reliable than the AWT as they do not need any code.
AWT
It is the original java based tool kit which is used for the graphical as well as the user interface. This tool kit is also used for many java profiles and is a part of Java Foundation Class.
GWT Vs SWT Vs Swing Vs AWT
GWT is a product of Google and is compatible with all java formats while SWT is an IBM production which is primarily used for graphics and is maintained by Eclipse. AWT is original java application for web tools and is also a part of it while Swing is better than AWT as it is more compact and does not need any codes.

2011年7月10日 星期日

Kick Ass -關於屁股的五個哩語

[轉錄自] http://www.chinadaily.com.cn/language_tips/2007-03/15/content_828577.htm

大家都知道kick ass有“踢屁股”的意思,可是它還有“了不起”的意思你知道嗎?事實上,美國口語裡有太多的詞是和這個“ass (中國人概念中不登大雅之堂的屁股)”有關。下面我給大家介紹一些你經常會聽到的:


1. Kiss ass 拍馬屁 
例如: A: Mary, I'm sorry for cheating on you before. Do you see any chance that we can get back together? Mary,我真的很抱歉對你不忠實。你想我們可不可能重修舊好呢?
B: I don't know, but you can kiss my ass. 不知道,不過你可以巴結我。
kiss ass 的意思就是"拍馬屁","cheat"除了作弊外,還有"不忠實"的意思。


2. kick ass 了不起 
"kick ass"直譯過來是"踢屁股",美國俚語裡表示輕而易舉地戰勝某人,此人很"牛"。給大家舉個例子:你即將參加一場籃球比賽,你的朋友問你緊張不緊張,你可以說:"They are going to get their asses kicked (他們就等著被打個落花流水吧! )
再舉個例子: A: Wow, you fixed my computer in less than 10 minutes. You're good. B: Yep. I just kick ass! (那是,我就是厲害!)
美國人中的牛人,狂人經常會用到這個"kick ass"來表示充分的自信。


3. Asshole 不是個東西 
"ass"是"屁股","hole"是"洞","asshole"是什麼意思大家應該明白了。根據wikipedia 的英文解釋,"asshole"是一個不雅的用語來表示對某人的厭惡。詞語形容的對象通常是非常刻薄的,自私的,或是粗魯無禮的。 (The word is mainly used as a profanity towards someone the speaker does not like or to express deep contempt for someone whose behavior is hurtful, self-centered or particularly abrasive.) 通常"asshole"用來形容男生的情況比較多。 如果有人毫不留情面的當眾指責你,辱罵你,你可以指著他的鼻子罵一句:"Asshole! "。
如果當你全心全意為他付出了那麼多,而他卻覺得理所應當,甚至是不屑一顧,這也到了罵他一句"Asshole"的時候,表示說:"你真不是個東西!" 如果某人滿嘴髒話,毫無教養,那麼他也配得上一句"You are an asshole!"
特別說明,此詞屬於髒話粗口,因此不要亂用啊! <---可是我特別喜愛這句的意思耶....(羞)


4. Jackass 不像話 
這個詞在美國也非常常用。想必大家已經清楚了asshole的用法。其實,"jackass" 和"asshole"意思差不多,只不過是語氣上輕了不少,厭惡程度低了不少。如果你沒有那麼討厭這個人,但又一定要發洩心中的怒火,那就吼一句:"You are a jackass! "吧!當然,這個詞也是粗口,使用起來可要小心哦。


5. Pain in the ass 
想形容某人很討厭,英文怎麼說? Somebody is pain in the ass。其實,如果你想說得文雅些,避免用"ass"這個詞,可以說"Somebody is pain in the neck."。意思完全一樣,只不過"脖子"上的痛比"屁股"上的痛更見得光些。

2011年4月13日 星期三

Axis2 偵錯:Timeout waiting for connection

有多個user Invoke 同一個service時,Service的Stack會滿,所以當服務結束時一定要釋放連線資源,讓一下個client使用,否則就會出現Timeout waiting for connection的情形。

必須在程式的最後加入下面程式碼:


ServiceClient sender = new ServiceClient();
...

if (sender != null) {
       try {
              //done using the client
              //in order to discard any associated resources
              sender.cleanupTransport();
        } catch (Exception e) {
                e.printStackTrace();
        }
}

參考文章:
http://amilachinthaka.blogspot.com/2009/05/improving-axis2-client-http-transport.html
http://amilachinthaka.blogspot.com/2010/01/improving-axis2-http-transport-client.html

2011年4月12日 星期二

IMDb Top 100

原來"The Shawshank Redemption"是第一名,那確實是部不錯的電影。
2011年
緩慢的看完Top100吧!


能看完Top 250的人真神!


IMDb Charts: IMDb Top 100




RankRatingTitleDate
1.9.2The Shawshank Redemption (1994)
2.9.2The Godfather (1972)
3.9.0The Godfather: Part II (1974)
4.8.9Il buono, il brutto, il cattivo. (1966)
5.8.9Pulp Fiction (1994)
6.8.9Schindler's List (1993)
7.8.912 Angry Men (1957)
8.8.8Inception (2010)
9.8.8One Flew Over the Cuckoo's Nest (1975)
10.8.8The Dark Knight (2008)
11.8.8Star Wars: Episode V - The Empire Strikes Back(1980)
12.8.8The Lord of the Rings: The Return of the King(2003)
13.8.8Shichinin no samurai (1954)
14.8.7Fight Club (1999)
15.8.7Goodfellas (1990)
16.8.7Star Wars (1977)
17.8.7Casablanca (1942)
18.8.7Cidade de Deus (2002)
19.8.7The Lord of the Rings: The Fellowship of the Ring(2001)
20.8.7C'era una volta il West (1968)
21.8.7Rear Window (1954)
22.8.7Raiders of the Lost Ark (1981)
23.8.7The Matrix (1999)
24.8.7Psycho (1960)
25.8.7The Usual Suspects (1995)
26.8.7The Silence of the Lambs (1991)
27.8.6Se7en (1995)
28.8.6It's a Wonderful Life (1946)
29.8.6Memento (2000)
30.8.6The Lord of the Rings: The Two Towers (2002)
31.8.6Sunset Blvd. (1950)
32.8.6Forrest Gump (1994)
33.8.6Toy Story 3 (2010)
34.8.6Léon (1994)
35.8.6Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb (1964)
36.8.6Apocalypse Now (1979)
37.8.6Citizen Kane (1941)
38.8.5American History X (1998)
39.8.5North by Northwest (1959)
40.8.5American Beauty (1999)
41.8.5Taxi Driver (1976)
42.8.5Terminator 2: Judgment Day (1991)
43.8.5Saving Private Ryan (1998)
44.8.5Alien (1979)
45.8.5Vertigo (1958)
46.8.5Le fabuleux destin d'Amélie Poulain (2001)
47.8.5Sen to Chihiro no kamikakushi (2001)
48.8.5The Shining (1980)
49.8.5WALL·E (2008)
50.8.5Paths of Glory (1957)
51.8.5The Pianist (2002)
52.8.5Lawrence of Arabia (1962)
53.8.5Double Indemnity (1944)
54.8.5City Lights (1931)
55.8.5M (1931)
56.8.5A Clockwork Orange (1971)
57.8.5Das Leben der Anderen (2006)
58.8.4The Departed (2006)
59.8.4To Kill a Mockingbird (1962)
60.8.4Aliens (1986)
61.8.4Eternal Sunshine of the Spotless Mind (2004)
62.8.4Requiem for a Dream (2000)
63.8.4Das Boot (1981)
64.8.4Reservoir Dogs (1992)
65.8.4The Third Man (1949)
66.8.4Modern Times (1936)
67.8.4L.A. Confidential (1997)
68.8.4Chinatown (1974)
69.8.4La vita è bella (1997)
70.8.4Back to the Future (1985)
71.8.4The Treasure of the Sierra Madre (1948)
72.8.4Black Swan (2010)
73.8.4The Prestige (2006)
74.8.4Monty Python and the Holy Grail (1975)
75.8.4Raging Bull (1980)
76.8.4Nuovo Cinema Paradiso (1988)
77.8.3El laberinto del fauno (2006)
78.8.3Singin' in the Rain (1952)
79.8.3The Green Mile (1999)
80.8.3Some Like It Hot (1959)
81.8.3Rashômon (1950)
82.8.3Once Upon a Time in America (1984)
83.8.3The Bridge on the River Kwai (1957)
84.8.3Amadeus (1984)
85.8.3All About Eve (1950)
86.8.3The Great Dictator (1940)
87.8.3Ladri di biciclette (1948)
88.8.3Full Metal Jacket (1987)
89.8.32001: A Space Odyssey (1968)
90.8.3Braveheart (1995)
91.8.3Inglourious Basterds (2009)
92.8.3The Apartment (1960)
93.8.3Der Untergang (2004)
94.8.3Metropolis (1927)
95.8.3Gladiator (2000)
96.8.3Up (2009)
97.8.3Gran Torino (2008)
98.8.3The Sting (1973)
99.8.3Unforgiven (1992)
100.8.3Oldeuboi (2003)