Friday, March 5, 2010

vim script: automatic setup "include guard" for new c/c++ header file


function! FileName()
return expand('%:t')
endfunction
function! HeadName()
return toupper(substitute(FileName(), '\.', "_", "g"))
endfunction
function! IncludeGuard()
let lines = []
let lines += ["#ifndef " . HeadName() . "_"]
let lines += ["#define " . HeadName() . "_"]
let lines += [""]
let lines += ["#endif"]
return lines
endfunction
autocmd BufNewFile *.h call append(0, IncludeGuard())


:e abcd.h
#ifndef ABCD_H_
#define ABCD_H_

#endif

Sunday, September 13, 2009

bash tips for efficiency

set show-all-if-ambiguous on
If you have this in your /etc/inputrc or ~/.inputrc, you will no longer have to hit the Tab key twice to produce a list of all possible completions. A single Tab will suffice.

set visible-stats on
Adding this to your /etc/inputrc or ~/.inputrc will result in a character being appended to any file-names returned by completion, in much the same way as ls -F works.

"\ep": history-search-backward
"\en": history-search-forward
Set the above in your /etc/inputrc or ~/.inputrc. Then, ESC-p and ESC-n (or M-p and M-n) will give you non-incremental history completion backwards and forwards, respectively.


Friday, September 11, 2009

Testing is not enough

"Any failure during testing should be analysed to understand the root causes:

1. how the error came to be introduced
2. why the development processes failed to detect the error earlier - so that other errors of this class are found too and so that the processes can be improved to avoid such errors in future."

"Errors should no longer be regarded as inevitable"


--- from <<Engineering values in IT>>

Monday, May 11, 2009

finally setup juniper VPN network on home laptop with Arch Linux

1. get firefox
2. get JRE (openjdk6)
3. login company VPN website
4. start network connection session - but "conection failed!"

Google can not help... the wired thing is that the same environment of Arch Linux + firefox + openjdk6 inside VirutalBox of my another laptop with XP at office works perfectly... should this be related with IP address? but I tried once at home with XP's IE, it also works...

After spending another 2 hours here and there on website, finally I got the soluation still from ArchWiki:
"3. Do "sudo modprobe tun". You'll need to do it every time before you connect. So you might want to setup the tun module to be autoloaded at start up to save you time and trouble. "

after that, everything turns out perfect.  I guess my previous install of KDE or something else on the VirtualBox Arch Linux enabled "tun" module by default.

From now on, I don't have to bring the heavy Dell 630 to home every weekend.

What do you think of marketing?

Monday, April 27, 2009

VirtualBox + Arch Linux + LXDE

很久以前用过vmware,但是每次要自己装一遍linux,当时来说也是一件很复杂的事情;后来一直用vmware player, 直接下载一个ubuntu的virutal application就可以了,的确很方便, 自己也可以再装些别的软件。不过vmware player好像是不直接支持vmware tools, 以前花了很多时间googling,弄成功过一次。 但是前两天, 脑子一抽筋去把vmware player升级到了2.5, 原来那些shared folders, 屏幕自动缩放的功能就彻底废了。。。搞得巨不爽, 但又不想再重复以前的痛苦过程,于是就想到了virtualbox.

但是用virtualbox也是要自己装os才行的。刚好最近看到一篇在Arch Linux上装KDE 4.2的blog ,那效果真的很炫。而且过程貌似也很简单, 好像只要 pacman -S kde 就可以了(其实,第一次的弄的话,总还是要费很多周折, 不过能学到不少有用的东西)。 所以就决定在virtualbox上装个arch linux,然后pacman -S kde 。。。

1. 先找到virtualbox的主页,然后下载安装。 基本上就是一般的windows xp上装个软件, 就是中间会报一大堆的warning说这个软件没有通过windows的兼容性测试。装完不用vmware那么多的重启,就可以直接用了。 感觉没有vmware那么笨重。

2. 然后在virtualbox里面创建一个virtual machine。 根据向导就行了,不过中间犯了一个严重错误:没有仔细看虚拟硬盘文件的max disk size的意思,以为dynamic expansion的话, 就可以随便设置(只给了2G)。到后来, 没有硬盘空间,加上都有的东西都在一个分区里, 只要重新来过。 实际上,这里设好了以后, 就是虚拟硬盘的大小。 不过,用完了以后,可以再创建新的attache给virtual machine。

3. 前面应该已经下载好arch linux的iso了。有两种ISO文件, 一种是带core的300多M大小;另外一种是不带core的150多M,但是要通过网络下载core文件来安装。 所以选带core的装起来会比较快。

4. 显然,windows host上要个虚拟光驱的软件(像DAEMON Tools)用来加载arch linux的ISO文件。 这样,在启动虚拟机的时候,Arch Linux的live disk 就会自动boot up。选live disk那个选项进入,用root帐号登录,就可以开始安装了。

- to be continued...

Thursday, March 19, 2009

补常识

讲的是,something you should know, but may don't know。所以叫补常识。
大家可能都会注意到: 在马路两边的人行步道上铺的地砖中间会夹杂一些大块、稍微凸起的砖头。以前一直没明白到底是干吗用的,也许是装饰吧, 或是跟排水有关?有时候觉得会磕磕碰碰, 还有点不方便。
今天终于明白了:原来是给视力上不方便的人用的。 所以颜色也特别醒目。
并不是自己突然变聪明了。 其实有人在新修好的路砖上专门贴了纸条:“这个是给视力不方便的人用的, 请不要把东西放在上面”。
这样一来,下次拖着拉杆箱 咯噔经过的时候, 就不会抱怨碍事了。