2013年7月18日 星期四

git revert without change-id

We can use git revert to revert a commit. But if you need a change-id, you will find git revert won't invoke commit-msg hooks. And you won't get a change-id for this commit.
Here is a workaround.

git revert -n <<commit-id>>
git commit

refer to git-revert,
-n
--no-commit
Usually the command automatically creates some commits with commit log messages stating which commits were reverted. This flag applies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. In addition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning state of your index.
This is useful when reverting more than one commits' effect to your index in a row.

2013年7月15日 星期一

how to add an existing git repo. to gerrit project.

1. Create new project in gerrit. command as below.
ssh -p 29418 user@gerrit.server gerrit create-project --name gerrit_project_name

2. Push existing git repo. to gerrit server as below.
git push ssh://user@gerrit.server:29418/gerrit_project_name HEAD:refs/heads/master

2013年5月9日 星期四

如何開啟 windows telnet server (for windows 7)


  1. Click on Start / Control Panel / Program Features / Turn Windows Features on or off.
  2. Check "Telnet Server" and "Telnet Client" on. (as below picture)

You still can NOT telnet to your server until now. just because you will get the following error.
Access Denied: Specified user is not a member of TelnetClients group.
Server administrator must add this user to the above group.
Telnet Server has closed the connection


Please follow the steps to solve the problem.
    1. Open the Local Users and Groups snap-in. In the Start Search box, type mmc lusrmgr.msc.
    2. In the navigation pane, click Groups.
    3. In the details pane, right-click TelnetClients, and then click Properties.
    4. In the TelnetClient Properties dialog box, click Add.
    5. select user who you allows to telnet to your windows7.

    and then enjoy your telnet in win7.

    2013年1月14日 星期一

    MVP in Android

    一個簡單的介紹有關android如何實作MVP pattern.
    An MVP Pattern for Android

    實際範例,可以下載回來自己測試,了解MVP架構。(其中包含了 unit test 的使用)
    mvp-hello-world


    2012年9月25日 星期二

    adb devices no permissions 的解決方法

    使用adb devices 出现如下:
    List of devices attached
    ???????????? no permissions

    解决方法:
    1. 找出usb vid,pid
    $ lsusb      #列出usb device內容
    Bus 009 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 003: ID 192f:0916 Avago Technologies, Pte.
    Bus 003 Device 002: ID 0e8f:0022 GreenAsia Inc.
    Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 002 Device 005: ID 18d1:4e26
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

    只要插入usb device查乙次,拔出usb device查詢一次,比較差異就可以知道我們要的usb device是哪一個。
    如:
    Bus 003 Device 002: ID 0e8f:0022 GreenAsia Inc.
    其中的0e8f就是vid,0022就是pid.

    2. 編輯權限
    sudo vim /etc/udev/rules.d/70-android.rules
    加入以下內容
    SUBSYSTEM=="usb", ATTRS{idVendor}=="0e8f", ATTRS{idProduct}=="0022",MODE="0666" 

    3. 重新啟動 udev service
    sudo chmod a+rx /etc/udev/rules.d/70-android.rules 
    sudo service udev restart 

    4. 重新啟動 adb
    sudo ./adb kill-server 
    $ ./adb devices

    完成

    2012年9月18日 星期二

    UML中的關聯


    class之間的關係有以下幾種
    1. Association / 關聯 / knows a
    X知道Y的存在
    X可能以pointer(指標)或reference(參考)知道Y的存在
    在概念模型階段方向性(箭頭)通常不太有意義可以省略

    2. Dependency / 相依 / use a
    A dependency exists between two elements if changes to the definition of one element (the supplier) may cause changes to the other (the client).
    X相依Y
    Y若改變 X可能會受到影響 但X的改變不會影響到Y
    X可能有某個function可以call Y的function
    舉個例子:
    有一個 class Circle,提供 drawCircle 的功能,然 drawCircle 內部是使用 java 的 graphic 來實作繪圖。則我們可以說:Circle use a graphic. 也就是 Circle 相依於 graphic.

    3. Composition / 組合 / has a
    car 組合 wheel
    Composition是一種整體完全擁有部分
    如車子(car)擁有4個輪子(wheel)
    當車子(car)消滅時4個輪子(wheel)同時也會消滅

    4. Aggregation / 聚合
    car 聚合 passenger
    Aggregation是一種"擁有性"比較弱的關係
    如:
    車子(car)裡面有4個人(passenger)
    當車子(car)消滅時4個人(passenger)不會消滅

    Composition跟Aggregation在意義的差異在於:
    Composition是『同生共死』,當System物件死亡時,Component物件也要跟著死亡。Aggregation是『生死有命』,當System物件死亡時,Component物件並不特別去處理。
    在C#、Java這類有garbage collection的語言,composition幾乎不會用到,但在C++,只要用到pointer,就得自己去delete,所以在composition對於C++就很重要。


    再舉個例子,(from wiki)
    a university owns various departments (e.g., chemistry), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors. In addition, a Professor could work in more than one department, but a department could not be part of more than one university.

    5. Inheritance / 繼承 (UML以繼承表示泛型關係)
    X繼承Z,Y繼承Z,此時Z和X,Y之間就存在著泛型關係。
    Z是共同化(抽象化),X/Y則是特性化(具體化)
    如:
    BMW / Benz 繼承Car,則Car和BMW / Benx就存在泛型關係

    2012年5月1日 星期二

    在Linux下使用兩張網卡的設定

    在一些場合,需要讓同一台電腦,用兩張不同的網卡,來做不同的事情,今天要說的就是這個。最常應用的狀況就是:一個網卡用於對內網路,一個網卡用於對外網路。

    設定如下:
    一般我們現在用的NB通常會有ethernet介面跟wifi介面,我們假設要用wifi連上internet(前題是wifi 熱點已經可以上網),用ethernet連私有網路。

    wifi設定應該如下:
    wlan_IP: 192.168.0.X
    Submask: 255.255.255.0
    以上資料由熱點的DHCP提供。

    ethernat設定如下:
    eth0_IP: 172.16.0.X
    Submask: 255.255.255.0
    以上資料由內部的DHCP提供。

    我們要做的事:
    1. 先查出這兩張網卡的gateway.
    我的方式比較簡單,只要停用其中一個網卡,利用 route -n 即可知道。如:
    Destination = 0.0.0.0 的那一行就是default gateway.

    我們可以用這個方式查出兩個gateway的IP.

    2. 查出 route的設定
    完成之後,將兩張網卡都啟動,再次執行route -n,察看目前預設的route狀況

    3. 修改route成我們要的方式
    因為 linux環境中只能有一個 default gateway,所以我們可以先用下列指令新增default gateway.
    sudo route add default gw {default_gateway_ip1}
    用下列指令將不要的default gateway 移除
    sudo route delate default gw {default_gateway_ip2}
    但是這樣做只是將大家的default gateway換掉,並沒有做到分開。
    為了要將內網/外網分開,所以我們要加一條指令,設定封包流動的方法
    route add -net 172.16.0.0 netmask 255.255.0.0 gw 172.16.100.1
    上面這一條指令的意思就是,只要是要到172.16.*.*的封包,都請傳送到172.16.100.1的gateway。
    其餘的就請透過 default gateway來傳送。



    參考資料