note

Programming

Programming Tips and Notes.

C Operator Precedence and Associativity

Operator Description Associativity
()
[]
.
->
++ --
Parentheses (function call)
Brackets (array subscript)
Member selection via object name
Member selection via pointer
Postfix increment/decrement
left-to-right
++ --
+ -
! ~
(type)
*
&
sizeof
Prefix increment/decrement
Unary plus/minus
Logical negation/bitwise complemnet
Cast (change type)
Deference
Address
Determine size in bytes
right-to-left
* / % Multiplication/division/modulus left-to-right
+ - Addition/subtraction left-to-right
<< >> Bitwise shift left, Bitwise shift right left-to-right
< <=
> >=
Relational less than/less than or equal to
Relational more than/more than or equal to
left-to-right
== != Relational is equal to/is not equal to left-to-right
& Bitwise AND left-to-right
^ Bitwise exclusive OR left-to-right
| Bitwise inclusive OR left-to-right
&& Logical AND left-to-right
|| Logical OR right-to-left
? : Ternary conditional right-to-left
=
+= -=
*= /=
%= &=
^= |=
<<= >>=
Assignment
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise ADN assignment
Bitwise exclusive/inclusive OR assignment
Bitwise shift left/right assignment
right-to-left
, Comma (separate expressions) left-to-right

Memory


Unix

Unix Tips and Notes

emacs shortcuts

open a file
Ctrl-x Ctrl-f
forward delete
Ctrl-d
switch read-only mode
Ctrl-x Ctrl-q
remove ^M character
M-x replace-string RET Ctrl-q Ctrl-m RET RET

Windows

Windows Tips and Notes

WM_USER

Range Description
0 ~ WM_USER -1 Messages reserved for use by the system
WM_USER ~ 0XFFF Integer messages for use by private window classes
WM_APP ~ 0XBFFF Messages available for use by applications
0XC000 ~ 0XFFFF String messages for use by applications
0X10000 ~ Reserved by the system

Others

Other Tips and Notes

OSI Model

Data unit Layer Function
Host layers Data 7. Application Network process to application Telnet, FTP, HTTP, SMTP
6. Presentation Data representation and encryption
5. Session Interhost communication TCP, UDP
Segment/Datagram 4. Transport End-to-end connections and reliability
Media layers Packet 3. Network Path determination and logical addressing IP, IPv6
Frame 2. Data Link Physical addressing (MAC & LLC) Ethernet, PPP
Bit 1. Physical Media, signal and binary transmission Fiber

Vector and Matrix

Dot Product:
A = (a1, a2, ... , an)
B = (b1, b2, ... , bn)

A dot B = |A||B|cos(θ)
= a1b1 + a2b2 + ... + anbn

A dot B > 0 => 0 < θ < 90 degree
A dot B = 0 => θ = 90 degree
A dot B < 0 => 90 < θ < 180 degree

Cross Product:
A = (ax, ay, az)
B = (bx, by, bz)

A cross B = (aybz - azby, azbx - axbz, axby - aybx)

|A cross B| = |A||B|sin(θ)

Eigenvalue and Eigenvector:
Ax = λx => (A - λI)x = 0
λ: eigenvalue, x: eigenvector

Norm:

Equation Ax = y:
Ax = y => x = A-1y

[1] y = ax + b
S = sum(yi - axi - b)^2
= (y - Az)^T(y - Az)
 A      x     y
 |x1 1||a| = |y1|
 |x2 1||b|   |y2|
 |    |      |  |
 |xn 1|      |yn|
	 
[2] y = ax^2 + bx + c
 A           x     y
 |x1^2 x1 1||a| = |y1|
 |x2^2 x2 1||b|   |y2|
 |         ||c|   |  |
 |xn^2 xn 1|      |yn|
	 

Differential Equations

ODE - Ordinary Differential Equations:
dy/dt = F(t, y), y(t0) = y0

PDE - Partial Differential Equations (second order):
F(x, y, u, ux, uy, uxx, uxy, uyy) = 0

Intersecting Chord Theorem

Formula => AE * EB = CE * ED
         /H----D-----\
        / |\   |      \
       A--I-\--E-------B
      /   |  \ |        \
      |   |   \|        |
      |   J----O        |
      |        |        |  (AB: arc
      \        |        /  |AB: chord 
       \       |       /     O: center of a circle
        \      |      /    |OE: apothem
         \-----C-----/     |OA |OB |OC |OD: radius

    Known variables: AB, ED, AI
	 
CE = (1/4*AB*AB) / ED (since AE = EB = 1/2 * AB)
radi = (CE + ED)/2
= (AB*AB/(4*ED) + ED)/2
HI = sqrt(OH*OH - OJ*OJ) - IJ
= sqrt(radi*radi - (AE-AI)*(AE-AI)) - OE
= sqrt(radi*radi - (AB/2-AI)*(AB/2-AI)) - (radi - ED)

Fractal

Mandelbrot:
f = z^2 + c
=> zn+1 = zn^2 + c
z0 = 1
z = x + yi
c = a + bi

z = (x + yi)^2 + a + bi
=> zx = x^2 - y^2 + a
zy = 2xy + b