Monday, November 30, 2009

{1,5, -5, -8,2, -1,15 } -> {-5, -8, -1, 1, 5, 2,15}

每遇到一个负数, instead of exchange with the
first 正数,把前面的正数right round shift就可以了。

Index 0 1 2 3
Data 1 5 4 -5

L = 0, R = 3
right round shift from 1 to -5 就变成
-5 1 5 4

void shiftright(int* A, int L, int R) {
        int tmp=A[R],i;
        for (i=R; i>L; i--) {
                A[i] = A[i-1];
        }
        A[L] = tmp;
}


int main(){
        int a[] = {-7, -8, 9, -6, -11, -3, -5, 2, 3};
        int n, i, j= 0;
        n = sizeof(a)/sizeof(int);
        printf("array size %d\n", n);

        for(i=0; i

Sunday, November 15, 2009

Software development under Linux

Posted on 2003, a little bit old, but still very useful guide for
linux beginners.
http://reallylongword.org/gentoo/


Quick start on python
http://reallylongword.org/python/


How to create SVN repository
http://reallylongword.org/svn/

grep/cut/perl usage examples

grep -o
Only print the match part.
grep -A num
Print num lines after the match

grep "\<" match the empty string at the beginning
of the word
$ echo "so happy i am " | grep -o "\"
happy


echo -e "\t"
Show special chars in script string.

cut -s
do not print lines not containing delimiters


#!/bin/bash
for file in $(ls *.html)
do
match=$(perl parse.pl $file | grep -A 1 Manufacturer:)
manu=$(echo $match | grep -w -o Manufacturer:.*Mfr | sed 's/Manufacturer://g'| sed 's/M
fr//g')
date=$(echo $match | grep -w -o "Date:.*NHTSA CAMPAIGN"| sed 's/Date://g'| sed 's/NHTSA
CAMPAIGN//g')
comp=$(echo $match | grep -w -o Component:.*Potential | sed 's/Component: //g'| sed 's/
Potential//g')
num=$(echo $match | grep -w -o Affected:.*Summary | sed 's/Affected: //g'| sed 's/Summa
ry//g')

echo -e "$manu\t$comp\t$num\t$date" >> table
done

# file1="${file%.html}.txt"
# echo $file1
# manu=$(grep "Manufacturer:" $newfile| cut -d":" -s -f 2)
# date=$(grep "ReportDate:" $newfile| cut -b 19-32)
# date=$(grep "ReportDate:" $newfile| cut -b 19-32)
# comp=$(grep "Component:" $newfile|sed 's/Component:/\t/g' |)

Thursday, November 5, 2009

awk vs sed

"Doing even seemingly simple thing in sed can quickly result in large,
difficult expressions, making most usage of sed hard to understand. sed
works well for simple cases of string filtering, but awk can often be a
more maintainable choice."



http://www.osnews.com/story/21004/Awk_and_Sed_One-Liners_Explained
seq 19 | tr '\n' ,
tr translate \n with ,



http://reallylongword.org/sedawk/
"&" stands for the matched part of the text

sed 's!.*/!!'

[jwang@osnet1 bin ]$ echo "/users/abc/bla1.exe" |sed 's!.*/!!'

bla1.exe


Remove MSDOS carriage return characters of each line.
sed 's/\r$//'




#!/bin/bash

while read line
do
# path=${line%%/*}
path=${line%/*}
echo $path
done < $1 > outfile

exit 0


#newusers/defgh/ik/albg2.exe
#->
#newusers/defgh/ik


#if %% result is :
#newusers

Tuesday, November 3, 2009

linux npviewer problem

64-bit Firefox npwrapper (npviewer) plugin allows the 32-bit version
of Flash Player run in 64-bit Firefox. But it lock up all the time and
eating CPU cycles all the time.

How to kill npviewer process:
for name in $(ps ux | awk '/npviewer.bin/ && !/awk/ {print $2}'); do kill "$name"; done


Install firefox plugin: noscript or flashblock will solve the problem.


Download 64 bit flashplayer here:
sudo yum install flash-plugin libflashsupport
http://www.cyberciti.biz/tips/linux-install-flash-player-10.html
wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz
extract and copy libflashplayer.so to /usr/lib/mozilla/plugins/libflashplayer.so

Notes:
Seems the 64 bit player still not work right now for firefox
http://labs.adobe.com/downloads/flashplayer10.html