星期四, 十二月 10, 2009

Ruby让你成为一个愉悦的开发者


在最近工作的几个项目中,我有意无意的采用了Ruby语言。作为一种介于主流与非主流之间的动态语言(TIOBE排名10左右),采用ruby的开发者群体在一度暴涨之后,一直处于一个相当稳定的水平。

从效率来看,ruby确实不是一个让人完全满意的选择。在我以前一个项目中实现的一个搜索项目,最先采用了一个PHP的版本,运行起来显示了php一贯的高效和稳定特性。后来采用了ruby进行功能扩展,开发的过程让人愉悦,少量的代码实现了全部功能,并且增加了灵活性,但是在数据量急遽增加的时候,ruby的表现并不如php那样轻松自在。jruby等正在尝试通过新的手段来对这个方面进行改进,前面的路还有很长,值得期待。

而抛开这个瑕疵,Ruby语言本身的优雅简洁,却能将开发者吸引到它的圈子。

ruby强调代码的质量,在ruby的世界里,到处看到的是短小精悍的代码,寥寥几行,可以清晰看到进程的脉络。那比较负责的任务怎么实现呢?Ruby的解决方案是将问题分解,在单独的块里实现复杂的功能。其实这个单独的块也是一个清晰的框架,复杂的功能还会继续分块下去,直到所有的功能的实现都在一个简洁的块中实现。不用卖弄任何技巧,问题在逐步自然而优雅的分解过程中,已经有了一个完美的解决。
大多数语言支持完善的函数,大都有代码重用的机制。而Ruby所特有的灵活高效的block机制,让它出类拔萃。在你需要的时候,方便地def你的方法;采用block/closure,对进程进行有效的控制。通过引入这种灵活性,使Ruby的代码更加简洁。开发者会发现这种语言不会因为严格的语法规则来限制他/她的思维,怎么能不爱它呢?

Ruby的社区也比其它的社区更为友善一些,很少能看到其它社区常见的那句RTFM。这一方面可以归因于ruby是个后起之秀,很多问题都在解决之中,文档中并没有成熟的解决方案。而另一方面,ruby开发者一直处于一种愉悦的开发心情中,大都应该不会以那种暴躁的方式来对待有相同兴趣的吧。


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

星期五, 九月 25, 2009

curl -4 --head -H "Host 203.166.178.9" http://www.liulantao.com/images/lax_shetou.gif


lax@homex ~ $ host www.liulantao.com
www.liulantao.com has address 203.166.178.9
lax@homex ~ $ curl -4 --head -H "Host 203.166.178.9" http://www.liulantao.com/images/lax_shetou.gif
HTTP/1.1 200 OK
Date: Fri, 25 Sep 2009 13:19:45 GMT
Server: Apache/2.0.52 (Red Hat)
Last-Modified: Sat, 07 Feb 2009 07:30:15 GMT
ETag: "1208ae-16be-1bc9efc0"
Accept-Ranges: bytes
Content-Length: 5822
Connection: close
Content-Type: image/gif

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

What is Test-Driven Development in Ruby?

TDD steps:

1, Write a test that describes some shortcoming or missing feature in the code.

2, Run the tests.

3, Write just enough code to make this test pass.

4, Run the tests again.

5, Refactor.

6, Write a test to define a new feature and start the process all over again.


Always remember:

1, Code doesn't exist yet until it's tested.

2, Run tests religiously.


see more:
1, http://ruby.about.com/od/advancedruby/a/tdd.htm

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期四, 九月 24, 2009

rake db:drop with permission denied error.

>rake db:drop
Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - db/development.sqlite3>

maybe you run script/console and didn't exit.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期三, 九月 16, 2009

A journey to Gentoo: Intel video card and xorg installed.

config intel video card on Gentoo Linux.

first, make sure the kernel module option, "Device Drivers --> Graphics support --> Direct Rendering Manager --> Intel 810" should be checked for my i810 card.

then set  VIDEO_CARDS="intel"  in /etc/make.conf.

now, reinstall xorg-x11:  # sudo emerge -uDNva xorg-x11.

when all above steps were finished, remove /etc/X11/xorg.conf, run $ startx, and everything is fine.

Though, there is neither any input method nor web browser installed, a easy journey to go.

--
Liu Lantao, Oaks Pacific Corp.
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期一, 九月 07, 2009

Installing Chromium Web Browser on Fedora 11.

[lax@homex ~]$ sudo vim /etc/yum.repos.d/chromium.repo
[chromium]
name=Chromium Test Packages
baseurl=http://spot.fedorapeople.org/chromium/F$releasever/
enabled=0
gpgcheck=0

[lax@homex ~]$ sudo yum install *chromium* --enablerepo=chromium
Loaded plugins: aliases, fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 * fedora: ftp.cuhk.edu.hk
 * rpmfusion-free: mirrors.cat.pdx.edu
 * rpmfusion-free-updates: mirrors.cat.pdx.edu
 * rpmfusion-nonfree: mirrors.cat.pdx.edu
 * rpmfusion-nonfree-updates: mirrors.cat.pdx.edu
 * updates: ftp.cuhk.edu.hk
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package chromium.i586 0:4.0.204.0-0.1.20090827svn24640.fc11 set to be updated
--> Processing Dependency: libv8.so.1 for package: chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586
--> Processing Dependency: libminizip.so.1 for package: chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586
--> Processing Dependency: nss-mdns(x86-32) for package: chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586
--> Running transaction check
---> Package minizip.i586 0:1.2.3-22.fc11 set to be updated
---> Package nss-mdns.i586 0:0.10-7.fc11 set to be updated
---> Package v8.i586 0:1.3.8-1.20090827svn2777.fc11 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package     Arch    Version                                  Repository   Size
================================================================================
Installing:
 chromium    i586    4.0.204.0-0.1.20090827svn24640.fc11      chromium     15 M
Installing for dependencies:
 minizip     i586    1.2.3-22.fc11                            fedora       25 k
 nss-mdns    i586    0.10-7.fc11                              fedora       25 k
 v8          i586    1.3.8-1.20090827svn2777.fc11             chromium    914 k

Transaction Summary
================================================================================
Install      4 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 16 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586 |  15 MB     02:15    
(2/4): minizip-1.2.3-22.fc11.i586.rpm                    |  25 kB     00:01    
(3/4): nss-mdns-0.10-7.fc11.i586.rpm                     |  25 kB     00:00    
(4/4): v8-1.3.8-1.20090827svn2777.fc11.i586.rpm          | 914 kB     00:09    
--------------------------------------------------------------------------------
Total                                           100 kB/s |  16 MB     02:43    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : v8-1.3.8-1.20090827svn2777.fc11.i586                     1/4
  Installing     : minizip-1.2.3-22.fc11.i586                               2/4
  Installing     : nss-mdns-0.10-7.fc11.i586                                3/4
  Installing     : chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586        4/4

