Tuesday, February 25, 2014

[OSDI] SVN (Version Control)


Difference between Git

"Git is Distributed Source Control", but SVN is not.

Start Here

In SVN, we have to:
  1. create a new empty SVN repo
  2. find our project directory and import it to the repo
  3. checkout the code in the other places
Then, we can start using basic SVN commands after the 3 steps.

  • Repo directory: /User/heron/Downloads/svn_test
  • Project directory: /User/heron/Downloads/project
  • Checkout directory: /User/heron/Download/test
  • you may have to replace your own directory path

create a new empty SVN repo

  • mkdir /User/heron/Downloads/svn_test
  • cd /User/heron/Downloads/svn_test
  • svnadmin create .

find our project directory and import it to the repo

  • svn import /User/heron/Downloads/project file:///Users/heron/Downloads/svn_test -m "init import"
    • -m: following the content of the commit

checkout the code in the other places

  • cd /User/heron/Download/test
  • svn checkout file:///Users/heron/Downloads/svn_test

start using basic SVN commands

  • svn log
    • read commit logs
  • svn diff
    • review the changes from the last commit
  • svn commit
    • similar to "git commit" and "git push"
    • commit current project
    • ex. svn commit -m "the second commit"
  • svn update
    • similar to "git pull"

More Reference

Sunday, February 23, 2014

[Technology Entrepreneurship] 9 Key Models and Frameworks

This note is taken from one of the course in Stanford Technology Entrepreneurship. 9 models and frameworks are listed out and introduced in this course. And the course video is here.
  1. Two "Phases"
  2. (Byers, Dorf & Nelson) Vision -> Strategy -> Execution
  3. Sahlman's Concept of Fit
  4. Komisar's "3 Questions Every Venture Capitalist Wants to Know"
  5. Risk Reduction
  6. Moore's "Crossing The Chasm" Model and Positioning Statement Template
  7. Blank's Customer Development Process
  8. Kaplan's Startup Race
  9. Effectuation

Online Survey

Some tools for Online Surveys:

[OSDI] Configuring the Kernel

Configuration & Run

  • make config: takes a long time
    • make menuconfig: ncurses-based graphical utility
    • make gconfig: gtk+-based graphical utility
    • make defconfig: default configurations based on my architecture
  • make oldconfig: compress the configuration file .config /proc/config.gz
  • make

[OSDI] Memory Layout




  1. Text Segment
    • code (plain text), contains executable instructions
    • place below the heap or stack in order to prevent heaps and stack overflows from overwriting it.
    • sharable and readonly
      • may be accessed by editor, compiler, shell, etc.
  2. Initialized Data Segment
    • global variables and static variables
    • not read-only
      • initialized read-only area (ex. s[] = "hello world")
      • initialized read-write area (ex. const char *string = "hello world")
  3. Uninitialzed Data Segment
    • bss section: block started by symbol
    • global variables and static variables that are initialized to zero or do not have explicit initialization in source code
    • ex.
      • static int i;
      • [global] int j;
  4. Stack
  5. Heap
    • dynamic memory allocation


Friday, February 21, 2014

Gson (on Android Studio)

Why I met with Gson?

While I was try to store one whole complex object into SharedPerference in Android code, I found that it's default basic data types are not supporting. Also, it's hard to decode them in to json string unless I am writing it's custom encoding function.

Then, I found people are solving this problem using Gson on StackOverflow.

Intro for Gson

"Gson is a Java library that can be used to convert Java Objects into their JSON representation."

Install Gson on Android Studio

Follow the top answer in this StackOverflow thread.


Thursday, February 20, 2014

[OSDI] Debugger

  • ptrace
  • gdb (用ptrace API做)

Stack Overflow

Reference: http://en.wikipedia.org/wiki/Stack_overflow

In software, a stack overflow occurs when the stack pointer exceeds the stack bound. The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many factors, including the programming language, machine architecture, multi-threading, and amount of available memory. When a program attempts to use more space than is available on the call stack (that is, wen it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the static is said to overflow, typically resulting in a program crash.

Static Variable

static with init value -> .data
others -> .bss
i -> stack

Reference: http://en.wikipedia.org/wiki/Static_variable

In computer programming, a static variable is a variable that has been allocated statically -whose lifetime or "extent" extends across the entire run of the program. This is in contrast to the more ephemeral automatic variables (local variables are generally automatic), whose storage is allocated and deallocated on the call stack; and in contrast to objects whose storage is dynamically allocated in heap memory.

When a program (executable or library) is loaded into memory, static variables are stored in the data segment of the program's address space (if initialized) or the BSS segment (if uninitialized), and are stored in corresponding sections of object files prior to loading.

The static keyword is used in C and related languages both for static variables and other concepts.

Tuesday, February 18, 2014



  • make sure vim is installed
  • wget http://cscope.sourceforge.net/cscope_maps.vim
  • mv cscope_maps.vim ~/.vim/plugin/
  • download http://sourceforge.net/projects/cscope/files/ & change the current directory into the downloaded directory
    • ./configure
    • make
    • sudo make install


  • cscope -R -b


  • ctrl-t: side tab
  • ctrl-o: next jump
  • ctrl-i: previous jump
  • ctrl-]: go into


