About This Blog

This is Chunhao's Blog

I'm writing something about life and technology here. As a practice of English writing.

My Chinese Blog: http://blog.chunhao.net

My Chinese Page: http://chunhao.net/index-cn.html

Subscribe

The books I’m reading

The items I’m interested in

License

21 May 2009 - 19:39Tools for Reading Sources

Hacking is a good method of learning. And the pre-stage of hacking is reading the source code. You might have this experience: facing a large amount of source code (generally dozens of files), you don’t know how to start, or you even don’t know how to read them. A good tool is very helpful for reading code. It can facilitate your understanding of the code and help you find out the things you want as soon as possible. I will introduce you some wonderful tools of browsing sources.

For me, the must-have feathers of a source browsing tool should be:

  1. Syntax highlighting
  2. Friendly user interface
  3. Identifier and function search

Read more…

No Comments | Tags: Software, linux, programming

24 February 2009 - 0:12How to write an auto-downloading script

如何写一个自动下载的脚本?

用Linux有一个很好的地方就是你可以很方便地让计算机为你做体力活。当然,前提是你要了解Linux的思维方式。下面就是一个活生生的例子,大家可以看看用Linux是怎么做事情的。

如果你喜欢听评书,这里是个不错的地方。这个网站有很多评书,还有百家讲坛,甚至有声的金庸小说。上面的东西不光可以在线听,而且都可以免费下载,不用注册。但是,只能一个链接一个链接地下载。例如,如果想下载《大唐惊雷》第1回,就要进入一个页面,然后点下载;要下载第2回,就要进入另一个页面,然后再点下载。这样,就无法批量下载一整部评书了。

如果你用Windows,那么你要么人肉点击这些链接,一个一个地下载(可能有100+回);要么就用C或者Java写一个程序自动下载,前提是你要懂网络编程的细节。

下面,我就说一说在Linux下如何用Shell写一个自动下载脚本:

Read more…

3 Comments | Tags: linux, programming

22 February 2009 - 23:02Unify the themes

My site is based on various applications. The blog is based on Wordpress, the wiki is based on Dokuwiki, the photo gallery the Simpleviewer. Other pages are written by hand.

Originally, each part had its own theme. It’s hard to acces other parts directly from one part. For example, there are no links from my blog or wiki to my homepage. I decided to change this. Eventually, the goal is achieved.

The theme of my blog is blue-pix. I like it for its briefness. The first thing I did is to port this theme on my home page. This work is pretty simple. I only changed the tags of the CSS file. Then, I modified the blog’s theme, added a link to homepage. The themes of homepage and blog was unified.

Next thing is my wiki. I have no idea about how to create template on dokuwiki at the beginning. When I refered to this link, I started my work. I did a lot of change on CSS and PHP files. Finally, my own template of dokuwiki was created. Now the themes of the whole site is unified, except for the photo gallery.

For the blog’s theme, blue-pix, I also did lots of modification. The originally version did not support widget, and it did not support Google Analytics and other things. It also did not support thread comments. Now, it works fine. If you are interested in this theme, just feel free to contact me.

I am not an expert on PHP, CSS, and HTML. However, I like hacking. All the problems are solved with the help of Google. I believe one sentence–don’t learn to hack, just hack to learn.

———–

Supplement:

Just now, I finished the modification of my photo gallery. Now, everything in my site are following the same theme!

1 Comment | Tags: other, programming

13 September 2008 - 0:19Command & Conquer

首先,这篇日志和技术有关,应该用英文写的,但里面夹杂了一些中文的元素,就写成中文了。

这个题目,作为游戏的名字就是“命令与征服”,作为Full Circle中文杂志的一个栏目名,就是“决胜命令行”。

人们总在做关于图形界面与命令行的争论,其实,二者各有优缺点。图形界面总能给人一种直观的感受,在一定程度上提高工作效率。但是,任何事都有它的局限性。如果画一个圆,里面的空间代表图形界面所擅长的工作,那么,这个圆环外面的整个空间都应该属于命令行!

命令行也有它的局限性,用手敲命令的时间有时并不一定比把鼠标移到某个菜单并点一下快。而且,尤其是对于非英语国家的人来说,了解那么多的命令和参数并不是一件容易的事情,尽管man命令可以帮助我们很多。

命令行的一个杀手应用就是批处理。如果你需要对几十个,甚至几百个文件进行类似的操作,摆在你面前的有三条路:1. 等专门的软件被写出来。2. 自己纯手工对这几百个文件处理。3.动手写个脚本。