Installed:
  chromium.i586 0:4.0.204.0-0.1.20090827svn24640.fc11                          

Dependency Installed:
  minizip.i586 0:1.2.3-22.fc11                 nss-mdns.i586 0:0.10-7.fc11     
  v8.i586 0:1.3.8-1.20090827svn2777.fc11     

Complete!


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

Output of an Array to sentence, the ruby way

@contacts.collect{|s| s.name}.to_sentence.concat(".")


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期日, 九月 06, 2009

西四新开的一家奶酪魏


奶酪魏,西四店,今年入夏新开的店。老字号的牌子,进去店面不大,装修得简单,但是也干净整洁。奶酪白色小瓷碗,一般是7元。此外还有奶酪卷、奶酪干等品种。

我要了一碗原味的,很好吃,入口滑而不腻,奶的香醇之气全在其中,回味很久。平时吃的现酿酸奶与它相比,瞬间就没有了一点儿吸引力。

地点嘛,22路、826路等公交车在平安里路口南,路东。过段时间西四的地铁开通,应该更方便了。

奶酪魏第一家店位于前门门框胡同15号,名字为麟记酪铺,在经常是极为有名的了,梁实秋的文章中曾有描述。

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期三, 九月 02, 2009

Config rubygems and rails in ubuntu.

 sudo apt-get install rubygems
 sudo gem install rubygems-update
 sudo update_rubygems
 sudo apt-get install libsqlite3-dev
 sudo gem install sqlite3-ruby rails

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期六, 八月 29, 2009

Unix-like系统用户交流信息的几个小命令



向系统所有在线用户发送消息:
$ wall [message]
如果想设定是否接收这个消息:
$ mesg [y|n]

向特定用户发送小心:
$ write user [ttyname]

$ talk person [ttyname] 
也可以通过mesg来设定。

当然还有选项更丰富的mail命令:
$ mail [-iInv ] [-s subject ] [-c cc-addr ] [-b bcc-addr ] to-addr... 
$ mail [-iInNv -f ] [name ] 
$ mail [-iInNv [-u user ] ]

--
Liu Lantao
Oak Pacific Interactive Corp. Ltd.
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 八月 25, 2009

Google Sets is cool!

Use Google Sets to expand a list of a few items, into a list with many items. For example let's suppose you want a set (or list) of Star Wars characters, but can only think of a few. Enter a the ones you can think of, and Google sets will return a whole list.

links: http://labs.google.com/sets

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

How-to: disable the PING response.

To disable the PING response, add the following line to your init script for the network:
echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

To reenable the PING response do this:
echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_all

To make the change PERMANENT add the following line to /etc/sysctl.conf:
net.ipv4.icmp_echo_ignore_all=1
and execute this command
sysctl -p

It is better to use firewall for these purposes, so that you can optionally enable ping from some systems, esp monitoring systems
iptables -t filter -I INPUT -p icmp --icmp-type echo-request -s monitoring_system -j ACCEPT
iptables -t filter -I INPUT -p icmp --icmp-type echo-request -j DROP

Just in case it's not obvious to iptables newbies, replace "monitoring_system" with the IP/range of the server(s) which should be able to ping the server. All other ping requests will be silenty dropped.



--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期五, 八月 14, 2009

sed -i 's/str1/rep1/;s/str2/rep2/;...;s/strN/repN/' urfile

sed -i 's/str1/rep1/;s/str2/rep2/;...;s/strN/repN/' urfile

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期五, 八月 07, 2009

Nginx访问日志统计:按时间计数

$ grep "GET / " access.log | awk '{print substr($4,2,14)}' | uniq -c

   4275 04/Aug/2009 14
  11484 04/Aug/2009 15
  10145 04/Aug/2009 16
   9718 04/Aug/2009 17
   7522 04/Aug/2009 18
   8169 04/Aug/2009 19
   8385 04/Aug/2009 20
   9033 04/Aug/2009 21
   8356 04/Aug/2009 22
   6144 04/Aug/2009 23
   3457 05/Aug/2009 00
   1698 05/Aug/2009 01
    853 05/Aug/2009 02
    534 05/Aug/2009 03
    393 05/Aug/2009 04
    380 05/Aug/2009 05
    725 05/Aug/2009 06
   1672 05/Aug/2009 07
   5352 05/Aug/2009 08
   6786 05/Aug/2009 09
   5742 05/Aug/2009 10
   5686 05/Aug/2009 11
   6102 05/Aug/2009 12
   5435 05/Aug/2009 13
   4852 05/Aug/2009 14
   4645 05/Aug/2009 15
   4911 05/Aug/2009 16
   4479 05/Aug/2009 17
   3816 05/Aug/2009 18
   3532 05/Aug/2009 19
   3645 05/Aug/2009 20
   3958 05/Aug/2009 21
   3864 05/Aug/2009 22
   2653 05/Aug/2009 23
   1531 06/Aug/2009 00
    775 06/Aug/2009 01
    449 06/Aug/2009 02
    256 06/Aug/2009 03
    222 06/Aug/2009 04
    234 06/Aug/2009 05
    393 06/Aug/2009 06
    966 06/Aug/2009 07
   2615 06/Aug/2009 08
   3456 06/Aug/2009 09
   3349 06/Aug/2009 10
   3496 06/Aug/2009 11
   3863 06/Aug/2009 12
   3362 06/Aug/2009 13
   3022 06/Aug/2009 14
   2937 06/Aug/2009 15
   3763 06/Aug/2009 16
   2893 06/Aug/2009 17
   2603 06/Aug/2009 18
   2757 06/Aug/2009 19
   3500 06/Aug/2009 20
   3931 06/Aug/2009 21
   3683 06/Aug/2009 22
   2400 06/Aug/2009 23
   1435 07/Aug/2009 00
    647 07/Aug/2009 01
    351 07/Aug/2009 02
    200 07/Aug/2009 03
    157 07/Aug/2009 04
    192 07/Aug/2009 05
    275 07/Aug/2009 06
    696 07/Aug/2009 07
   1937 07/Aug/2009 08
   2616 07/Aug/2009 09
   2677 07/Aug/2009 10
   2473 07/Aug/2009 11
   2541 07/Aug/2009 12
   2350 07/Aug/2009 13
   2161 07/Aug/2009 14
   1738 07/Aug/2009 15


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 七月 28, 2009

