Sunday, September 21, 2008

When you copy and paste from the clipboard to vim, you should "set paste" before pasting in order to avoid automatic insertion of "\t" in front of each line.

Friday, January 11, 2008

%s:number\[\d\] = \"\(\a*\)\":number.append("\1"):gc

Saturday, June 09, 2007

n choose k = ((n - 1) choose k) + ((n - 1) choose (k - 1))

Thursday, May 03, 2007

Treap Data Structure

http://www.ibr.cs.tu-bs.de/courses/ss98/audii/applets/BST/Treap-Example.html
Viewing the Contents of a JAR File

http://java.sun.com/developer/Books/javaprogramming/JAR/basics/view.html

Monday, April 30, 2007

VIM tips

Seven habits of VIM

Habit 1: Moving around quickly

/argc n, n, n ... => : set hlsearch *
=> Put :set hlsearch in .vimrc; use * again again

Habit 2: Don't type it twice.
type XpmCreatePixmapFromData() => type CTRL-N on word (word completion)

Habit 3: Fix it when it is wrong.
mis-spell => :iabbrev teh the
:syntax keyword WordError teh

Habit 4: A file seldom comes alone.
:!ctags -R
:tag init
:tnext
:grep "\" **/*.h <- search
:cnext

or gf => Go to file on header file names (work for http)
=> make sure the path option is set correctly.

[I => find the word under cursor to include files.
[ => Jump there.

Habit 5: Let's work together
Working with MsWord
=> set Vim with :set tw=0; wrap linebreak

Copy the text between app and Vim through clipboard.

Monday, April 16, 2007

Useful and powerful replace commands in vim

:.,X s/^/\/\/ comment them
:.,X s/^\/\// uncomment them


This does exactly the same thing but looks cleaner.
:.,X s_^_// comment them
:.,X s_^//_ uncomment them

Thursday, April 05, 2007

If we have a following block,

{
int i = 20;
int j = 40;
...
int k = i * j;
printf("k = %d, i = %d, j = %d\n", k, i, j);
}

Then the compiler would optimize this block in a way that i, j, and k variables never exist, since the block only uses values of them. Also, these values are within the scope of the block too. Thus, the compiler simply replaces the variables with constants. However, if the block ever uses reference or addresses, then it is illegal for compiler to optimize them. In this case, the compiler wouldn't optimize those variables away.