Friday, October 29, 2010

set default window size and font in gVim

click on
edit>startup settings to edit the vimrc in windows

"set defautl window size
set lines=24
set columns=90
"set default font:size
set guifont=Courier\ New:h14

Monday, October 4, 2010

google C++ coding style

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

Monday, September 27, 2010

gen_ctags

# setting
WORKDIR=`pwd`
# get all file list
echo "get all file list"
rm ctags.Uranus ctags.utopia 2>/dev/null
find $WORKDIR/Uranus/ -name '*.[HhCc]' >> ctags.Uranus
find $WORKDIR/Uranus/ -name '*.cc' >> ctags.Uranus
find $WORKDIR/Uranus/ -name '*.cpp' >> ctags.Uranus
find $WORKDIR/utopia/ -name '*.[HhCc]' >> ctags.utopia
find $WORKDIR/utopia/ -name '*.cc' >> ctags.utopia
find $WORKDIR/utopia/ -name '*.cpp' >> ctags.utopia

# remove unwanted files

echo "remove unwanted files"
# Uranus
sed -i /Cus60/d ctags.Uranus
sed -i /eCospro/d ctags.Uranus
sed -i /Trunk/d ctags.Uranus
sed -i /u3/d ctags.Uranus
# utopis
sed -i /u2/d ctags.utopia
sed -i /u3/d ctags.utopia

sed -i /t2/d ctags.utopia
sed -i /t4/d ctags.utopia
sed -i /t7/d ctags.utopia
sed -i /t8/d ctags.utopia
sed -i /t9/d ctags.utopia
sed -i /t11/d ctags.utopia
sed -i /t12/d ctags.utopia
sed -i /t13/d ctags.utopia
sed -i /titania4/d ctags.utopia
sed -i /titania7/d ctags.utopia
sed -i /titania8/d ctags.utopia
sed -i /titania9/d ctags.utopia

sed -i /Janus/d ctags.utopia
sed -i /janus/d ctags.utopia
sed -i /j2/d ctags.utopia

sed -i /s7/d ctags.utopia
sed -i /s7j/d ctags.utopia
sed -i /s7ml/d ctags.utopia
sed -i /s7ld/d ctags.utopia
sed -i /s8/d ctags.utopia

sed -i /maria10/d ctags.utopia
sed -i /prans2/d ctags.utopia

sed -i /r2/d ctags.utopia

# generate tag file
cat ctags.Uranus ctags.utopia > ctags.files
echo "generate tag file"
ctags -L ctags.files
#cscope -b -q -k

# generate file list for Perforce
echo "generate file list for Perforce"
ESCSTR=$(echo "$WORKDIR" | sed -e 's/\//\\\//g')
echo $ESCSTR
echo "sed -e 's/$ESCSTR//g' ctags.files > ctags.p4"
sed -e "s/$ESCSTR//g" ctags.files > ctags.p4

# export global variable
echo "===== IMPORTANT ====="
echo "please export the following variable"
echo "export CTAGFILE=$WORKDIR/tags"

Saturday, September 25, 2010

linux dump stace functions

1) dump_stack

Thursday, September 2, 2010

vimrc

ab tl Tlist
ab tls TlistSync

where

Tlist is for ctag list
TlistSync is for syncing the ctag navigating window with the current cursor

Wednesday, June 30, 2010

compound statement expression

http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html


wield stuff only for gcc, but useful

Tuesday, June 29, 2010

vimrc

syntax on
set nu
set ruler
set hlsearch
set cul
colorscheme evening
set vb
cs add cscope.out
set cscopetag
set foldmethod=marker
set tw=80
set ai
set nojoinspaces
set formatoptions=qtcor

"for C programming
ab #i #include
ab #d #define
ab #e #endif
ab #p #pragma
ab #m Min-Hua Chen

"spell check
ab sc set spell
ab nsc set nospell
"ab #c Author(s): xxx
"\Copyright (c) 2008 xxx
"\Permission to copy, modify, and distribute this program is granted


ab #c Author(s): xxx

autocmd BufReadPost *.c set cin
autocmd BufReadPost *.h set cin
autocmd BufReadPost *.pl set cin
autocmd BufReadPost *.cpp set cin
autocmd BufReadPost *.php set cin
autocmd BufReadPost *.py set si
autocmd BufReadPost *.java set si
autocmd BufReadPost *.java set cino+=j1
autocmd BufReadPost *.java set sw=4

Thursday, April 29, 2010

Interesting set intersection by using 'uniq'

I was asked to find the intersection of two IP lists yesterday. I write a simple program with Perl. The program iterates the two lists to find the repeated IPs, which is a O(n^2) algorithm.

foreach $a (@A) {
foreach $b (@B) {
if ($a eq $b) {
...
}
}
}
When I wake up this morning, another way to do this pops onto my mind.

