Archive

Archive for December, 2009

My Vimrc File

December 24th, 2009 西坪 No comments

Apply the recommend vimrc file:

cp /usr/share/vim/vimcurrent/vimrc_example.vim  /usr/share/vim/vimrc

~/.vimrc: Keep it simple!

" 设置文件编码检测类型及支持格式
 set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
 
 "显示行号
 set nu!
 
 " 中文帮助
 if version > 603
 set helplang=cn
 endi
 
 " 设置代码自动缩进
 :set cindent
 
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 " cscope setting (from http://easwy.com/blog/archives/advanced-vim-skills-cscope/)
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 if has("cscope")
   set csprg=/usr/bin/cscope
   set csto=1
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
       cs add cscope.out
   endif
   set csverb
 endif
 
 nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
 nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
 nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
 nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
 nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
 nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
 nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
 nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
Categories: Tools & Tips Tags:

Arguments on Java & C++

December 23rd, 2009 西坪 No comments

The Hypertable Team claimed they choose C++ to be Hypertable implement language for performance issues. They gave two points about that, Hypertable is memory (malloc) intensive and and CPU intensive. They also say:

(Hadoop)There are some places where Java is sub-optimal. In particular, at scale, there will be considerable memory pressure in the Namenode of the DFS. Java is a poor choice for this type of memory hungry application. Another place where the use of Java is sub-optimal is the post-map sorting in preparation for the reduce phase. This is CPU-intensive and involves the type of CPU work that Java is not good at.

There are a bunch comments on the Wiki Page. Someone gave another views. A guy gave two links to support Java is not so bad.

Some interesting comparative articles.

http://www.ddj.com/cpp/184401976?pgno=1

http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

Categories: $Programming Tags: ,

My Ubuntu Installation log

December 18th, 2009 西坪 No comments

业余使用Ubuntu好些年了,装了删删了装的,为了以后方便,把这次的新版本的安装配置过程都记录下来。

第一步,从官方下载 Ubuntu-desktop。

第二步,在VMWare上安装,并安装VMWare-tools。 在ubuntu-desktop-9.10上,不像以前需要手工安装一些包,安装linux头文件,这次一路回车就搞定了。

到这里系统就算安装完毕,发现已经用去了8G硬盘的 37%。

(update 2009-12-28): 事后发现根本没有装好,再次尝试安装,基本上各个模块编译时都会出现error日志,并报告模块没有成功编译。而原来在 ubuntu 8.10下是工作正常的。 为什么升级到 ubuntu 9.10就出错了呢?一开始在网络上搜索,看过 VMware workstation fails after 9.0.4 upgrade to 9.10, 根据该帖建议去打补丁, 但是都没有解决。

后来,去Vmware官方找了下是否有更新,结果发现 VMware Workstationfor Windows 出了新的6.5.3版本, 在 Release Notes 中发现 Ubuntu 9.04 is fully supported. 猜测也许是需要新版本。 尝试下载新版本安装后,重新安装和配置 vmware-tools, 一切顺利!

第三步,安装我需要的各种软件。

0. 设置source.list,我使用 mirrors.163.com.
设置网卡:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.126
netmask 255.255.255.0
gateway 192.168.1.1

#auto eth0
#iface eth0 inet dhcp

1. 安装 vim/ctags/cscope, 设置颜色,缩进等。 The details are noted at Here.

  • install: sudo apt-get install vim
  • Install Chinese vim help: download from http://vimcdoc.sourceforge.net/, tar and enter the directory, execute
  • sudo ./vimcdoc.sh -i
  • sudo apt-get install exuberant-ctags cscope

2. 安装 JDK/C++工具:

sudo apt-get install sun-java6-jdk sun-java6-source
sudo apt-get install build-essential

3. 安装manuals:

开发用的手册页:

sudo apt-get install manpages-dev