something about xulrunner and xpcom


-----------
 addProgressListener( listener, notifyMask )
    Return type: no return value
    Add a progress listener to the browser which will monitor loaded documents. The progress listener should implement the nsIWebProgressListener interface.

----------------
loadURI( uri, referrer, charset )
    Return type: no return value
    Load a URL into the document, with the given referrer and character set.

If you use an nsIURI argument for the first, uri, argument, the call will fail. If you use a string URL it will work.
---------------
 stop()
    Return type: no return value
    Equivalent to pressing the Stop button, this method stops the currently loading document.

---------------
interface nsIServerSocketListener : nsISupports
Methods

 nsIServerSocketListener

 This interface is notified whenever a server socket accepts a new connection.
 The transport is in the connected state, and read/write streams can be opened
 using the normal nsITransport API.  The address of the client can be found by
 calling the nsISocketTransport::GetAddress method or by inspecting
 nsISocketTransport::GetHost, which returns a string representation of the
 client's IP address (NOTE: this may be an IPv4 or IPv6 string literal).


 onSocketAccepted

 This method is called when a client connection is accepted.

 @param aServ
        The server socket.
 @param aTransport
        The connected socket transport.

void onSocketAccepted(in nsIServerSocket aServ, in nsISocketTransport aTransport)

 onStopListening

 This method is called when the listening socket stops for some reason.
 The server socket is effectively dead after this notification.

 @param aServ
        The server socket.
 @param aStatus
        The reason why the server socket stopped listening.  If the
        server socket was manually closed, then this value will be
        NS_BINDING_ABORTED.

void onStopListening(in nsIServerSocket aServ, in nsresult aStatus)

https://developer.mozilla.org/en/XUL/browser
http://www.oxymoronical.com/experiments/apidocs/
--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期一, 七月 27, 2009

.htaccess

.htaccess

<Limit GET>
Order Deny,Allow
Deny from all
Allow from 10.0.0.0/8
</Limit>


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期三, 七月 22, 2009

nagios中主机依赖与服务依赖

主机依赖:A主机依赖于B主机

服务依赖:A服务依赖于B服务

服务依赖有几种情况:

A主机上的X服务依赖于A主机上的Y服务

A主机上的X服务依赖于B主机上的X服务

A主机上的X服务依赖于B主机上的Y服务

 

依赖关系在主机和服务之间有很重要的地位。比如服务依赖的情况,很多服务都依赖于主机的可连接性,网页的可访问依赖于web服务器的状态。一般情况下,如果主机已经死掉,它上面的其它服务的监测也会失败。如果主机上的服务由不同的管理员负责,通过nagios进行检测,只需通报主机已经down掉的消息给系统管理员即可,因为即使得到其它相关服务无法访问的消息,其它服务管理员无力处理这个问题。nagios默认能够支持刚才提到的依赖。主机依赖也有相似的状况,比如A主机通过B主机连接网络提供服务,如果监测到B主机停止的话,则不再对A主机进行监测。

 

主机依赖 通过hostdependency进行定义。

参数格式定义

define hostdependency{
  host_name              host_name
  hostgroup_name      hostgroup_name
  dependent_host_name            host_name
  dependent_hostgroup_name    hostgroup_name
  inherits_parent                  [0/1]
  execution_failure_criteria     [o,d,u,p,n]
  notification_failure_criteria   [o,d,u,p,n]
  dependency_period              timeperiod_name
  }

o: OK; d: DOWN; u: UP; p:PENDDING; n:NONE.

 

实例

define hostdependency{
  host_name        WWW1
  dependent_host_name       DBASE1
  notification_failure_criteria        d,u
  }

 

服务依赖 通过servicedependency进行定义。

参数格式定义:

define servicedependency{
  host_name                 host_name
  hostgroup_name         hostgroup_name
  service_description       service_description
  dependent_host_name              host_name
  dependent_hostgroup_name      hostgroup_name
  dependent_service_description   service_description
  inherits_parent                  [0/1]
  execution_failure_criteria     [o,w,u,c,p,n]
  notification_failure_criteria   [o,w,u,c,p,n]
  dependency_period            timeperiod_name
  }

o: OK; w: WARNING; u: UP; c: CRITICAL; p: PENDDING; n:NONE;

实例:

define servicedependency{
  host_name             WWW1
  service_description             Apache Web Server
  dependent_host_name       WWW1
  dependent_service_description      Main Web Site
  execution_failure_criteria               n
  notification_failure_criteria             w,u,c
  }

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期三, 五月 13, 2009

在北京听到布谷鸟了

这个夜晚,开始听到窗外布谷鸟叫。麦子,马上要收割了。
 
城市之中竟然能听到布谷鸟,很神奇吧。
大家都加油吧
 

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 五月 12, 2009

Working Productively in Bash’s Vi Command Line Editing Mode (with Cheat Sheet)

