Nov 23, 2011

Install ns2.1b9a + TENS in Ubuntu 10.04

ns2.1b9a which is an old version NS2 has very strong OS dependency, so I choose Ubuntu 10.04(64-bit).

-------------------------------------Install NS2-----------------------------------------------------------

1) First of all, download the NS-2 package ns-allinone-2.1b9a-gcc32.

2) Install "build-essential" and "libxmu-dev"

sudo apt-get install build-essential

sudo apt-get install libxmu-dev

3) Because in Ubuntu10.04, the gcc compiler version is gcc-4.4 which is too high to compile ns2.19b, we have to install gcc-3.3 and g++-3.3 by ourselves.

Go to and download

"cpp-3.3_3.3.6-15ubuntu6_amd64.deb" "g++-3.3_3.3.6-15ubuntu6_amd64.deb" "gcc-3.3-base_3.3.6-15ubuntu6_amd64.deb" "gcc-3.3_3.3.6-15ubuntu6_amd64.deb" and " libstdc++5-3.3-dev_3.3.6-15ubuntu6_amd64.deb"

. (Depend on your system, the version may be different) Then install them by sudo dpkg --force-depends -i xxx.deb

To check compiler version, we use ls /usr/bin/gcc* -ll or ls /usr/bin/g++* -ll. We also can add the compiler options

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3

To change the default gcc version, we use

ln -sf /usr/bin/gcc-3.3 /usr/bin/gcc

ln -sf /usr/bin/g++-3.3 /usr/bin/g++

4) Now we are able to install NS2. First of all, tar xzvf ns-allinone-2.1b9a-gcc32.tar.gz and touch ns-allinone-2.1b9a/tcl8.3.2/generic/tclStubInit.c

5) Before running "./install", we have to modify some files (This is very important!!). Go to ns-allinone folder,

find . -name configure

You will see a list of configure files. Replace any line which is like system=MP-RAS-`awk '{print $3}' /etc/.relid'` to system=MP-RAS-`awk '{print $3}' /etc/.relid`

The original one will cause the error in tcl8.3.2, tk8.3.2 and otcl-1.8, checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string tcl8.3.2 configuration failed! Exiting

6) Modify otcl-xx/config.sub, tclcl-xx/config.sub and configure file in Nam folder.

Where "| x86 |"
appears, you must put "| x86 | x86_64 |". Where "| x86-* |" appears, you must put "| x86-* | x86_64-* |".

In nam config.sub file, it may not have "|86|", so just find out "case $basic_machine in"

It will cause the error, checking build system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized configure: error: /bin/sh ./config.sub x86_64-unknown-linux-gnu failed otcl-1.8 configuration failed! Exiting ... or x86_64-unknown-linux-gnu failed nam1.0a11a configuration failed!

7) After the modification, ns2 may be compiled successfully. Just run ./install

8) When it is done, edit .bashrc file and configure environment variables. Put them at the end of file.
export NS_HOME=/home/XX/ns-allinone-2.1b9a

export PATH=$PATH:$NS_HOME/bin:$NS_HOME/tcl8.3.2/unix:$NS_HOME/tk8.3.2/unix

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NS_HOME/otcl-1.0a8:$NS_HOME/lib:$NS_HOME/tcl8.3.2/unix:$NS_HOME/tk8.3.2/unix

export TCL_LIBRARY=$NS_HOME/tcl8.3.2/library/

9) Finally, source .bashrc

cd ns-2.1b9a


The Test may not be successful, but it will not effect too much.

--------------------------------------Install TENS------------------------------------------------------------

10) After the NS2 installation, we will start to make The Enhanced Network Simulator (TENS). So just follow the tutorial (

The only thing is that when type in make depend, it may have an error pcap.h is not found. So open the Ubuntu Software Center, search libpcap and install all the related packages.

11) Congratulation! It is done!

Nov 18, 2011

Interview Test 2011

Here is some of the written exam questions in the interviews I attended. They are just based on my memory, so maybe I forget some parts. And mostly they are about IT, mobile programming, software engineering and networking technology.

# What do you think is the most important ability for a software developer? And why?

# What is TDD? Plz describe it.

# What are the differences between composition and inheritance in OO programming? Which one do you prefer?