安装 Posix 相关的手册页。pthread 库相关的手册页就在这里面,而不在 Dev manual pages 中。

sudo apt-get install manpages-posix manpages-posix-dev

安装 STL library man pages:

sudo apt-get install libstdc++6-4.2-doc

4. 安装版本工具 Subversion 和 Git:

sudo apt-get install subversion subversion-tools git-doc git-core

5. Configure SSH server:

sudo apt-get install openssh-server

.
6. Install LAMP server by tasksel, and configure;
7. 中文支持。我安装系统时用的是英文,因此 LANG=’en_US.UTF-8′。中文输入遵循下面三步骤即可:

  1. Install Simple Chinese Language support.
  2. install: sudo apt-get install scim scim-pinyin
  3. System->Administration->Language Support->Input Method, select scim.
    1. Reboot system, 此时就可以使用智能拼音了。

Resource: SCIM Setup, SCIM Usage

中文问题的解决没有这么简单,还存在下面的问题:

  • gedit不能打开中文文件: 这个文件主要是gedit猜测编码的机制造成的,略加修改就可以。具体参考这里
  • vim不能打开中文文件:Here
  • pdf不能阅读某些中文文件: 问题的症状是能够阅读某些中文pdf,但是还有一些pdf则表现为乱码。问题的原因不太清楚,但是Google后安装了一个新包 poppler-data,就解决了。(sudo apt-get install poppler-data)

8. 安装 CHM 格式文档查看工具 kchmviewer.

sudo apt-get install kchmviewer

但是 kchmviewer 在查看 boost中文文档页时出现了编码错误。当然这不一定就是kchmviewer有问题,也可能是boost中文文档本身的兼容性等。于是另外安装了chmsee, chmsee的另外一个优点就是安装时体积很小,下载过程中才下了几百K。当然也可能是因为我提前把其他需要的库都已经装上了…
9. ruby gems:

sudo apt-get install rubygems1.9.1

10. 声音问题的解决:这里

Categories: Tools & Tips Tags:

设计与开发的五条原则

December 15th, 2009 西坪 No comments

从2004年初(大学二年级第二学期)加入学校就业信息网站,靠写代码获得第一笔收入,迄今已经将近六年。

第一条原则,首先弄清你的问题是什么。这一条规则无论怎么强调都不过分。

《Programming Pearls》第二版的开篇,Jon Bentley 讲的就是,首先弄清你的问题是什么! 在你没有详细、明确地定义好你的问题之前,你所做的大部分工作只产出废物。这些年,最头疼的事情,就是经常搞了一大堆东西,累死累活,甚至加班加点,最后总才发现很多事情偏离了目标。但这样的事情,总是在周围一遍一遍地发生。

一个工程师,如果在接到一个问题时首先不是尽可能挖到细致的资料,定义问题,并向了解问题的人去反馈,详细讨论问题的定义。虽然问题定义不是那么容易,但不首先定义好问题,那就是不合格的工程师。

还有很多原则,大抵都是这个原则的派生品。

第二条规则, 弄清你要干什么,以及哪些先干,哪些后干,哪些根本就不需要干。

说白了,就是把问题分解,列个表,排个先后顺序。这是大部分程序员最蹩脚的部分。高效的本质不是捧着ThoughtWorks那本《卓有成效的程序员》,而是我这条原则。我对Joel的书里印象最深刻的就是有关用Excel列任务列表的部分。

这条仍然是如此重要,以致于著名的YAGNI, (You ain’t gonna need it )仅仅是一条推论而已。

当然,区分的标准是什么?It depends. 但是最重要的参照是,怎么做你能获得最大产出?也许你会在所谓的扩展性、适应需求变化与可工作的代码,用户的需求之间抉择。 最重要的还是可工作的代码,能够按时 ship the beta!

记住,先列出来要干什么;然后分清先后顺序,然后淘汰那些可以不干的。