在Linux世界,如果你要完成一项工作,有三条法则:

  1. 如果有现成的软件,使用它。
  2. 如果需要使用几个软件来完成,用管道或其他东西把他们连接起来。
  3. 否则,自己写程序完成它。

使用命令行,使用脚本,应该是介于第二条和第三条之间。脚本是用于把几个程序连接起来的工具,当然,也算是自己写的一个程序。

在批处理中,我们可以通过脚本,通过定义的一些变量,甚至一些循环、判断语句来很轻松地完成工作。当然,这一些的基础就是命令行,脚本很难通过图形界面和其他程序交互。当然,也有一些在命令行中生成GUI的工具,例如zenity

大概半年前,我做史记的电子书。其中,一个文件夹下的文件是这样的:

Read more…

No Comments | Tags: linux, programming

19 March 2008 - 1:22How to connect vim with gdb — using clewn

screenshot3.png

First, I will show you the screen shot The screen of vim is divide into two sub windows, the top one can display the code and the bottom one shows the variable you want to watch. Well, this can be changed by you, you can split the window any way you like. You can use C-B to make a break, and press R to run your program, and press S to step, and C-J to add the variable you want to watch. You can download clewn here:

http://clewn.sourceforge.net/

How to install: first of all, you should have your gvim installed,

sudo apt-get install vim-gnome

as well as gdb And then download the source file of clewn; note here, not vimgdb. And extract the file, then use your terminal to enter the clewn folder

./configure make sudo make install

Note here, may be some one will be suffered from the dependency problem during their installing. If your machine tell you that you need readline, then install libreadline5-dev

sudo apt-get install libreadline5-dev

And then, copy some files to ~/.vim you can refer my folder:

cp /usr/local/share/vim/vimfiles/clewn.vim ~/.vim/plugin/

cp /usr/local/share/vim/vimfiles/doc/clewn.txt ~/.vim/doc/

cp /usr/local/share/vim/vimfiles/macros/clewn_mappings.vim ~/.vim/macros/

cp /usr/local/share/vim/vimfiles/syntax/gdbvar.vim ~/.vim/syntax/

Then, every thing is done. You can write a small program to test.

#include 
 
int main(int argc, char *argv[]) {
  int i;
  int s;
  s = 0;
  for (i = 0; i < 10; ++i) {
    s = s + 1;
  }
}

Save it as test.c , for example. And then,

gcc -g -o test test.c

If everything is right during compiling, then

clewn -va test.c

Then, gdb is opened on your terminal, and your gvim is opened at the same time Cool down now; input the following on your terminal(gdb):

file test

Now, you can debug your program on gvim. For example, you can click the line you want to set break point. And then press CTRL+B, then, break point is set. SHIFT+r(that is capital R)It will run and stop at your break point SHIFT+s(that is capital S)It will step And watch your variable, input following on gvim

:split

Then the window will be split, and then click the variable you want to watch, and press C+J, then you can see the variable appears in another window. To do this, you also can input the following on your terminal(gdb)

createvar yourvar

“youvar” represents the variable you want to watch. Following is the default shortcuts

List of default key mappings:

        CTRL-Z  send an interrupt to GDB and the program it is running
        B       info breakpoints
        L       info locals
        A       info args
        S       step
        I       stepi
        CTRL-N  next: next source line, skipping all function calls
        X       nexti
        F       finish
        R       run
        Q       quit
        C       continue
        W       where
        CTRL-U  up: go up one frame
        CTRL-D  down: go down one frame

cursor position: ~
        CTRL-B  set a breakpoint on the line where the cursor is located
        CTRL-E  clear all breakpoints on the line where the cursor is located

mouse pointer position: ~
        CTRL-P  print the value of the variable defined by the mouse pointer
                position
        CTRL-X  print the value that is referenced by the address whose
                value is that of the variable defined by the mouse pointer
                position
        CTRL-K  set a breakpoint at assembly address shown by mouse position
        CTRL-H  clear a breakpoint at assembly address shown by mouse position
        CTRL-J  add the selected variable at mouse position to the watched
                variables window

This is referred the official document, which is available here

http://clewn.sourceforge.net/doc.html

Hope this will help you somewhat. If you have some new or better idea, please contact me. chunhao86@gmail.com Thanks

5 Comments | Tags: linux, programming, vim