put this functions in the ~/.bashrc
# convert a number into decimal format
n2d() {
perl -e "printf \"%d\n\", $@"
}
# convert a number into hex format
n2h() {
perl -e "printf \"0x%X\n\", $@"
}
# convert a number into binary format
n2b() {
perl -e "printf \"0b%b\n\", $@"
}
Thursday, April 21, 2011
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
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
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"
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
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
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
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
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
"\
"\
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.
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).
When I wake up this morning, another way to do this pops onto my mind.
foreach $a (@A) {
foreach $b (@B) {
if ($a eq $b) {
...
}
}
}
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
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
Subscribe to:
Posts (Atom)