第三条规则,KISS。 Keep It Simple Stupid。
用郭靖和杨过来比喻,代码要像郭靖一样用最简单直接的方式强壮地工作,不需要太多的波折。你的程序要是像杨过的人生那么复杂、聪明,早死翘翘了。 你的程序要简单强壮地干活,思想越简单越好,功能和特性越少越好。

这一条对于设计是至关重要的,浮躁的程序员们经常要在架构设计中引入模式、分层,又或者是绚丽的Ajax效果之类,完全是无知下的自虐。我也是好些年后才明白这条道理,直到后来开始使用Unix下的那些让无数人着迷的工具,才真真地看到了这条规则的巨大威力。

要特别澄清一下,KISS 与你的程序是否好用,是否易于复用,不但不矛盾,而且是相辅相成的。你要知道的只是你的程序应该做什么,然后努力做好。借用《Programming Pearls》开篇里法国作家兼飞机设计师的话:“设计者确定其设计已经达到了完美的标准不是不能再增加任何东西,而是不能再减少任何东西”。又如Chuck Yeager将军(第一个超音速飞行的人)赞扬一架飞机的机械系统时的用词是“结构简单、部件很少、易于维护、非常坚固”。

第四条规则,一键集成和适当的自动化测试。

这条不多说了,在有条件的情况下做会受益非浅。

其他还有一些很有名的原则,例如 DRY (Don’t Repeat Yourself), 也许是因为一开始我就懂得了这个道理(尤记得大学的时候把ASP代码提取函数,封装Head和Foot,将写HTML Table的封装成方法来根据不同的数据集打印,好傻。),感触没那么深。

六年了,好快。

(Update 2009-12-23)
第五条: 一定需要且只需要数页简单明了的设计说明书。

这个设计说明最好不用word,最好是放在源代码下的html或者txt格式。简单粗线条的UML最适宜用在这种地方。当然设计文档也可以放在别的地方。

P.S.
用原则这个词,是为了强调重要性。遣词或有问题,慎自斟酌之。

Cygwin下使用公钥登录SSH

December 2nd, 2009 西坪 No comments

为了直接使用公钥登录SSH,而不使用密码登录Cygwin,费了老大劲,很长时间以来一直没有成功。此前,一直是按照网络上流传的方法,主要是生成key,然后设置到 authorized_keys中。遵照官方的命令,修改sshd_config, ssh_config, 但是一直没有奏效(不过遵照这些方法,在Ubuntu等系统上配置成功)。

昨天偶然在这个页面上看到 ssh-user-config 命令,试了试,就成功了!各位设置不成功的同学,考虑使用下这个命令,然后一路回车确认即可。

另一篇重要的参考文章:这里

顺便记录下在探索 SSH使用公钥登录过程中学到的几个sshd相关的命令:

# debug more information 
ssh  -vvv  localhost
 
#start services
net start sshd
#or
cygrunsrv  --start  sshd
 
#login command for user name that has space
ssh  Mickey\  mouse@127.0.0.1
 
#copy publickey to remote host ( 或使用 ssh-copy-id, e.g ssh-copy-id -i ~/.ssh/id_dsa.pub user@host )
king@king:~$ cat .ssh/id_dsa.pub | ssh master "cat - >> ~/.ssh/authorized_keys"
#copy publickey from remote host
king@king:~$  ssh master "cat .ssh/id_dsa.pub" | cat - >> ~/.ssh/authorized_keys"

在某些情况下,必须使用代理登录SSH服务器。connect.c is the simple relaying command to make network connection via SOCKS and https proxy. It is mainly intended to be used as proxy command of OpenSSH. You can make SSH session beyond the firewall with this command.

在Windows下,只需要下载connect.exe到c:/windows,然后在 ~/.ssh/config中添加如下配置:

ProxyCommand connect -S x.x.x.x:x %h %p

connect.c 还支持 https 代理,真不赖。

Categories: server & system Tags: