#+TITLE: Study Note #+AUTHOR: Peng Li #+EMAIL: seudut@gmail.com #+DATE: 2016-08-18 * Programming Languages ** Perl *** One line command **** perl help #+BEGIN_SRC sh :exports both :results output replace perl --help #+END_SRC #+RESULTS: #+begin_example Usage: perl [switches] [--] [programfile] [arguments] -0[octal] specify record separator (\0, if no argument) -a autosplit mode with -n or -p (splits $_ into @F) -C[number/list] enables the listed Unicode features -c check syntax only (runs BEGIN and CHECK blocks) -d[:debugger] run program under debugger -D[number/list] set debugging flags (argument is a bit mask or alphabets) -e program one line of program (several -e's allowed, omit programfile) -E program like -e, but enables all optional features -f don't do $sitelib/sitecustomize.pl at startup -F/pattern/ split() pattern for -a switch (//'s are optional) -i[extension] edit <> files in place (makes backup if extension supplied) -Idirectory specify @INC/#include directory (several -I's allowed) -l[octal] enable line ending processing, specifies line terminator -[mM][-]module execute "use/no module..." before executing program -n assume "while (<>) { ... }" loop around program -p assume loop like -n but print line also, like sed -s enable rudimentary parsing for switches after programfile -S look for programfile using PATH environment variable -t enable tainting warnings -T enable tainting checks -u dump core after parsing program -U allow unsafe operations -v print version, patchlevel and license -V[:variable] print configuration summary (or a single Config.pm variable) -w enable many useful warnings -W enable all warnings -x[directory] ignore text before #!perl line (optionally cd to directory) -X disable all warnings Run 'perldoc perl' for more help with Perl. #+end_example **** Used as =grep= #+BEGIN_SRC sh perl -ne 'print if /expression/' xxx.log; #+END_SRC #+BEGIN_SRC perl :results output replace my $tt = "hello"; ($tt =~ /h(.*)o/ ) and print $1; #+END_SRC #+RESULTS: : ell Or #+BEGIN_SRC sh perl -wnl -e '/keyword/ and print;' xxx.log #+END_SRC **** Used as =awk= #+BEGIN_SRC sh perl -ne 'print "$1\n" if /aaa=(\d+)\s.*/' xxx.log; #+END_SRC #+BEGIN_SRC fundamental :tangle ./temp/aa.txt aa: 1 bb: 2 cc: 3 dd: 4 #+END_SRC #+BEGIN_SRC sh :results output replace perl -wnl -e 'print "==$.: $_"' ./temp/aa.txt #+END_SRC #+RESULTS: : ==1: : ==2: aa: 1 : ==3: bb: 2 : ==4: cc: 3 : ==5: dd: 4 *** Special Variable See special variable in perl [[http://perldoc.perl.org/perlvar.html][perlvar]], or =perldoc perlvar= - =$.= Current line number ** gnuplog 1. normal #+BEGIN_SRC gnuplot :exports code :file ./temp/sin.png reset plot sin(x)/x #+END_SRC #+RESULTS: [[file:./temp/sin.png]] 2. plot with data file #+BEGIN_SRC fundamental :tangle ./temp/plot.dat # x y 1 11 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 #+END_SRC #+BEGIN_SRC gnuplot :file ./temp/ll.png reset set xrange [0:10] set yrange [0:20] plot "./temp/plot.dat" using 1:2 with lines #+END_SRC #+RESULTS: [[file:./temp/ll.png]] * TCP/IP ** netstat #+BEGIN_SRC sh :results output replace netstat -atn # For tcp port netstat -aun # For udp port netstat -atun # both #+END_SRC ** nc (netcat) #+BEGIN_SRC sh :results output replace # listening on port 1234 for a connection nc -l 1234 # connect to the machine and port nc 127.0.0.1 1234 #+END_SRC * Emacs ** =add-hook= vs =eval-after-load= Ref [[http://stackoverflow.com/questions/2736087/eval-after-load-vs-mode-hook][eval-after-load-vs-mode-hook]] #+BEGIN_QUOTE Code wrapped in =eval-after-load= will be executed only once, so it is typically used to perform one-time setup such as setting default global values and behaviour. An example might be setting up a default keymap for a particular mode. In =eval-after-load= code, there's no notion of the "current buffer". Mode hooks exectue once for every buffer in which the mode is enabled, so they're used for per-buffer configuration. Mode hooks are therefore run later than =eval-after-load= code; this lets them take actions baed upon such information as whether other modes are enabled in the current buffer. #+END_QUOTE