ruby中10进制和16进制的转换

Posted by Captain Zhan Mon, 29 Dec 2008 15:25:00 GMT

16进制到10进制:
>> "B0A0".hex
=> 45216

>> "B0A0".to_i(16)
=> 45216
10进制到16进制:
>> 45216.to_s(16)
=> "b0a0"

Posted in  | no comments

My collection of QUOTES

Posted by Captain Zhan Thu, 25 Dec 2008 17:50:00 GMT

I have not failed. I've just found 10,000 ways that won't work.
  - Thomas A. Edison

Look for the ridiculous in everything and you will find it.
  - Jules Renard

Failure is not the only punishment for laziness; there is also the success of others.
  - Jules Renard

There is no excellent beauty that hath not some strangeness in the proportion.
  - Sir Francis Bacon
Read more...

Posted in ,  | no comments

闻王昌龄左迁龙标遥有此寄 李白

Posted by Captain Zhan Sun, 14 Dec 2008 15:36:00 GMT

杨花落尽子规啼, 闻道龙标过五溪.
我寄愁心与明月, 随君直到夜朗西.

Posted in  | no comments

次北固山下 唐 王湾

Posted by Captain Zhan Sun, 14 Dec 2008 15:35:00 GMT

客路青山外, 行舟绿水前.
潮平两岸阔, 风下一帆悬.
海日生殘夜, 江春入旧年.
乡书何处达? 归雁洛阳边.

Posted in  | no comments

Ruby中如何复制对象 (deep clone)

Posted by Captain Zhan Sat, 13 Dec 2008 13:13:00 GMT

用Ruby复制一个对象(object)也许没有你想像的那么容易. 今天我google了半天, 做个总结吧.
先从最简单的开始, b = a 是复制吗? 看代码说话:
>> a= [0,[1,2]]
>> b=a
>> b[0]=88
>> b[1][0]=99
>> b 
=> [88, [99, 2]]
>> a 
=> [88, [99, 2]]
从上面代码发现, 一但修改b, 原来的a也同时被改变了. 甚至:
Read more...

Posted in  | no comments

CR, LF, CR/LF 回车 换行

Posted by Captain Zhan Wed, 10 Dec 2008 17:48:00 GMT

在文本处理中, CR, LF, CR/LF是不同操作系统上使用的换行符.
Dos和windows采用回车+换行CR/LF表示下一行,
而UNIX/Linux采用换行符LF表示下一行,
苹果机(MAC OS系统)则采用回车符CR表示下一行.
CR用符号'\r'表示, 十进制ASCII代码是13, 十六进制代码为0x0D;
LF使用'\n'符号表示, ASCII代码是10, 十六制为0x0A.
所以Windows平台上换行在文本文件中是使用 0d 0a 两个字节表示, 而UNIX和苹果平台上换行则是使用0a或0d一个字节表示.
一般操作系统上的运行库会自动决定文本文件的换行格式. 如一个程序在windows上运行就生成CR/LF换行格式的文本文件,而在Linux上运行就生成LF格式换行的文本文件.
在一个平台上使用另一种换行符的文件文件可能会带来意想不到的问题, 特别是在编辑程序代码时. 有时候代码在编辑器中显示正常, 但在编辑时却会因为换行符问题而出错.
很多文本/代码编辑器带有换行符转换功能, 使用这个功能可以将文本文件中的换行符在不同格式单互换.
在不同平台间使用FTP软件传送文件时, 在ascii文本模式传输模式下, 一些FTP客户端程序会自动对换行格式进行转换. 经过这种传输的文件字节数可能会发生变化. 如果你不想ftp修改原文件, 可以使用bin模式(二进制模式)传输文本.

Posted in  | no comments