# What are the heap and stack? Plz give an example by C or C++ to explain them respectively.

# Now you have a table like this,

Name      Home      Phone      Email

Paul      London      92821921

Amy      NY      92712345

John      HK      54378722

Paul      NY      86433478

Plz use SQL to make it as the name is unique, like "Paul, Amy, John".

# Plz give three database engines.

# What is the difference between auto-generated primary key and item`s primary key? Which one will you use and why?

# Plz give three mobile OS. And What is their processor structure respectively?

# What are the three primary data types in C programming? What are the three non-primary data types?

# What is the exact output of the follow PHP script?

< ?php

$i = 1;

$a = &$i;

$b = $a++;

print $a;

print $b;

print $i;


# Plz illustrate the two way communication process of an instant message software. You just need to write the pseudo codes.

# In object-oriented programming, what are the meanings of a) abstract class, b) object interface?

# In MySQL, what is the difference between left join, right join and inner join?

# What is bad about this line of code and how can you improve it?

$db->query(“SELECT username FROM user WHERE userid=”.$_REQUEST[‘uid’]);

# Please write a function to remove all html tags in a string, using regular expression.

# Please describe how to do character conversion from Traditional Chinese to Simplified Chinese using PHP.

# Please write a function to calculate the number of days between 2 dates.

# Please describe how you can schedule a daily job to remove log files older than 3 days, under a certain directory in a Redhat/CentOS Linux machine.

# In IE6, how to make a < div > 1px height with CSS?

Oct 25, 2011

Command Line on Mac

In OS X, when we use X11 terminal we may think it`s too small and not customized.

On command line of X11, we could activate one more terminal windows using this command < xterm -fa Monaco -fs 14 -fg white -bg black & >.

Although this command provides us as many self-defined terminals as we need, it still has some limitations, such as it does not support text copy on the window, we can not know current path name unless typing pwd and etc.

Anyway, here we just talk about the usage of this xterm command.

May 24, 2011

A simple method to reset your HTC Hero phone

If you want to perform Factory Reset your HTC mobile phone, you could do it like this,

1 Switch off the phone (either removing the battery or shutting down by holding the "end call" button for few seconds

2 While being switched off, hold the "home" (house) and "back" (the arrow in the lower right corner)

3 Hit briefly the "end call" button" while still holding the "home" and "back" buttons.

4 Release the "home" and "back" button, a white screen containing technical information should appear, with a red message asking
for hitting the "menu" button.

5 Hit the "menu button", the Hero will now boot with factory settings.

Somebody says you also have another way which is "HOME > MENU, then tap Settings > Security > Factory data reset" to reset the phone. But I do not find there is an item called "Factory data reset" under "Security" tab. So I think the first method is easier and better.

May 19, 2011

How to record command line output

if we want to record the output in Linux command line, we could use "script" command.

script [-a] [-f] [-q] [-t] + file name


Append the output to file or typescript retaining the prior contents.


Flush output after each write. This is nice for telecooperation: One person does `mkfifo foo; script -f foo' and another can supervise real-time what is being done using `cat foo'.


Be quiet.


Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays.

To exit the recording, we need to use "ctrl + d".

For example, we record the command line output to a log file whose name is "MyRecord".

$ script MyRecord.log

Then it will begin to record all the information displayed by command line. Finally, "ctrl + d" will exit and it will show "Script done, file is MyRecord.log"

Mar 15, 2011

Use time function to get timestamp in nanoseconds on Linux

#include < time.h >

#include < stdio.h >

int GetTime()

   struct timespec tsp;

   clock_gettime(CLOCK_REALTIME, &tsp);   //Call clock_gettime to fill tsp

   fprintf(stdout, "time=%d.%d\n", tsp.tv_sec, tsp.tv_nsec);



Mar 13, 2011

Exit full screen mode on Chicken of the VNC, Mac OS

When VNC is working in full screen mode, we need to use the key combination

"[CTRL] + [alt/option] + [Apple command] +[`]" to exit it.

How to compile VLC source code on MacOS and Fedora 12

