2013年11月27日 星期三

Python String Encoding Conversion (UTF-8/ANSI)

**Python String are recorded in UNICODE internally

Reading file encoded in UTF-8:


with open(fileName,'r') as f:
    for line in f.readlines():
        print line.decode("UTF-8")




2013年9月12日 星期四

Bind bash keyboard shortcut to delete word to slash

add the following line in ~/.bashrc


bind '\C-f:unix-filename-rubout'


Ctrl+F is bound to delete till previous slash

2013年7月23日 星期二

bash_profile vs bashrc vs profile, environment variables

.bash_profile --> login shell

.bashrc --> non-login shell

login shell:
e.g. login via console, ssh

non-login shell:
e.g. new terminal windows in inside GNOME ( already logged in)
/bin/bash in terminal

When bash is invoked as an interactive login shell, or as a non-interac-
tive shell with the --login option, it first reads and executes commands
from the file /etc/profile, if that file exists. After reading that file,
it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
order, and reads and executes commands from the first one that exists and
is readable. The --noprofile option may be used when the shell is started
to inhibit this behavior.

/etc/profile --> ~/.bash_profile > ~/.bash_login > ~/.profile

Environment Variable

/etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.


set -- show environment variables + shell variables

env -- show environment variables


2013年7月15日 星期一

CodeIgniter .htaccess mod_rewrite 404

CodeIgniter directory: /Document-root/[your-URL-path]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /[your-URL-path]
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php/$1 [L]
                  `---!! No heading slash
</IfModule>

2013年7月12日 星期五

Javascript Prototype Chain / Inheritance

*Every Object has an internal link to another object called prototype
syntax constructs:
var o = {a: 1};
//o ---> Object.prototype ---> null

var a = ["yo", "whadup", "?"];
//a ---> Array.prototype ---> Object.prototype ---> null

function f(){
return 2;
}
//f ---> Function.prototype ---> Object.prototype ---> null

Constructor:
function Graph() {
this.vertexes = [];
this.edges = [];
}
Graph.prototype = {
addVertex: function(v){
this.vertexes.push(v);
}
};
var g = new Graph();
//Graph ---> Graph.prototype ---> Object.prototype


Object.create
var a = {a: 1};
var b = Object.create(a);
// b ---> a ---> Object.prototype ---> null
var c = Object.create(b);
// c ---> b ---> a ---> Object.prototype ---> null
var d = Object.create(null);
// d ---> null

2013年7月7日 星期日

LINUX SYSTEM INITIALIZATION

DEBIAN

1.BIOS
   |--- POST (Power On Self Test)
    `--- Load initial code (bootloader code/kernel code...etc) form DISK
2.Bootloader (Bootstrap Loader)
    `--- load system kernel image and initrd image, hands over control
`-- Linux kernel             `---- initramfs
    * initrd : image of temporary root file system loaded into memory
               do hardware detection,module loading, mnt root file sys
3. initrd (mini-Debian System (Started by bootloader))
`----- /init is executed
4. Debian-System
|----- 0. /sbin/init (init(8)) is executed
| |--- parent of all processes
| `--- create process from script /etc/inittab
|----- 1. System goes into runlevel N(none) by following /etc/inittab
|----- 2. System goes into runlevel S for initialization
`----- 3. System goes into runlevel 2-5(multi-user))(determined by /etc/inittab)
`-- rc.local is executed at the end of each multiuser runlevel




A Bootable Linux Image

Load Sequence: Boot Loader->kernel->initrd->rootfs(the fs user will be working on)