Author Archives: Neucessor

Unix Useful Commands

alias + “pushd .”
alias – “popd”
alias u “cd ..”
alias p “pwd”
>> put in ~/.mycshrc

history | grep command-name
Untar gz:
tar -xvzf file.tar.gz
tar -xvf file.tar


Repeat previous command

  1. up arrow
  2. Type !! and press enter
  3. Type !-1 and press enter.
  4. Press Control+P will display the previous command

Commonly used Vim commands

:sav (save as)
c (change)
d (delete)
{ } (page up, down)
/ (search)
:wq (save, quit)

:%s/findme/replaceto/gc (replace within file, multiple occurence per line, confirmation)

v: Visual Mode
Shift+v : Line Visual Mode
Ctrl+v , then Shift+i : Column-wise Insert

:set autoindent
:set cindent
:set scrolloff=1000

:bufdo %s/from/replace/ge | w (search and replace, to all buffers)

(From command line) ctags -R .
Ctrl + ] = go to definition
Ctrl + T = go back to caller
:set tags=(the topmost ctags file desired)


syntax on
"set autoindent
"set cindent
set smartindent
filetype plugin on

let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

"Set color scheme
set t_Co=256
colorscheme desert256
"colorscheme gardener

"Enable indent folding
set foldenable
set fdm=indent
set tags=../tags

Heap Segmentation Fault – caused by declaration location/scope

Unexpected segmentation faults? Might be your variable declaration.

Here’s the point, declaring variables as global, is commonly known as “do you really need to?” .
Especially if it’s a dynamic sized data structure, like a C++ list.
Yeah  I realized the hard way, the size grew out of static memory bounds and got into the heap.

Good old GDB to the rescue, those error messages might be a mystery at first, it’s still potentially a beacon of hope.

Normalizing in fixed point multiplication

I got one point off in an exam, for mistakenly adding half an LSB for normalizing and then rounding it up. Adding half an LSB and cutting the decimal points off is a rounding mechanism. I unnecessarily rounded up again after adding half an LSB.

Reminds me to understand every detail of an operation.

Wireless bug when ethernet internet is shared in WinXP

After using my netbook as a wifi broadcaster for a mobile device, somehow I couldn’t connect to the campus wireless network.
Turns out the Internet Connection Sharing option was causing the trouble, even though it was set for the Ethernet, not the wireless.
Disable that bit and the wireless was good to go.

Wall Clock Time in Parallel Computing Cluster

If you’re trying to measure the wall clock time on a cluster, either use the library’s getwalltime function (as in OpenMP) or gettimeofday().
Never use clock() as it counts the number of clock cycles of the processors, and if you’re utilizing more than one processor, the number would accumulate and thus producing incorrect (overshoot) results.

Matplotlib on Mac OS 10.5 Leopard

I spent quite a long time trying to get Matplotlib to work, the problem was the dependencies. It somehow couldn’t find Freetype’s headerfiles. To make a long day short, I installed Macports and just to see that it could configures, builds and install packages automatically is such a timesaver and brainsaver. I thought about using Enthought Python Distro (EPD), but it would be an overkill for me, I just need to plot charts from Python scripts.

Using Macports does take away the ‘fun’ and the challenge on hacking Unix systems, but I’ve got studies to do, so I’ll save that for some time in the holidays.

Even after using Macports, it couldn’t find Matplotlib, turns out it was using the old python (2.5) instead of the new one (2.5.5). This happened even though I installed python_select as instructed. Turns out Macport installs to /opt/local/bin instead of the /usr/local, for reasons you could find on their website. Thus, I added /opt/local/bin to the environment variables path (I thought Macports did this already) by this command:

export PATH=$PATH:/opt/local/bin/

notice I put it last so that it would be in the first order. check with env.

Enjoy Matplotlib!

Newbie Matlab Error

Long time no Matlab, got this error:
??? Error using ==> mpower
Matrix must be square.

The mathematical operators *, /, and ^ each should have a dot “.” in front of them. This is a MATLAB convention that ensures that when the function’s argument is a vector of positions.

SSH X Window Forwarding

I was using Mac’s X11 terminal to run a GUI application remotely, when suddenly it gave the dreaded:
Tk initialization failed: no display name and no $DISPLAY environment variable.

Why? There’s no way my machine couldn’t handle X Window Forwarding.

Turns out to enable X Window Forwarding, you need to include the -X command line argument:
ssh -X you@server

This is like checking the enable X11 forwarding box in Putty.

Learning to use Vim

Awesome links


Dynamic Multidimensional Array in C and C++

Here’s how you would declare a one dimensional array in C:

 long* array;
 array = malloc(dimension*sizeof(long));

Equivalent to:
long array[dimension];

For two dimensional array in C, where each element are located in contiguous memory space:

long** array2;
long* tmp;
array2 = (long**)malloc(dimension1 * sizeof(long*));
 tmp = (long*)malloc(dimension1 * dimension2 * sizeof(long));
  for (i = 0;i<dimension1;i++){
	array2[i] = tmp + (i*dimension2);

One dimensional array in C++:

int *array;
array = new int [dimension];

For two dimensional array in C++:

int **array2;
array2 = new int* [dimension1];
for (i=0; i<dimension1; ++i)
   array2[i] = new int[dimension2];

If you get segmentation faults, and you have arrays in your program, most likely it’s because of those pointers. And never try to access a pointer that leads to NULL. Fault!

North Carolina Museums

I’ve been wondering if I could somehow enjoy the taxes that I will pay. Well, last month I visited NC’s Art Museum at Blue Ridge Road, and NC’s Museum of Natural Science. Free of charge.

I did assume the art museum was gonna be boring, but hey, turns out there were fascinating stuff there. One thing you will notice here is that the security guards are everywhere (and yes they watch really carefully, gaze, stare). There were original mummy cases, modern painting (nude as well, I don’t see the art there, but it wasn’t that intruding). There was a display of Monalisa made out of thread spools (rolls of string), but it was made upside down and you had to see it through a round glass ball. Physics with Art, now that’s cool.

The theme going on at the Museum of Natural Science was “Bugs”. Not pretty exciting, since nearly every time I see one, I step on them. Anyway, if you’re a fan of butterflies, fish, rocks, snakes, or atrocious worms, then you’ll love it. One information display shows the history of earthquakes, including real-time updates around the globe. Well, it does look like my home country has high potential of earthquakes. Good thing the East Coast and NC are very safe. But watchout for hurricanes. There’s another exhibit that’s pretty awesome, glow, so you get to see animals with bioluminescence (they light up) 🙂


My favorite file synchronizer for Windows. It’s free for personal use.

Hard Disk Freeware Utilities

I tried to revive a USB flash drive, and found useful utilities here:
Didn’t get mine to work though, the OS doesn’t even recognize it as a drive.