Saturday, October 30, 2010

C++ note: static variable from inline member function

I was thinking about Meyers singleton, and wonder how compilers will handle the same static variable defined in difference modules due to inline function expansion. Here are some relevant discussions (it occurs safe not to use the kind of singleton(?)).

http://objectmix.com/c/250462-static-local-variable-inline-static-member-function.html

Wednesday, October 13, 2010

Sh note: adding a line at the front of files

The example script adds a new line to the beginning of each file in the directory, recursively, except those files that contain svn.

for file in `find . -type f | grep -v 'svn'`;
do
sed '1i\New line' -i $file
done

Tuesday, October 12, 2010

Sh note: reversing a file or a line

rev can be used to reverse a line character by character
tac can be used to reverse a file line by line
these two commands are sometimes handy

sh$ rev
abc
cba

sh$ tac
a
b
c^D
c
b
a

echo abcde | rev

a particular context I used tac
ls /corpora/extra/nivre/corpus/conll-x/data/turkish/metu_sabanci/*/*.conll | cut -d '/' -f8-11 | tac