X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=study-note.org;h=3935a5eb44c26f7f27748d9ab8499f39470500fc;hb=4caf9a7a3c3ebc3780dddc9f8c5b484ea0c64c2f;hp=d9543abb92529ce9ed93d8c1b59e30a6e0360543;hpb=819b557f9ec286f3e9a86d120ac94b9472523ce2;p=dotfiles.git diff --git a/study-note.org b/study-note.org index d9543ab..3935a5e 100644 --- a/study-note.org +++ b/study-note.org @@ -128,3 +128,279 @@ See special variable in perl [[http://perldoc.perl.org/perlvar.html][perlvar]], #+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 + +* ObjectiveC +** =#import= vs. =#include= +[[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]] +- =#import= directive as added to Objective-C as an improvied version of =#include= +- =#import= ensures that a file is only ever included onces so that you never have a problem with recursive includes +- Bacically, use =#import= for Objective-C thins, =#include= for C stufff. + + +* Books +** Intruduction to Algorithms +*** Foundations +**** The Role of Algorithms in Computing +** SICP (Structure and Interpretation of Computer Programs) +*** Building Abstractions with Procedures + +The acts of the mind, wherein it exerts its power over simple ideas, are chiefly there threee: 1. +Combining serveral simple ideas into one compund one, and thus all complex ideas are made. 2. The +second is bringing two idears, whether simple or complex, together, and setting them by one another +so as to take a view of them at once, without uniting them into one, by which it gets all its ideas +of relations. 3. The third is separating them from all other ideas that accmpany them in there real +existence: this is called abstraction, and thus all its general ideas are made. + +-- Jone Locke, An Essay Concerning Human Understanding (1690) + +We are about to study the idea of computational process. Computational processes are abstract being +that inhabit computers. As they evolve, process manipulate other abstract things called data. +The evolution of a process in directed by a pattern of rules called a /programm/. People create +programs to direct processes. In effect, we conjure the spirits of the computer with our spells. + + A computaional process is indeed much like a sorcerer's idea of a spirit. It cannot be seen or +touched. It is composed of matter at all. However, it is very real. It can perform intellectual work. +It can answer questions. It can affect the world by disbursing money at a bank or by controlling +a rebot arm in a factory. The programs we use to conjure processes are like a sorcerer's spell. +They are carefully composed from symbolic expressions in arcane and esoteric /programming languages/ +that prescribe the tasks we want our processes to perform + +**** The Elements of Programming + +When we describe a language, we should pay particular attentation to the means that the language +provides for combining simple ideas to form more complex ideas. Every powerful language has three +mechanisms for accomplishing this: + +- *primitive expressions*, which represent the simplest entities the language is concerned with, +- *means of combination*, by which compound elements are built from simpler ones, and +- *means of abstraction*, by which compund elements can be names and manipulated as units. + +In programming, we deal with two kinds of elements: /procedures/ and /data/. (Later we will discover +that they are really not so distinct.) + +***** Expressions + +***** Naming and the Environment + +#+BEGIN_SRC scheme + (define size 2) +#+END_SRC + +***** Evaluating Combinations +To evaluate a combination, do the follow: +- Evaluate the subexpressions of the combination. +- Apply the procedure that is the value of the leftmost subexpression (the operator) to the + values of the other subexpressions (the operands). + +***** Compound Procedures + +We have identified in Lisp some of the elements that must appear in any powerful programming +language: + +- Numbers and arithmetic operations are primitive data and procedures. +- Nesting of combinations provides a means of combining operations.. +- Definitions that associate names with values provide a limited means of abstraction. + +The general form of a *procedure definition* is +#+BEGIN_SRC scheme + (define ( ) + ) +#+END_SRC + +***** The Substitution Model for Procedure Application + +To apply a compound procedure to arguments, evaluate the body of the procedure with each formal +parameter replaced by the corresponding argument. + +Applicative order versus normal order + +***** Conditional Expressions and Predicates + +=cond= , which stands for "conditional" +#+BEGIN_SRC scheme + (cond ( ) + ( ) + ... + ( )) +#+END_SRC + +consisting of the symbol =cond= followed by parenthesized pais of expressions =(

)= +called /clauses/. The first expression in each pair is a /predicate/-that is, and expression +whose value is interpreted as either true or false. + +=else=, is a special symbol that can be used in place of =

= in the final clause of a =cond= +#+BEGIN_SRC scheme + (define (abs x) + (cond (( ) +#+END_SRC + +- =and=, =or=, =not= +#+BEGIN_SRC scheme + (and ... ) + + (or ... ) + + (not ) +#+END_SRC + +****** Exercise +- 1.2 +#+BEGIN_SRC scheme + (/ (+ 5 + 4 + (- 2 + (- 3 + (+ 6 + (/ 4 5))))) + (* 3 + (- 6 2) + (- 2 7))) +#+END_SRC + +- 1.3 +#+BEGIN_SRC racket + (define (sum-two-larger a b c) + (cond ((and (> a b) (> c b)) (+ a c)) + ((and (> c a) (> b a)) (+ c b)) + ((and (> a c) (> b c)) (+ a b)))) + ;; test + (sum-two-larger 1 2 3) + (sum-two-larger 7 3 5) + + ;; another way + (define (minimal-of-two a b) + (if (> a b) + b + a)) + + (define (sum-two-larger-2 a b c) + (- (+ a b c) (minimal-of-two a (minimal-of-two b c)))) + + (sum-two-larger-2 1 2 3) +#+END_SRC + +***** Example: Square Roots by Newton's Method + +***** Procedures as Black-Box Abstractions + +- Local Name + +- Internal definitions and block structure + + +**** Procedures and the Processes They Generate + +***** 1.2.1 Linear Recursion and Iteration +sample, factorial function of n! + +***** 1.2.2 Tree Recursion +Fibonacci number + +***** 1.2.3 Orders of Grouth + +***** 1.2.4 Exponentiation +b^3 + +***** 1.2.5. Greatest Common Divisior + +***** 1.2.6 Example: Testing for Primality +- Fermat test +Fermat's Little Theorem: + +**** Formulating Abstractions with Higher-Order Procedures + +Procedures that manipulate procedures are called /higher-order procedures/. + +***** 1.3.1 Procedures as Arguments +#+BEGIN_SRC scheme + (define (inc n) (+ n 1)) + (define (cube a) (* a a a)) + (define (sum-cubes a b) + (+ cube a inc b)) + + (sum-cubes 1 10) +#+END_SRC + +***** 1.3.2 Constructing Procedures Using lambda +#+BEGIN_SRC scheme + (lambda () ) +#+END_SRC + +In general, =lambda= is used to create procedures in the same way as =define= except that no +name is specified for the procedure + +Like any expression that has a procedure as its values. a =lambda= expression can be used as +the operator in a combination such as +#+BEGIN_SRC scheme + ((lambda (x y z) (+ x y (square z))) + 1 2 3) + + 12 +#+END_SRC + +Useing =let= to create local variable +#+BEGIN_SRC scheme + (let (( ) + ( ) + ... + ( )) + ) +#+END_SRC + +***** 1.3.3 Procedures as General Methods + +***** 1.3.4 Procedures as Returned Values +Sample +#+BEGIN_SRC scheme + (define (average-damp f) + (lambda (x) (average x (f x)))) + + ((average-damp square) 10) + 55 +#+END_SRC + +*** Building Abstractions with Data +#+BEGIN_SRC scheme + (define a 3) + a +#+END_SRC + +#+RESULTS: +: 3 +