e9cc7d9bb5d1739e782df9da0fc30d013239a5c2
[dotfiles.git] / study-note.org
1 #+TITLE: Study Note
2 #+AUTHOR: Peng Li
3 #+EMAIL: seudut@gmail.com
4 #+DATE: 2016-08-18
5
6 * Programming Languages
7 ** Perl 
8 *** One line command
9 **** perl help
10 #+BEGIN_SRC sh :exports both :results output replace
11   perl --help
12 #+END_SRC
13
14 #+RESULTS:
15 #+begin_example
16
17 Usage: perl [switches] [--] [programfile] [arguments]
18   -0[octal]         specify record separator (\0, if no argument)
19   -a                autosplit mode with -n or -p (splits $_ into @F)
20   -C[number/list]   enables the listed Unicode features
21   -c                check syntax only (runs BEGIN and CHECK blocks)
22   -d[:debugger]     run program under debugger
23   -D[number/list]   set debugging flags (argument is a bit mask or alphabets)
24   -e program        one line of program (several -e's allowed, omit programfile)
25   -E program        like -e, but enables all optional features
26   -f                don't do $sitelib/sitecustomize.pl at startup
27   -F/pattern/       split() pattern for -a switch (//'s are optional)
28   -i[extension]     edit <> files in place (makes backup if extension supplied)
29   -Idirectory       specify @INC/#include directory (several -I's allowed)
30   -l[octal]         enable line ending processing, specifies line terminator
31   -[mM][-]module    execute "use/no module..." before executing program
32   -n                assume "while (<>) { ... }" loop around program
33   -p                assume loop like -n but print line also, like sed
34   -s                enable rudimentary parsing for switches after programfile
35   -S                look for programfile using PATH environment variable
36   -t                enable tainting warnings
37   -T                enable tainting checks
38   -u                dump core after parsing program
39   -U                allow unsafe operations
40   -v                print version, patchlevel and license
41   -V[:variable]     print configuration summary (or a single Config.pm variable)
42   -w                enable many useful warnings
43   -W                enable all warnings
44   -x[directory]     ignore text before #!perl line (optionally cd to directory)
45   -X                disable all warnings
46   
47 Run 'perldoc perl' for more help with Perl.
48
49 #+end_example
50
51 **** Used as =grep=
52 #+BEGIN_SRC sh
53   perl -ne 'print if /expression/' xxx.log;
54 #+END_SRC
55
56 #+BEGIN_SRC perl :results output replace
57   my $tt = "hello";
58   ($tt =~ /h(.*)o/ ) and print $1;
59 #+END_SRC
60
61 #+RESULTS:
62 : ell
63
64 Or 
65 #+BEGIN_SRC sh
66   perl -wnl -e '/keyword/ and print;' xxx.log
67 #+END_SRC
68
69 **** Used as =awk=
70 #+BEGIN_SRC sh
71   perl -ne 'print "$1\n" if /aaa=(\d+)\s.*/' xxx.log;
72 #+END_SRC
73
74 #+BEGIN_SRC fundamental :tangle ./temp/aa.txt
75   aa: 1
76   bb: 2
77   cc: 3
78   dd: 4
79 #+END_SRC
80
81 #+BEGIN_SRC sh :results output replace
82   perl -wnl -e 'print "==$.: $_"' ./temp/aa.txt
83 #+END_SRC
84
85 #+RESULTS:
86 : ==1: 
87 : ==2: aa: 1
88 : ==3: bb: 2
89 : ==4: cc: 3
90 : ==5: dd: 4
91
92 *** Special Variable
93 See special variable in perl [[http://perldoc.perl.org/perlvar.html][perlvar]], or =perldoc perlvar=
94 - =$.= Current line number
95
96 ** gnuplog
97
98 1. normal
99 #+BEGIN_SRC gnuplot :exports code :file ./temp/sin.png
100   reset
101   plot sin(x)/x
102 #+END_SRC
103
104 #+RESULTS:
105 [[file:./temp/sin.png]]
106
107 2. plot with data file
108 #+BEGIN_SRC fundamental :tangle ./temp/plot.dat 
109   # x y
110   1 11
111   2 12
112   3 13
113   4 14
114   5 15
115   6 16
116   7 17
117   8 18
118   9 19
119 #+END_SRC
120
121 #+BEGIN_SRC gnuplot :file ./temp/ll.png
122   reset
123   set xrange [0:10]
124   set yrange [0:20]
125   plot "./temp/plot.dat" using 1:2 with lines
126 #+END_SRC
127
128 #+RESULTS:
129 [[file:./temp/ll.png]]
130
131 * TCP/IP
132 ** netstat
133 #+BEGIN_SRC sh :results output replace
134   netstat -atn    # For tcp port
135   netstat -aun    # For udp port
136   netstat -atun   # both
137 #+END_SRC
138
139 ** nc (netcat)
140 #+BEGIN_SRC sh :results output replace
141   # listening on port 1234 for a connection
142   nc -l 1234
143
144   # connect to the machine and port
145   nc 127.0.0.1 1234
146 #+END_SRC
147
148 * Emacs
149 ** =add-hook= vs =eval-after-load=
150 Ref [[http://stackoverflow.com/questions/2736087/eval-after-load-vs-mode-hook][eval-after-load-vs-mode-hook]]
151 #+BEGIN_QUOTE
152 Code wrapped in =eval-after-load= will be executed only once, so it is typically used to perform
153 one-time setup such as setting default global values and behaviour. An example might be setting
154 up a default keymap for a particular mode. In =eval-after-load= code, there's no notion of the 
155 "current buffer".
156
157 Mode hooks exectue once for every buffer in which the mode is enabled, so they're used for per-buffer
158 configuration. Mode hooks are therefore run later than =eval-after-load= code; this lets them take 
159 actions baed upon such information as whether other modes are enabled in the current buffer.
160 #+END_QUOTE
161
162 * ObjectiveC
163 ** =#import= vs. =#include=
164 [[http://stackoverflow.com/questions/439662/what-is-the-difference-between-import-and-include-in-objective-c][what-is-the-difference-between-import-and-include-in-objective-c]]
165 - =#import= directive as added to Objective-C as an improvied version of =#include=
166 - =#import= ensures that a file is only ever included onces so that you never have a problem with recursive includes
167 - Bacically, use =#import= for Objective-C thins, =#include= for C stufff.
168
169
170 * Books
171 ** Intruduction to Algorithms