cat file-A | sort | uniq > tmp
cat file-B | sort | uniq >> tmp
cat tmp | sort | uniq -d

Basically, it is a O(nlog(n)) algorithm. (the sort operation).

Wednesday, March 31, 2010

X forwarding in ssh

To enable X forwarding, try the following command
ssh -X xxx.xxx.xxx.xxx

than we can launch a program with GUI through ssh.

Sometimes it does not work as expected, check the DISPLAY environment variable.

export DISPLAY=:10.0

duplicate a new table in Oracle

create table [new table name] as select * from [table name]

Wednesday, March 17, 2010

Remove VirtualBox lock

The lock file of VirtualBox is placed in
/tmp/.vbox-[user name]-ipc

Monday, February 8, 2010

default apache2 username on Debian

www-data

Tuesday, January 12, 2010

fighting with oci8 - apache2 + php5 + Oracle

Connecting to the Oracle database by using apache2 + php5 is simple -- if you already know all the traps along the way.

In order to connect to the Oracle database with my apache2 and php5, I've read several tutorials. Many thanks for them.

I want to talk about my experience -- everything is done correctly, but the phpinfo() still shows no oci8 information.

First, you should take a look at the error log of apache in /var/log.
In my case, my error log shows
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/200 60613+lfs/oci8.so' - libaio.so.1: cannot open shared object file: No such fi le or directory in Unknown on line 0

The log already told me the answer, all I had to do is to install the lobaio.so. I did so and solved the problem.

Another way to discover the problem is to use the ldd command to exam the oci8.so.
linux-gate.so.1 => (0xb7fb3000)
libclntsh.so.11.1 => /opt/oracle/instantclient/libclntsh.so.11.1 (0xb627b000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb610e000)
libnnz11.so => /opt/oracle/instantclient/libnnz11.so (0xb5ec0000)
libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb5ebc000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb5e96000)
libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb5e7d000)
libnsl.so.1 => /lib/i686/cmov/libnsl.so.1 (0xb5e64000)
/lib/ld-linux.so.2 (0xb7fb4000)
libaio.so.1 => not found

It showed the same problem.

Tuesday, January 5, 2010

rrdtool - every data is a rate!

This article is about understanding the rate calculating in the rrdtool.

I'm doing a SA project recently. We get the RTTs(round-trip time) by the ping command and write the RTT to a rrd file, print out the graph, ...

More information about the rrdtool can be found on their website.
http://oss.oetiker.ch/rrdtool/

I first created a rrd file:
rrdtool create F.rrd \
--step 10 \
DS:rtt1:GAUGE:20:0:U \
RRA:MAX:0.5:1:35712

Then, I updated some values to the F.rrd file. A interesting fact is that when I update the value at exact the time step (say 10, 20, 30, etc.), I'll have a accurate value.

# rrdtool update F 1262733290:3
# rrdtool update F 1262733300:4
# rrdtool update F 1262733310:5
# rrdtool update F 1262733320:6

1262733300: 4.0000000000e+00
1262733310: 5.0000000000e+00
1262733320: 6.0000000000e+00

OK, there is a thing called "heartbeat" in the rddtool, it helps the updates that occur at a not-accurate timestamps. For example, if we update a value at time 1262733331, the rrdtool will put the value to 1262733330. It's a nice feature, since there is always some delays in the networking world.

Let's take a look

# rrdtool update F 1262733331:7
# rrdtool update F 1262733340:8

1262733330: 7.0000000000e+00
1262733340: 7.9000000000e+00

As you can see, the value 7 is updated at 1262733331 but is shifted to 126273330 in the rrd file. But what happened with the next update at 1262733340? We update 8 but the rrd file recorded 7.9. Strange, right?

Here is how 7.9 comes out: since rrdtool treats every data as a rate, if there are more than one samples before a time step, rrdtool tries to calculate the average rate of all the samples before the time step (after the previous time step, of course).

previous time step: 1262733330
when we update 7 at 1262733331; 8 at 1262733340.
the calculation is
(7 * (1262733331 - 1262733330) +
8 * (1262733340 - 1262733331) ) / 10 = 7.9

Here is a figure to help understanding:


OK, Let's do the math with another example:

# rrdtool update F 1262733341:54
# rrdtool update F 1262733342:3
# rrdtool update F 1262733347:31
# rrdtool update F 1262733350:3

To find out the average value at 1262733350:
previous time step: 1262733340
(54 * (1262733341 - 1262733340) +
3 * (1262733342 - 1262733341) +
31 * (1262733347 - 1262733342) +
3 * (1262733350 - 1262733347)) / 10 = 22.1

Read the rrd file to verify our answer:
1262733350: 2.2100000000e+01

It's a perfect match. :-)

I hope this article can help someone who has the same question as I did.