Fork me on GitHub


Blog Decoration CSS

This post records the decoration in this blog for backup. Using markdown with these decoration to write blog is awesome!

1. Code Block

pre {
    border:1px dashed #E1E1E1;
code {

2. Blcokquote

blockquote {
    background  : #f9f9f9;
    border-left : 10px solid #ccc;
    margin      : 1.5em 10px;
    padding     : .5em 10px;
    quotes      : "\201C""\201D""\2018""\2019";

3. Github Ribbon

.ribbon {
    background-color          : #a00;
    overflow                  : hidden;
    z-index                   : 1;
    position                  : absolute;
    right                     : -3em;
    top                       : 2.5em;
    -moz-transform            : rotate(45deg);
    -webkit-transform         : rotate(45deg);
    -moz-box-shadow           : 0 0 1em #888;
    -webkit-box-shadow        : 0 0 1em #888;
.ribbon a {
    border          : 1px solid #faa;
    color           : #fff;
    display         : block;
    font            : bold 81.25% 'Helvetiva Neue', Helvetica, Arial, sans-serif;
    margin          : 0.05em 0 0.075em 0;
    padding         : 0.5em 3.5em;
    text-align      : center;
    text-decoration : none;
    text-shadow     : 0 0 0.5em #444;

-- EOF --


Using Git In Non Merging Way

Here is the flow I used in the past few months development wit Git

  1. First, create a branch 'base' to track the remote collaborating branch

    $ git checkout -b base -t origin/trunk
        // create a local branch 'base' to track a remote branch 'origin/trunk'
    $ git branch -a
        // show the detail info about local/remote branches
    $ git remote show origin
        // to know which local branch tracks which remote branch, see the bottom of output
  2. Any feature/hotfix are checkout to a separate feature branch from base branch, and develop on it

    $ git checkout -b 1201-fea
        // create a local branch for development
  3. After completing and verifying your changes, patch your changes

    $ git diff > p1225_refactor
        // output your changes to a patch file names 'p1201_fea'
  4. When ready to sync changes to server, update your base branch, checkout to it, then apply your patch

    $ git checkout base
    $ git pull --rebase
        // make sure the branch in the updated condition
    $ git apply p1225_refactor
        // apply your changes on top of it
  5. The habits which prevent you from the regular loop of conflict and merge

    Often update your 'base' branch, don't let it lag too much behind the remote trunk

    If your changes are not urgent, keep checking out a daily experiment branch from 'base' and try to apply your patch and verify it. If any conflict, you can fix it as early as posiible

    Naming your branches and patches clearly, give them some identifiable prefix or suffix

-- EOF --


open drain & push pull

IC 的輸出腳位通常可以透過設定 register 來改變其輸出的 mode (Open Drain 或 Push-Pull),以下網路上找到的解釋蠻清楚的,紀錄一下。

The push-pull output actually uses two transistors. Each will be on to drive the output to the appropriate level: the top transistor will be on when the output has to be driven high and the bottom transistor will turn on when the output has to go low.

The open-drain output lacks the top transistor. When the output has to go high you simply turn off the bottom transistor, but the line is now pulled high only by the pullup resistor.

Your micro allows you to select between the two types, which means that by setting some bits in some register you actually enable/ disable the top transistor and enable/disable the pullup (if internal, otherwise you just disable the top transistor and have to use an external pullup)

The advantage of the push-pull output is the higher speed, because the line is driven both ways. With the pullup the line can only rise as fast as the RC time constant allows. The R is the pullup, the C is the parasitic capacitance, including the pin capacitance and the board capacitance. The push-pull can typically source more current. With the open-drain the current is limited by the R and R cannot be made very small, because the lower transistor has to sink that current when the output is low; that means higher power consumption.

However, the open-drain allows you to cshort several outputs together, with a common pullup. This is called an wired-OR connection. Now you can drive the output low with any of the IO pins. To drive it high all ouputs have to be high. This is advantageous in some situations, because it eliminates the external gates that would otherwise be required.


[C] Error “initializer element is not constant” and static

嘗試著要在  static 的 struct 成員指向其他 struct 的時候 (也就是巢狀 struct),必須注意成員必須是 const,而 C 和 C++ 的 const 語意有所出入,需注意之!

It has to do with C language. In C language objects with static storage duration has to be initialized with constant expressions or with aggregate initializers containing constant expressions.
A "large" object is never a constant expression in C, even if the object is declared as const.
Moreover, in C language the term "constant" refers to literal constants (like 1,'a'0xFF and so on). Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects with static storage duration, regardless of their type.
For example, this is NOT a constant
const int C = 5; /* not a constant in C */
It would be a constant in C++, but it is not a constant in C. So, if you try doing
static int j = C; /* ERROR */
you will get the same error: an attempt to initialize a static object with a non-constant.
-- EOF --


Use CMake to setup OpenCV environment, and use CMake variable to link installed OpenCV lib

OpenCV 是一個好用的 computer vision open source library,自從 2.0 版本之後就開始採用 CMake 的建構系統,讓整個安裝和跨平台的使用上變得相當容易!

Ubuntu 的安裝方式:
    基本上可以直接參考 Installing OpenCV 2.2 in Ubuntu 11.04 這篇文章,安裝好一些基本的 dependent lib 之後,就是到官網抓最新的 source code 下來編譯然後安裝,比較需要注意的是不要忘記 sudo gedit /etc/ 然後要加入 /usr/local/lib (這樣系統才知道要去哪裡找安裝好的 library)。

Mac 的安裝方式:
    基本上和 Ubuntu 大同小異,不過要先安裝好 Xcode,安裝完不用自行加入 library path。

如何讓別人使用你寫好的 OpeCV application:
    其實安裝好 OpenCV 以後,系統就會有一些現成的 CMake 變數可以使用,如果你利用 OpenCV 開發了一些專案想要利用 CMake 建構的方式,分享給別人的話,那麼可以透過插入下面這兩行,搞定 library linking 的問題:


如果有興趣的話,在你安裝完以後,也可以 clone 一些我之前寫的 project 玩玩!例如:一個追蹤手部移動的程式,詳細運行方式請參考 README 檔案,也歡迎留言指教 :)

--- EOF ---