Reference from this site:
  • :cs find s ----查找C語言符號,即查找函數名、宏、枚舉值等出現的地方
  • :cs find g ----查找函數、宏、枚舉等定義的位置,類似ctags所提供的功能
  • :cs find d ----查找本函數調用的函數
  • :cs find c ----查找調用本函數的函數
  • :cs find t: ---查找指定的字符串
  • :cs find e ----查找egrep模式,相當於egrep功能,但查找速度快多了
  • :cs find f ----查找並打開文件,類似vim的find功能
  • :cs find i ----查找包含本文件的文

Bug Found

On Mac OS X 10.9, cscope is having error if the working path contains "space". The error is recorded below:
Error detected while processing /Users/heron/.vim/plugin/cscope_maps.vim:
line   42:
cs_read_prompt EOF: Not a directory
E609: Cscope error: cscope: cannot read trailer offset from file cscope.out
Press ENTER or type command to continue


It's time to trace the linux kernel code!

Apache Memory管理:Prefork and Worker

這幾日觀察提供數種服務的Linode server上,各個process使用資源的情況,發現一個apache的child process約需要20MB的memory,若是沒有多加管控,容易超出linux的memory上限,觸發OOM,部分process會被作業系統kill。

"It is not unheard of for even small to moderate sized Python web applications to consume 30MB or more of private memory in each child server process." -- from this reference

  • prefork:一個request(task)由其中一個apache process負責
  • worker:一個request(task)由多個apache process負擔

"If you use mod_wsgi daemon mode, it doesn't matter which Apache MPM you use, although suggested that for UNIX systems worker MPM be used unless you are stuck with having to also host PHP applications using mod_php as some PHP extensions aren't thread safe." -- from this reference

Sunday, February 16, 2014

Get Router's MAC Address

>> traceroute google.com
traceroute: Warning: google.com has multiple addresses; using
traceroute to google.com (, 64 hops max, 52 byte packets
1 ( 2.781 ms 39.006 ms 4.022 ms
2 ( 2.771 ms 34.815 ms 2.666 ms
3 ( 2.429 ms 4.358 ms 2.866 ms
4 ( 4.497 ms 6.394 ms 4.826 ms

>> arp -a
? ( at b4:52:7d:7d:15:46 on en0 [ethernet]
? ( at f4:f1:5a:d5:80:76 on en0 [ethernet]
? ( at 84:0:d2:52:20:a5 on en0 [ethernet]
? ( at d0:51:62:2b:2c:64 on en0 [ethernet]
? ( at 1c:b0:94:88:68:a7 on en0 [ethernet]
? ( at d0:51:62:3a:f6:ff on en0 [ethernet]
? ( at e8:99:c4:ba:41:1 on en0 [ethernet]
? ( at 4c:21:d0:43:3a:56 on en0 [ethernet]
? ( at 1c:7b:21:7a:bf:33 on en0 [ethernet]
? ( at c:74:c2:4d:6e:2b on en0 [ethernet]
? ( at bc:85:56:2d:cb:f on en0 [ethernet]
? ( at 44:d8:84:56:72:3b on en0 [ethernet]
? ( at b4:52:7d:79:71:78 on en0 [ethernet]
? ( at 20:7d:74:1a:95:81 on en0 [ethernet]
? ( at d0:51:62:10:9c:84 on en0 [ethernet]
? ( at b4:52:7e:72:7:74 on en0 [ethernet]
? ( at dc:9b:9c:a4:2a:61 on en0 [ethernet]
? ( at 30:f7:c5:2c:8d:48 on en0 [ethernet]
? ( at 18:e7:f4:80:88:50 on en0 [ethernet]
? ( at 0:eb:2d:e3:9c:21 on en0 [ethernet]
? ( at f4:f1:5a:91:39:88 on en0 [ethernet]
? ( at 18:e7:f4:9:61:4 on en0 [ethernet]
? ( at 4c:8d:79:a4:21:4f on en0 [ethernet]
? ( at 1c:7b:21:c2:1d:80 on en0 [ethernet]
? ( at 78:6c:1c:d6:3c:7f on en0 [ethernet]
? ( at 34:c0:59:a0:48:dc on en0 [ethernet]
? ( at 84:38:35:a6:62:58 on en0 [ethernet]
? ( at 1c:7b:21:61:2e:69 on en0 [ethernet]
? ( at 90:b9:31:d:ee:ad on en0 [ethernet]
? ( at e0:f5:c6:70:9e:5c on en0 [ethernet]
? ( at c8:6f:1d:1e:ec:12 on en0 [ethernet]
? ( at a8:d0:e5:a4:38:10 on en0 [ethernet]

Wednesday, February 12, 2014

Page not Found after Changing Permalinks

In WordPress, we are allow to change the URL of the pages. However, creating the custom URL may cause some problems, and here is the solution.

Change the Permalinks: using "post name" is not a bad idea, and we are able to edit the URL in the post edit page.

Page not Found may occurs for the first time we apply custom permalinks. And the solution is to enable rewrite for the apache. Reference is here. And the easiest way is:
sudo a2enmod rewrite
sudo service apache2 restart