1) On Mac OS (According to

[*] Set the development environment

Install the Mac OS X Developer Tools or get them online.

You need at least Mac OS X 10.5 and Xcode 3.1.4 for compilation. Mac OS X 10.6 and its 3.2.x Xcode releases are also supported. Make sure that the LLVM GCC 4.2 compiler is installed.

Compiling with earlier releases of Mac OS X and/or Xcode will not work.

Additionally, you may need to install Subversion (SVN) and more importantly Git on your Mac.

[*] Get the source

Download the VLC media player source code (using Git) as described on the "Get the source" page or get a recent source tarball.
Note that the 3rd party libraries will probably break a few months after the release's publication.

[*] Build external libs

$ cd extras/contrib

$ ./bootstrap

$ make

[*] Prepare the VLC build

Now we return to VLC itself. Go back to the top level VLC source directory.

$ cd ../..

$ ./bootstrap

This will create configure and Makefiles for VLC media player (snapshots and releases already include this).

[*] Setup the correct compiler

Current revisions of VLC need to be compiled using Apple's llvm-gcc-4.2 compiler in its latest version. In case of failures, make sure that the latest version of Xcode is installed. To use this compiler, you need to export the respective variables. In a Bourne Shell, type this (if Xcode is installed to its default location; bash is the default shell on OS X):

$ export CC=/Developer/usr/bin/llvm-gcc-4.2

$ export CXX=/Developer/usr/bin/llvm-g++-4.2

$ export OBJC=/Developer/usr/bin/llvm-gcc-4.2

[*] Configure the VLC build

The next step is to configure, in the top level VLC source directory. In current revisions, you can simply run

$ ./configure --enable-debug

[*] Build VLC

After configure is finished, we can finally build VLC media player. A simple make will do the trick. If you want to use the resulting application package on a different Mac or a different account on the same Mac, run

$ make

$ make

2) On Fedora Linux