[ This article is from Peteris Krumins' blog, and you can read original aritle here:http://www.catonmat.net/blog/bash-vi-editing-mode-cheat-sheet/. ]

Bash provides two modes for command line editing - emacs and vi. Emacs editing mode is the default and I already wrote an article and created a cheat sheet for this mode.

This time I am going to introduce you to bash's vi editing mode and give out a detailed cheat sheet with the default keyboard mappings for this mode.

The difference between the two modes is what command each key combination (or key) gets bound to. You may inspect your current keyboard mappings with bash's built in bind command:

$ bind -P

abort can be found on "\C-g", "\C-x\C-g", "\M-\C-g".
accept-line can be found on "\C-j", "\C-m".
alias-expand-line is not bound to any keys
...

To get into the vi editing mode type

$ set -o vi

in your bash shell (to switch back to emacs editing mode, type set -o emacs).

If you are used to a vi text editor you will feel yourself at home.

The editing happens in two modes - command mode and insert mode. In insert mode everything you type gets output to the terminal, but in the command mode the keys are used for various commands.

Here are a few examples with screenshots to illustrate the vi editing mode.

Let '[i]' be the position of cursor in insert mode in all the examples and '[c]' be the position of cursor in command mode.

Examples:

Once you have changed the readline editing mode to vi (by typing set -o vi), you will be working in insert mode.

The example will be performed on this command:

$ echo arg1 arg2 arg3 arg4[i]

Example 1:

Suppose you have typed a command with a few arguments and want to insert another argument before an argument which is three words backward.

$ echo arg1 (want to insert arg5 here) arg2 arg3 arg4[i]

Hit 'ESC' to switch to command mode and press '3' followed by 'B':

$ echo arg1 [c]arg2 arg3 arg4

Alternatively you could have hit 'B' three times: 'BBB'.

Now, enter insert mode by hitting 'i' and type 'arg5 '

$ echo arg1 arg5 [i]arg2 arg3 arg4

Example 2:

Suppose you wanted to change arg2 to arg5:

$ echo arg1 [c]arg2 arg3 arg4

To do this, you can type 'cw' which means 'change word' and just type out 'arg5':

$ echo arg1 arg5[c] arg3 arg4

Or even quicker, you can type 'f2r5', where 'f2' moves the cursor right to next occurrence of character '2' and 'r5' replaces the character under the cursor with character '5'.

Example 3:

Suppose you typed a longer command and you noticed that you had made several mistakes, and wanted to do the correction in the vi editor itself. You can type 'v' to edit the command in the editor and not on the command line!

Example 4:

Suppose you typed a long command and remembered that you had to execute another one before it. No need to erase the current command! You can switch to command mode by hitting ESC and then type '#' which will send the current command as a comment in the command history. After you type the command you had forgotten, you may go two commands back in history by typing 'kk' (or '2k'), erase the '#' character which was appended as a comment and execute the command, this makes the whole command look like 'ESC 2k0x ENTER'.

These are really basic examples, and it doesn't get much more complex than this. You should check out the cheat sheet for other tips and examples, and try them out!

To create the cheat sheet, I downloaded bash-2.05b source code and scanned through lib/readline/vi_keymap.c source code file and lib/readline/vi_mode.c to find all the default key bindings.

It turned out that the commands documented in vi_keymap.c were all documented in man 3 readline and I didn't find anything new.

After that I checked bashline.c source file function initialize_readline to find how the default keyboard shortcuts were changed. I found that 'CTRL-e' (which switched from vi mode to emacs) got undefined, 'v' got defined which opens the existing command in the editor, and '@' which replaces a macro key (char) with the corresponding string.

The cheat sheet includes:

  • Commands for entering input mode,
  • Basic movement commands,
  • Character finding commands,
  • Character finding commands,
  • Deletion commands,
  • Undo, redo and copy/paste commands,
  • Commands for history manipulation,
  • Completion commands,
  • A few misc. commands, and
  • Tips and examples




http://www.catonmat.net/blog/wp-content/plugins/wp-downloadMonitor/user_uploads/bash-vi-editing-mode-cheat-sheet.txt

.---------------------------------------------------------------------------.
| |
| Readline VI Editing Mode |
| Default Keyboard Shortcuts for Bash |
| Cheat Sheet |
| |
'---------------------------------------------------------------------------'
| Peteris Krumins (peter@catonmat.net), 2008.01.08 |
| http://www.catonmat.net - good coders code, great reuse |
| |
| Released under the GNU Free Document License |
'---------------------------------------------------------------------------'

======================== Keyboard Shortcut Summary ========================

.--------------.------------------------------------------------------------.
| | |
| Shortcut | Description |
| | |
'--------------'------------------------------------------------------------'
| Switching to COMMAND Mode: |
'--------------.------------------------------------------------------------'
| ESC | Switch to command mode. |
'--------------'------------------------------------------------------------'
| Commands for Entering INPUT Mode: |
'--------------.------------------------------------------------------------'
| i | Insert before cursor. |
'--------------+------------------------------------------------------------'
| a | Insert after cursor. |
'--------------+------------------------------------------------------------'
| I | Insert at the beginning of line. |
'--------------+------------------------------------------------------------'
| A | Insert at the end of line. |
'--------------+------------------------------------------------------------'
| c<mov. comm> | Change text of a movement command <mov. comm> (see below). |
'--------------+------------------------------------------------------------'
| C | Change text to the end of line (equivalent to c$). |
'--------------+------------------------------------------------------------'
| cc or S | Change current line (equivalent to 0c$). |
'--------------+------------------------------------------------------------'
| s | Delete a single character under the cursor and enter input |
| | mode (equivalent to c[SPACE]). |
'--------------+------------------------------------------------------------'
| r | Replaces a single character under the cursor (without |
| | leaving command mode). |
'--------------+------------------------------------------------------------'
| R | Replaces characters under cursor. |
'--------------+------------------------------------------------------------'
| v | Edit (and execute) the current command in the text editor. |
| | (an editor defined in $VISUAL or $EDITOR variables, or vi |
'--------------'------------------------------------------------------------'
| Basic Movement Commands (in command mode): |
'--------------.------------------------------------------------------------'
| h | Move one character right. |
'--------------+------------------------------------------------------------'
| l | Move one character left. |
'--------------+------------------------------------------------------------'
| w | Move one word or token right. |
'--------------+------------------------------------------------------------'
| b | Move one word or token left. |
'--------------+------------------------------------------------------------'
| W | Move one non-blank word right. |
'--------------+------------------------------------------------------------'
| B | Move one non-blank word left. |
'--------------+------------------------------------------------------------'
| e | Move to the end of the current word. |
'--------------+------------------------------------------------------------'
| E | Move to the end of the current non-blank word. |
'--------------+------------------------------------------------------------'
| 0 | Move to the beginning of line |
'--------------+------------------------------------------------------------'
| ^ | Move to the first non-blank character of line. |
'--------------+------------------------------------------------------------'
| $ | Move to the end of line. |
'--------------+------------------------------------------------------------'
| % | Move to the corresponding opening/closing bracket. |
'--------------'------------------------------------------------------------'
| Character Finding Commands (these are also Movement Commands): |
'--------------.------------------------------------------------------------'
| fc | Move right to the next occurance of char c. |
'--------------+------------------------------------------------------------'
| Fc | Move left to the previous occurance of c. |
'--------------+------------------------------------------------------------'
| tc | Move right to the next occurance of c, then one char |
| | backward. |
'--------------+------------------------------------------------------------'
| Tc | Move left to the previous occurance of c, then one char |
| | forward. |
'--------------+------------------------------------------------------------'
| ; | Redo the last character finding command. |
'--------------+------------------------------------------------------------'
| , | Redo the last character finding command in opposite |
| | direction. |
'--------------+------------------------------------------------------------'
| | | Move to the n-th column (you may specify the argument n by |
| | typing it on number keys, for example, 20|) |
'--------------'------------------------------------------------------------'
| Deletion Commands: |
'--------------.------------------------------------------------------------'
| x | Delete a single character under the cursor. |
'--------------+------------------------------------------------------------'
| X | Delete a character before the cursor. |
'--------------+------------------------------------------------------------'
| d<mov. comm> | Delete text of a movement command <mov. comm> (see above). |
'--------------+------------------------------------------------------------'
| D | Delete to the end of the line (equivalent to d$). |
'--------------+------------------------------------------------------------'
| dd | Delete current line (equivalent to 0d$). |
'--------------+------------------------------------------------------------'
| CTRL-w | Delete the previous word. |
'--------------+------------------------------------------------------------'
| CTRL-u | Delete from the cursor to the beginning of line. |
'--------------'------------------------------------------------------------'
| Undo, Redo and Copy/Paste Commands: |
'--------------.------------------------------------------------------------'
| u | Undo previous text modification. |
'--------------+------------------------------------------------------------'
| U | Undo all previous text modifications. |
'--------------+------------------------------------------------------------'
| . | Redo the last text modification. |
'--------------+------------------------------------------------------------'
| y<mov. comm> | Yank a movement into buffer (copy). |
'--------------+------------------------------------------------------------'
| yy | Yank the whole line. |
'--------------+------------------------------------------------------------'
| p | Insert the yanked text at the cursor. |
'--------------+------------------------------------------------------------'
| P | Insert the yanked text before the cursor. |
'--------------'------------------------------------------------------------'
| Commands for Command History: |
'--------------.------------------------------------------------------------'
| k | Insert the yanked text before the cursor. |
'--------------+------------------------------------------------------------'
| j | Insert the yanked text before the cursor. |
'--------------+------------------------------------------------------------'
| G | Insert the yanked text before the cursor. |
'--------------+------------------------------------------------------------'
| /string or | Search history backward for a command matching string. |
| CTRL-r | |
'--------------+------------------------------------------------------------'
| ?string or | Search history forward for a command matching string. |
| CTRL-s | (Note that on most machines Ctrl-s STOPS the terminal |
| | output, change it with `stty' (Ctrl-q to resume)). |
'--------------+------------------------------------------------------------'
| n | Repeat search in the same direction as previous. |
'--------------+------------------------------------------------------------'
| N | Repeat search in the opposite direction as previous. |
'--------------'------------------------------------------------------------'
| Completion commands: |
'--------------.------------------------------------------------------------'
| TAB or = or | List all possible completions. |
| CTRL-i | |
'--------------+------------------------------------------------------------'
| * | Insert all possible completions. |
'--------------'------------------------------------------------------------'
| Miscellaneous commands: |
'--------------.------------------------------------------------------------'
| ~ | Invert case of the character under cursor and move a |
| | character right. |
'--------------+------------------------------------------------------------'
| # | Prepend '#' (comment character) to the line and send it to |
| | the history. |
'--------------+------------------------------------------------------------'
| _ | Inserts the n-th word of the previous command in the |
| | current line. |
'--------------+------------------------------------------------------------'
| 0, 1, 2, ... | Sets the numeric argument. |
'--------------+------------------------------------------------------------'
| CTRL-v | Insert a character literally (quoted insert). |
'--------------+------------------------------------------------------------'
| CTRL-r | Transpose (exchange) two characters. |
'--------------'------------------------------------------------------------'


===========================================================================

.---------------------------------------------------------------------------.
| Peteris Krumins (peter@catonmat.net), 2008.01.08. |
| http://www.catonmat.net - good coders code, great reuse |
| |
| Released under the GNU Free Document License |
'---------------------------------------------------------------------------'



--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 四月 28, 2009

Subversion主干-分支开发的流程。

使用Subversion辅助开发,有一个重要的概念就是主干与分支。
采用主干与分支的开发方法,可以有几种不同的策略:
1、主干上开发,分支上发布。发布之后,如果分支有BUG(主干可能也是有的),则在分支上修改BUG。然后合并到主干。分支的发布 继续进行。这个一般适用于客户化软件工程的。
2、主干保持一个最新的稳定版本,保证随时能提供稳定的发布版本。而所有的新功能、新技术实验全放在分支上去做开发,进行新技术的验证实验。等分支相对稳定以后,再合并到主干上形成稳定的发布版本。此 时就要更新主干,进行主干版本的升级。很多开源软件基本采取这种策略。
3、还有一种就是这两者的混合,结合两者的优点,即保证随时可以有稳定的版本发布,又能保证客户化的版本分支开发功能及其客 户化版本的维护。

下面介绍采用第2中策略的详细步骤和命令。
以trunk为主干目录,branches下为分支目录。在分支进行开发,稳定后合并入主干。

首先,从主干创建开发分支:
[lax@liulantao-com ~]$ svn cp http://gnu.bnu.edu.cn:8000/repos/www.myshu.org/trunk/ http://gnu.bnu.edu.cn:8000/repos/www.myshu.org/branches/www.myshu.org_20090428/ -m "Creating branch: 20090428."
Committed revision 10.

然后,获取分支代码,进行新特性的开发工作。
[lax@liulantao-com ~]$ svn co http://gnu.bnu.edu.cn:8000/repos/www.myshu.org/branches/www.myshu.org_20090428/

之后,则进入本地的www.myshu.org_20090428目录中进行开发,所有改动直接提交,直至新功能稳定并完成。
[lax@liulantao-com ~]$ cd www.myshu.org_20090428/
[lax@liulantao-com ~]$ [change the code]......
[lax@liulantao-com ~/www.myshu.org_20090248/]$ svn ci -m "Changing something."

分支开发完成后,检查分支的历史,获得创建时所在的版本。
[lax@liulantao-com www.myshu.org_20090428]$ svn log --stop-on-copy -q http://gnu.bnu.edu.cn:8000/repos/www.myshu.org/branches/www.myshu.org_20090428/
------------------------------------------------------------------------
r10 | lax | 2009-04-28 11:46:02 +0800 (Tue, 28 Apr 2009)
------------------------------------------------------------------------
数值最小的版本号是我们需要合并的版本。本例中是r10。记下这个数值。

获取主干的代码。
[lax@liulantao-com ~]$ svn co http://gnu.bnu.edu.cn:8000/repos/www.myshu.org/trunk
[lax@liulantao-com ~]$ cd trunk/

接着将开发分支合并入刚获取的主干代码上。
[lax@liulantao-com trunk/]$ svn merge -r 10:HEAD http://gnu.bnu.edu.cn:8000/repos/www.myshu.org/branches/www.myshu.org_20090428/

然后查看合并后主干代码的状态。
[lax@liulantao-com trunk/]$ svn status

如果没有冲突(conflict),则可以提交了新的主干了。
[lax@liulantao-com trunk/]$ svn ci -m "Adding new features."

现在,主干已经形成一个新的状态。在整个过程中,主干的代码一直保持着稳定可用的状态,而分支代码则处于开发状态。

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期六, 四月 25, 2009

Install and Config Sun Java Runtime Environment: How-to.

Install and Config Sun Java Runtime Environment: How-to.
[ http://www.liulantao.com/ ]
 
First, get the latest jre from SUN and get the rpm.
Go-to http://java.com/en/download/manual.jsp, and choose the rpm file.

Then install it using rpm
[lax@liulantao-com JAVA]$ sudo rpm -Uvh jre-6u12-linux-i586.rpm

Make the system recognize it.
[lax@liulantao-com ~]$ sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jre1.6.0_12/bin/java 100 --slave /usr/bin/rmiregistry rmiregistry /usr/java/jre1.6.0_12/bin/rmiregistry --slave /usr/share/man/man1/rmiregistry.1 rmiregistry.1 /usr/java/jre1.6.0_12/man/man1/rmiregistry.1 --slave /usr/share/man/man1/rmiregistry.1.gz rmiregistry.1.gz /usr/java/jre1.6.0_12/man/man1/rmiregistry.1.gz

Then we check the default version. See it, java is there waiting for U!
[lax@liulantao-com JAVA]$ java -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

在Linux上编译安装SUN拼音输入法|Build SunPinyin on GNU/Linux (CentOS/Redhat/Fedora).

〔懒桃原创,转载请注明完整链接http://www.liulantao.com/

= 在Linux上编译安装SUN拼音。 =

Sun Pinyin是最近评价很高的一款中文输入法。

首先安装必须的工具和库文件:
[lax@liulantao-com ~]
$ sudo yum install mercurial scim-devel

如果安装过程中报错,可以添加下面的东西试试:
[lax@liulantao-com ~]$ sudo yum install git gnome-common intltool -y

现在把源代码从库中签出:
[lax@liulantao-com ~]$ hg clone ssh://anon@hg.opensolaris.org/hg/nv-g11n/inputmethod

开始安装过程,以下命令安装使得sun拼音能够在scim中被调用:
[lax@liulantao-com ~]$ cd inputmethod/sunpinyin/ime
[lax@liulantao-com ~]$ ./autogen.sh --prefix=/usr --disable-cle --enable-scim
[lax@liulantao-com ~]$ make
[lax@liulantao-com ~]$ sudo make install

退出桌面,重新登入。从你的SCIM中选择Sun Pinyin就可以了。

--------------------------------------------------------------------------------
Sun Pinyin is a recently high performance chinese input method.

First, Install essential tools and development libraries:
[lax@liulantao-com ~]
$ sudo yum install mercurial scim-devel
 
If something goes wrong in next steps, you may need some of the following packages:
[lax@liulantao-com ~]$ sudo yum install git gnome-common intltool -y

Now, check out the source from opensolaris server:
[lax@liulantao-com ~]$ hg clone ssh://anon@hg.opensolaris.org/hg/nv-g11n/inputmethod

Just install it, with the following commands:
[lax@liulantao-com ~]$ cd inputmethod/sunpinyin/ime
[lax@liulantao-com ~]$ ./autogen.sh --prefix=/usr --disable-cle --enable-scim
[lax@liulantao-com ~]$ make
[lax@liulantao-com ~]$ sudo make install
Logout your desktop and re-login, a fresh sun-pinyin is just there in scim menu.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 四月 21, 2009

磁盘数据救援工具R-Studio

R-Studio 是一个功能强大、节省成本的反删除和数据恢复软件系列。它采用独特的数据恢复新技术,为恢复 FAT12/16/32、NTFS、NTFS5(由 Windows 2000/XP/2003/Vista 创建或更新)、Ext2FS/Ext3FS(LINUX 文件系统)以及 UFS1/UFS2(FreeBSD/OpenBSD/NetBSD 文件系统)分区的文件提供了最为广泛的数据恢复解决方案。R-Studio 运行于本地磁盘和网络磁盘,即使这些分区已被格式化、损坏或删除。对参数进行灵活的设置,可以让您对数据恢复实施绝对控制。


R-Studio 工具恢复适合以下情况:

1、没有进回收站而被直接删除的文件,或者当回收站被清空时的文件;
2、因病毒攻击或电源故障被删除的文件;
3、文件分区被重新格式化后的文件(甚至是不同的文件系统);
4、硬盘上的分区结构被改变或损害时的文件。在这种情况下,R-Studio 工具可以 扫描硬盘,尝试去找到以前存在的分区并从找到的分区恢复文件。
5、有坏扇区的硬盘的文件 R-Studio 数据恢复软件首先拷贝整个磁盘或者部分磁盘内容到一个镜像文件中,然后再处理该镜像文件。当新的坏扇区不断出现在硬盘上时,这一处理方式尤为实用,其余信息必须立即保存。


R-Studio 数据恢复功能详情:
1、标准的"Windows Explorer"风格界面。
2、主机操作系统:Windows 9x、ME、NT、2000、XP、2003 Server、Vista。
3、通过网络进行数据恢复。可以从运行 Win95/98/ME/NT/2000/XP/2003/Vista、Linux 以及 UNIX 的网络计算机上恢复文件。
支持的文件系统:FAT12、FAT16、FAT32、NTFS、NTFS5(由 Windows 2000/XP/2003/Vista 创建或更新)、Ext2FS/Ext3FS (Linux)、UFS1/UFS2 (FreeBSD/OpenBSD/NetBSD)。
4、识别和分析动态(Windows 2000/XP/2003/Vista)、基本和 BSD (UNIX) 分区布局方案。
5、损坏的 RAID 恢复。如果操作系统不能识别出您的 RAID,您可以从其组件创建一个虚拟的 RAID。这样的虚拟 RAID 可以当作真实的 RAID 处理。
6、创建 镜像文件用于整个硬盘、分区或它的一部分。这类镜像文件可以作为常规的磁盘处理。
7、对被损坏或删除的分区、加密文件 (NTFS 5)、额外的数据流 (NTFS, NTFS 5) 进行数据恢复。
8、对如下情况进行数据恢复:
8.1 FDISK 或其它磁盘工具已经在运行;
8.2 VIRUS 侵入;FAT 损坏;MBR 被破坏。
9 识别本地化名称。
10 被恢复的文件可以保存在主机操作系统可以访问的任何(包括网络)磁盘上。
11 文件或磁盘的内容可以在十六进制编辑器中查看或编辑。该编辑器支持 NTFS 文件属性编辑。



--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期三, 四月 15, 2009

Principles behind the Agile Manifesto

Principles behind the Agile Manifesto


We follow these principles:

Our highest priority is to satisfy the customer
through early and continuous delivery
of valuable software.

Welcome changing requirements, even late in
development. Agile processes harness change for
the customer's competitive advantage.

Deliver working software frequently, from a
couple of weeks to a couple of months, with a
preference to the shorter timescale.

Business people and developers must work
together daily throughout the project.

Build projects around motivated individuals.
Give them the environment and support they need,
and trust them to get the job done.

The most efficient and effective method of
conveying information to and within a development
team is face-to-face conversation.

Working software is the primary measure of progress.

Agile processes promote sustainable development.
The sponsors, developers, and users should be able
to maintain a constant pace indefinitely.

Continuous attention to technical excellence
and good design enhances agility.

Simplicity--the art of maximizing the amount
of work not done--is essential.

The best architectures, requirements, and designs
emerge from self-organizing teams.

At regular intervals, the team reflects on how
to become more effective, then tunes and adjusts
its behavior accordingly.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 四月 07, 2009

使用SVN+SSH,同步Ruby On Rails代码的脚本

版本库和开发都在自己的笔记本上进行,而服务器则通过svn来同步代码。
每次在服务器上测试都需要运行一系列的命令,并且由于无线网络使用DHCP取得动态ip,每次都要修改。这个过程很麻烦,所以写一个简单的脚本完成这个任务。

基本思路很简单:
首先修改hosts文件(为svn update时提供方便,即使使用动态ip,也可以每次通过主机名来访问),
然后通过svn+ssh来获取代码,
之后则进行初步的设定,配置数据库文件,
最后则执行数据库迁移,并且启动script/server。
---------------------------------------------
[lax@gnu ~]$ cat svn_ssh_from_lax
sudo vi /etc/hosts
svn co svn+ssh://lax/LAX/_DEV_/_SVN_/repos/www.myshu.org/trunk www.myshu.org.devel_trunk
cd www.myshu.org.devel_trunk/ && cp config/database.yml.orig config/database.yml
vi config/database.yml && rake db:drop && rake db:create && rake db:migrate && ruby script/server
---------------------------------------------

只需
$ sh svn_ssh_from_lax
即可运行此脚本来完成任务。

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期三, 三月 04, 2009

YUM error: No module named rpm

When I am upgrading my Fedora 10 to Fedora rawhide, my desktop was locked. Then I restart the computer, rerun the yum upgrade. some error like the following comes out.
-------------------------
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

No module named rpm

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.5 (r25:51908, Apr 10 2007, 10:29:13)
[GCC 4.1.2 20070403 (Red Hat 4.1.2-8)]

If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.duke.edu/YumFaq
-------------------------
someone in fedoraforum said to reinstall yum and python, but i found it didn't work well.

then i try uninstall some yum plugin such as yum-metadata-parser, then the error mesage becomes
--------------
No module named iniparser
--------------
it seems that the error comes from here.
then i find a package called python-iniparser is out of date. so i download it by hand and update it.
try to yum upgrade again, it works! everything comes to there original way.

after all, you just need to reinstall 2 packages: yum-metadata-parser and python-iniparser.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期四, 二月 26, 2009

Debian Lenny: Chinese Input Method

Install the Chinese input tool package scim-chines with its recommended packages such as im-switch.

- Execute "im-switch -c" from user's shell and select "scim".
- Relogin.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

Debian Lenny: Audio Not Working

The simplest, and currently suggested approach, is to use the
asoundconf command.
# alsaconf
if it still doesn't work for normal users, try add this user to audio group.
# adduser lax audio


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 二月 17, 2009

Install Debian GNU/Linux under an existing Unix-like system VIA chroot and debootstrap

I should say the new debian GNU/Linux LENNY is an excellent platform to meet various users' needs.

Before starting our installation, the new version of debootstrap and chroot should work on your machine.
Information about chroot can be found an "http://en.wikipedia.org/wiki/Chroot".
These two software should have been contained in the repository of most of the popular distributions such as redhat/debian/suse, etc. "yum install chroot debootstrap -y" should work on RHEL/Centos/Fedora, and "apt-get install chroot debootstrap -y" should work on Debian/Ubuntu.

The operations below need root priviledge. The following command line started with a '#' should be perform on you existing system, and the line start with two '#'s should be perform in the chrooted environment. Additional the line started with three '#'s should be perform after the new debian lenny was boot up.

Let's GO!

1 - PREPARE DISK SPACE
 1.1 - I just want to install my new Debian LENNY on /dev/sda3, you should replace this with own choice.
# mke2fs -j /dev/sda3
# mkswap /dev/sda8
# sync; sync; sync
# swapon /dev/sda8
 1.2 - mount the partition.
#mkdir /debian
#mount /dev/sda3 /debian

2 - INSTALL BASIC SYSTEM WITH DEBOOTSTRAP.
# debootstrap --arch i386 lenny /debian/ URL
 replace "URL" with the mirror you have chosen, eg:
# debootstrap --arch i386 lenny /debian/ ftp://ftp3.tsinghua.edu.cn/mirror/debian/debian

3 - CHROOT TO THE NEW SYSTEM.

#LANG=C chroot /debian/ /bin/bash

4 - NOW WE ARE IN THE CHROOTED SYSTEM, A BRAND NEW WORLD
mount the /proc filesystem
## mount -t proc proc /proc

perform some initial operation.
## MAKEDEV

5 - CONFIGURE LENNY.
configure the filesystem.
## editor /etc/fstab
## mount -a

configure the network.
## editor /etc/network/interfaces
## echo HOSTNAME >> /etc/hostname
## editor /etc/hosts

6 - OTHER CONFIGURATION AND PACKAGES TO INSTALL.
configure sourcelist of you mirror.
## editor /etc/apt/source.list
## aptitude update

configure system locales.
## aptitude install locales
## dpkg-reconfigure locales

------------- optional : after reboot  ---------------
### aptitude install console-data
### dpkg-reconfigure console-data
------------------------------------------------

7 - KERNEL AND BOOTLOADER.
find some kernel files to boot your machine.
## apt-cache search linux-image
## aptitude install linux-image-2.6.26-1.686
## editor /etc/kernel-img.conf

install the grub bootloader
## aptitude install grub
## grub-install /dev/sda3
## update-grub

8 - AUTOMATICALLY INSTALL SOME PACKAGE.
install basic system packages.
## tasksel install standard
## aptitude clean

install various packages for laptop and desktop application, OPTIONAL.
## tasksel install laptop
## tasksel install desktop

8 - REBOOT TO LENNY.
 iT works, HAVE FUN!
--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期六, 二月 07, 2009

嗨,大家好!新年新面貌,我的主页也换了一个新风格。希望这里能够成为我与亲人和朋友们交流的好平台。


您可以把本网页加入收藏夹,以便获得最新动态。
网址:
http://www.liulantao.com/
http://www.liulantao.com/blogs/liulantao/atom.xml

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期六, 一月 24, 2009

Rails国际化的关键步骤。Rails I18n Key Steps.

Rails I18n的关键点


1、设定locales文档。
config/locales/en.yml
------------------------------
en:
  hello: "Hello world"
  store: "Store"
------------------------------
config/locales/zh-CN.yml
------------------------------
zh-CN:
  hello: "你好"
  store: "商店"
------------------------------
2、解析locale。
app/controller/application.rb
------------------------------
  class ApplicationController < ActionController::Base
    before_filter :set_locale
    def set_locale
      I18n.locale = params[:locale] || 'zh-CN'              #如果没有,则使用默认值。
    end
    ...
  end
------------------------------
3、在控制器中读取变量
------------------------------
class StoreController < ApplicationController
  def index
    @products = Product.find_products_for_sale
    flash[:hello_flash] = t(:hello_flash)
  end
  ...
end
------------------------------
4、在视图层中使用变量
------------------------------
      <% if flash[:hello_flash] -%>
        <div id="hello_flash"><%= flash[:hello_flash] %></div>
      <% end -%>
------------------------------

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 一月 20, 2009

Rails开发中的MySQL中文问题以及简单解决方式

Rails2.2.2对中文的支持是不错的,当然不仅仅是中文,所有多字节文字都能够很好得被支持。
对于一个有很高本地化l10n和国际化i18n需求的网站,多语言支持的实现方式很多,最常用的是采用gettext来实现。

在网页生成过程中,初学者最容易出问题的就是数据库连接的编码问题。最便捷的解决方式是采用utf8编码方式。
Rails应用中config/database.yml中可以在数据库段中设置encoding: utf8如下:
----------------
development:
adapter: mysql
encoding: utf8
database: project_development
pool: 5
username: root
password:
host: localhost
----------------
对于使用MySQL数据库的应用,只要设置/etc/my.cnf就可以保证正确的存取utf8数据了。

检查/etc/my.cnf文件,保证里面有如下两段内容,如果没有则添加进去:
--------------
[client]
default-character-set=utf8

[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
--------------
修改保存之后,重启服务器即可。
--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期六, 一月 17, 2009

ROR development with RadRails in Eclipse

安装Eclips。
菜单:Help - Software Updates - Available Software - Add Sites, http://radrails.sourceforge.net/update, http://updatesite.rubypeople.org/release
------------参考文章-------------------
installing RadRails on Eclipse ...........

I could not find a proper answer when i wanted to install RadRails on eclipse . This is how it is done , .... in the Eclipse menu go to
Help-->Software Updates --> Find and Install....
then in the pop - up window which appears ,..
Search for new features to install
and then click next and then u will have to add 2 new remote sites, .. the details for the sites are the ones which were very difficult to obtain , they are
site 1 :
Name :RadRails
URL : http://radrails.sourceforge.net/update
site 2 :
Name :RDT
URL : http://updatesite.rubypeople.org/release
then click on finish , u are almost done with the installation , u have to just follow the instructions from here on to finish the installation .

Original link:http://satisheerpini.blogspot.com/2008/05/installing-radrails-on-eclipse.html
-------------------------------
--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

星期二, 一月 06, 2009

从“Rails 2.2 / Scaffold功能增强”看Rails敏捷性的提高

这几天看《Agile Web Development With Rails, 2nd Edition》(AWDWR),体验一下rails开发的敏捷。
不料第一个例子就卡住了。原来书上的例子所需要使用的方法是在rails1.2中有效的,而在rails2.2不被默认支持了。


我遇到的这个东西就是那个scaffold!从网上搜索发现大家都说要装plugin才能够使用,可是找到plugin的老巢也没看出什么门道。
于是打开AWDWR,3rd edition beta电子书来看,才发现这个东西已经是可以直接作为script/generate的对象来使用了。


下面是成功的使用方式,创建一个product的scaffold:
---------------------------------------------
depot> ruby script/generate scaffold product \
> title:string description:text image_url:string
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/products
exists app/views/layouts/
exists test/functional/
exists test/unit/
exists public/stylesheets/
create app/views/products/index.html.erb
create app/views/products/show.html.erb
create app/views/products/new.html.erb
create app/views/products/edit.html.erb
create app/views/layouts/products.html.erb
create public/stylesheets/scaffold.css
create app/controllers/products_controller.rb
create test/functional/products_controller_test.rb
create app/helpers/products_helper.rb
route map.resources :products
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/product.rb
create test/unit/product_test.rb
create test/fixtures/products.yml
create db/migrate
create db/migrate/20080601000001_create_products.rb
-------------------------------------------------------
从上面的输出可以看出,这个命令已经整合起原来的命令方式。

下面是原来的方式:
------------------------
script/generate model product 并且修改db/migrate下的任务
script/generate controller admin  并且修改app/controllers/admin下的admin_controller.rb,增加scaffold :product
------------------------

下面的迁移任务还是同以前一样操作:
--------------------------------------------------------
depot> rake db:migrate
(in /Users/rubys/work/depot)
== 20080601000001 CreateProducts: migrating ===================================
-- create_table(:products)
-> 0.0027s
== 20080601000001 CreateProducts: migrated (0.0028s) ==========================
----------------------------------------------------

可以查看数据的版本:
----------------------------------------------------
depot> sqlite3 db/development.sqlite3 "select version from schema_migrations"
20080601000001
---------------------------------------------------

启动服务器:
---------------------------------------------------
depot> ruby script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2008-03-27 11:54:55] INFO WEBrick 1.3.1
[2008-03-27 11:54:55] INFO ruby 1.8.6 (2007-09-24) [i486-linux]
[2008-03-27 11:54:55] INFO WEBrick::HTTPServer#start: pid=6200 port=3000
----------------------------------------------------

对比下两个版本中操作的便捷程度:
rails 1.2中, 输入命令 5 次,修改文件 2 处,
rails 2.2中,输入命令 3 次,修改文件 0 处。
可以明显看出新版的效率有了如此大的改进,真是让人欣喜。现在Rails仍然处于一个高速发展的阶段,相信不久它很快还能为我们带来更加便捷的开发方式。

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------