2011년 3월 31일 목요일

switch between vi and shell

in vi : Ctrl+z
--> shell
--> type 'fg'
in vi : again

linux time print out in C

format : YYYY-MM-DD HH:mm:ss:ms

#include <time.h>
#include <sys/time.h>


...



struct timeval tv;
struct tm *lt;
gettimeofday(&tv, 0);
lt = localtime(&(tv.tv_sec));
fprintf(stderr, " >> %4d-%02d-%02d %02d:%02d:%02d.%03d \n", 1900 + lt->tm_year, lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, int(tv.tv_usec/1000.));

2011년 3월 29일 화요일

온라인 ogg to mp3 사이트

http://media.io

1. 급하게 쓸만하다.

2. 한번에 하나밖에 안되는게 단점.
  여러탭으로 멀티세션 가능!!

2011년 3월 28일 월요일

sed for survival

1. What is sed?
  1) stream editor
    (1) input --(edited)--> output

2. Essential command
  1) s : substitution
    (1) 4 parts of command
      a. s : command
      b. /../../ : delimiter
      c. ^fjdkal : regular expression pattern search pattern
      d. fdjj : replacement string
    (2) Use '/' as a delimiter
      a. '\' : sed 's\/user\/local\/bin/common\/bin' <old >new
      b. '_' : sed 's_/user_/local_/bin_/common_/bin' <old >new
      c. ':' : sed 's:/user:/local:/bin/common:/bin' <old >new
      d. '|' : sed 's|/user/local/bin|common/bin' <old > new
    (3) Use '&' as matched string
      a. add parenthesis to a pattern : sed 's/abc/(&)/' <old <new
        - '&' means pattern, in this command, "abc"

  2) '-e' command
    (1) Combines multiple commands into a single process.

  3) Substitute flags
    (1) /g : global replacement, as in vi

3. Others
  1) File names
    (1) any argument that doesn't start with sed option, it is the file name.

  2) -f : use sed command file
    (1) sed -f sedcommands <old >new

  3) '\' : to divide sed command into multiple lines.

  4) Bourne shall(bash) quote : using ' to quote commands in multiple lines.

  5) Restricting to a line number
    (1) by number : sed '3 s/[0-9][0-9]*//' <old <new
      a. remove the first number in the 3rd line.
    (2) by pattern : sed '/^#/ s/[0-9][0-9]*//' <old <new
      a. remove the first number which is starting with '#'.

Regular expression for survival

0. A truth for the regular expression
  Regular expression is used to matching pattern in a line. (Not laid on multiple lines.)

1. The Structure of a regular expression
  1) Anchors
    (1) ^ : begin of a line
    (2) $ : end of a line
    (3) \< ... \> : word level matching.

  2) Character sets
    (1) . : any char except the EOL char.
    (2) [...] : any char in brackets.
      a. range : [a-z], [0-9], [A-Za-z0-9_]
      b. order : "^T[a-z][aeiou] " : Tha, The, Thi, ...
    (3) [^...] : negate pattern. except chars in brackets.
    (4) \( ... \) : remembered pattern. use it with "\1 ~ \9"

  3) Modifiers : follows a character set. if not, not a modifier.
    (1) * : 0 or more copies
    (2) {a,b} : # of copies between a and b.