[#] Download vlc source code 1.1.5 and log on Linux as root user

[#] $ tar -xzvf

[#] Compile vlc by ./configure --prefix=/usr --enable-run-as-root

(--prefix=/usr is the directory for the installation)

[#] If get an error "configure: error: Could not find libmad on your system: you may get it from Alternatively you can use --disable-mad to disable the mad plugin.
configure: error: Could not find lua. Lua is needed for some interfaces (rc, telnet, http) as well as many other custom scripts. Use --disable-lua to ignore this error."

Then search and download lua-devel from internet. And install it by "yum install lua-devel"

[#] Compile libmad

Download source from, and compile ./configure --prefix=/usr

If it has make error, "cc1: error: unrecognized command line option "-fforce-mem"
make[2]: *** [version.lo] Error 1
make[2]: Leaving directory `/home/izhier/download/libmad-0.15.1b' ", modify the makefile to delete -fforce-mem.

[#] $ ./configure --prefix=/usr --with-mad=/usr

If it has error, "configure: error: Could not find libavcodec or libavutil. Use --disable-avcodec to ignore this error.", download ffmpeg from internet.

compile ffmpeg by "./configure --prefix=/root/soft/ffmpeg --enable-swscale --enable-postproc --enable-gpl" and then

$ make

$ make install

[#] If it has error about libavcodec, use

$ export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/ffmpeg/lib/pkgconfig"

To test it,

$ pkg-config --modversion libavcodec

Then it will show "52.20.1"

[#] Compile vlc by "./configure --prefix=/usr --with-mad=/usr"

If it has error, "configure: error: Could not find libswscale. Use --disable-swscale to ignore this error. Proper software scaling and some video chroma conversion will be missing.", use

$ ./configure --help|grep swscale

it will show "--enable-swscale enable GPLed software scaler support [no]". Then, go back to ffmpeg directory and install it again,

$ ./configure --prefix=/usr/ffmpeg --enable-swscale

$ make

$ make install

[#] If it has error, "checking for ffmpeg/swscale.h... no checking for POSTPROC... no configure: error: Could not find libpostproc. Use --disable-postproc to ignore this error.", use

$ ./configure --help|grep postproc

it will show "--enable-postproc enable GPLed postprocessing support [no]"


$ ./configure --prefix=/usr/ffmpeg --enable-swscale --enable-postproc --enable-gpl

[#] If it shows error "checking for a52dec/a52.h... no
configure: error: Could not find liba52 on your system: you may get it from Alternatively you can use --disable-a52 to disable the a52 plugin.", download a52 from "" and then,

$ ./configure --prefix=/usr

$ make

$ make install

[#] Compile vlc,

$ ./configure --prefix=/usr --with-mad=/usr --with-a52=/usr

If it has error, "checking for FRIBIDI... configure: error: Package requirements (fribidi) were not met:
No package 'fribidi' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables FRIBIDI_CFLAGS
and FRIBIDI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.", download fribidi from website "" and then install it,

$ ./configure --prefix=/usr

$ make

$ make install

[#] Compile vlc,

$ ./configure --prefix=/usr --with-mad=/usr --with-a52=/usr --enable-run-as-root

$ make

$ make install

[#] Now VLC on Fedora could be installed successfully!

Mar 9, 2011

MATLAB will crash when using FIGURE or PLOT function. Solution to version R2008b on Mac OS

I use MatLab R2008b all the time. But after I upgrade my Mac OS, it always crashes when the PLOT or FIGURE function is called.

Now MathWorks post the solution as the following,

The crash is possibly related to upgrading the Mac OS to version 10.5.8 or 10.6.8. This issue has been seen in MATLAB R2007a, R2007b, and R2008a, including both Professional and Student versions. Please note that OS 10.6 is not officially suported for MATLAB R2007a, R2007b, and R2008a.

Configurations reported with this crash:


Mac OS 10.6.8 with Java 1.6.0_26

Mac OS 10.5.8 with Java 1.5.0_30


If MatLab upgrading is not an option, as a workaround, replace a statement in the file as follows:

< Step 1 >: Close MATLAB, if there is any session open.

< Step 2 >: Locate the file, '' as follows, In Terminal or xterm , type:

open -a TextEdit /Applications/MATLAB_R2008a/bin/

< Step 3 >: Open the file in the editor to replace a line as follows,

Navigate to Line 407,

if [ "$DYLD_LIBRARY_PATH" != "" ]; then





Change the line "DYLD_LIBRARY_PATH=" to "DYLD_LIBRARY_PATH=/System/Library/Frameworks/JavaVM.framework/Libraries"

< Step 5 >:
Save the changes by pressing "Command" + "s" keys.

< Step 6 >:
Restart MATLAB.


Jan 28, 2011

Develop JVLC Project on Eclipse, Win7

JVLC is a java version of VLC player, it can be downloaded at ''. But it is not easy to be set up. I also encounter some hectic problems. And JVLC does not support Mac OS at present!!!

1) download Eclipse at ''. We should download the matched version with the OS, such that my computer need to use Windows 32-bit instead of 64-bit.

2) ensure Java Runtime Environment(JRE) has been installed.

3) install and run Eclipse directly.

4) extract vlcj to the workspace of Eclipse. Build up a project and import it into Eclipse.

5) If we run the project now, probably we will get some error like this, "Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libvlc': The specified module could not be found."

6) So we need install VLC and it can be downloaded at ''.

7) After the installation, the solution to that error is that the system PATH should be redirected to the directory which contains the module of "libvlc.dll". "libvlc.dll" is in 'C:\Program Files(x86)\VideoLAN\VLC'.

8) So what we need to do is to configure the environment variables, putting this path into the System PATH. The details and steps is illustrated on the website of Java (

9) And do not forget to Reboot your computer. This is very important to activate PATH variable.

10) Now, JVLC could be compilable and work.

Jan 8, 2011


DrunkAlert(DA) 是我现在实验室所进行项目的其中一部分(大概六分之一),版本号为V8.0.2,因为该项目其余部分涉及用户隐私数据,需要由服务提供商来运营,所以暂时不能上线使用。DA目前只支持Android手机用户,Android操作系统最好是2.1或更新的版本。DA的工作机制是通过随身携带的Android手机,来实时监测用户是否过量饮酒,判断的依据是当人醉酒时,往往无法走直线,而左右方向上加速度和摆幅变大。如果系统判断用户醉酒,就会自动振铃并触发一系列事件。


大家可以在Android Market上搜索并免费下载程序(如图1),搜索关键词可以是“drunkalert”, “drunkenness”, “drunk”等等(如图2)。
图1                         device.png 
  图2                       device2.png


图3. 程序主页        device3.png
图4. warning被触发device4.png