2011年5月27日 星期五

[Chrome] How To Print Preview in Google Chrome

How To Print Preview in Google Chrome

  1. First of all you would need to download an extension called IE Tab. This is a very useful extension which opens websites in Google Chrome as if its opening in Internet Explorer. You can get more details on it here.
  2. Now open the page which you want to print (or print preview), and click on the IE Tab extension icon besides your address bar. It would open a new tab which would display the page as if its Internet Explorer.
  3. Once the page loads, right click anywhere on the page and you can see the option ‘Print Preview’ in the context menu.
  4. Click on it and that’s it, you would be able to preview how the print would look.

    References:

    2011年5月19日 星期四

    [Android] How to set hostname on Android device?

    $ su
    # setprop net.hostname whateveryouwant
    

    Please restart wifi after set hostname.

    You can use the following code to check if it works.
    InetAddress addr = InetAddress.getByName("192.168.15.105"); // 192.168.15.105 is your device ip
    
    Reference:

    2011年5月17日 星期二

    [Android] tcpdump for Android devices

    tcpdump for Android devices

    • tcpdump, a powerful command-line packet analyzer.
    How to install on your device?
    Unzip tcpdump.rar
    // copy to tcpdump to your /system/bin:
    1. adb remount 
    2. adb push tcpdump /system/bin
    3. adb shell chmod 777 /system/bin/tcpdump 
    

    How to run tcpdump on your device?
    Run: adb shell tcpdump -i any -w /storage/netlog.cap
    Stop: USE Ctrl + C to abort this packet monitor. 
    Download log: adb pull /storage/netlog.cap c:\ 
    Delete log: adb rm /storage/netlog.cap 

    tcpdump parameters
    -i :後面接要監聽的網路介面,例如 eth0, lo, ppp0 等等的介面;any表示所有的網路介面
    -w :後面接要監聽所得的封包資料儲存的檔名
    
    

    References

    2011年5月5日 星期四

    [Android] SharedPreferences - a simple example

    我們可以用Android的SharedPreferences來讀寫裝置上的偏好設定檔。

    首先需要使用getSharedPreferences(String, int)來取得SharedPreferences。
    • 第一個參數是偏好設定檔的名稱,如果指定的設定檔名稱不存在的話,當使用者使用SharedPreferences.edit()而且Editor.commit()去更新資料時該偏好設定檔會自動產生。
    • 第二個參數是偏好設定檔的模式,0或MODE_PRIVATE是預設的參數,MODE_WORLD_READABLE 和MODE_WORLD_WRITEABLE為設定控制權限,MODE_MULTI_PROCESS為多個程序可以共用的偏好設定檔。

    String PREFS_FILENAME = "APP_SETTING";
    SharedPreferences mConfig = getSharedPreferences(PREFS_FILENAME, 0);
    SharedPreferences.Editor mConfigEditor = mConfig.edit();
    
    mConfigEditor.putBoolean("Setting1", true);        // set Setting2 = true
    mConfigEditor.commit();                  // We do commit to save data
    boolean bSetting1 = mConfig.getBoolean("Setting1", false);// get Setting1 from SharedPreferences
    System.out.println("Vince bSetting1 = " + bSetting1);   // bSetting = true
    
    mConfigEditor.putBoolean("Setting2", true);        // set Setting2 = true
    boolean bSetting2 = mConfig.getBoolean("Setting2", false);// get Setting2 from SharedPreferences
    System.out.println("Vince bSetting2 = " + bSetting2);   // bSetting = false
    
    

    References:

    [Eclipse] JAR Library: Export and Import

    Step by Step:
    1. In project source code, Right Click Mouse Button.
    2. Select [Export]
    3. Select Java > JAR file.
    4. Check the source code that you want to export as JAR library.
    5. Select the export destination.
    6. Press [Next].
    7. Press [Next].
    8. Press [Finish].

    Reference:

    [Java] 用YourKit看Java程式的CPU & Memory

    YourKit
    Step 1: Select monitor application
    • Launch your eclipse and YourKit.
    • Run your code.
    • Your will see your eclipse and running process on YourKit.

    Step 2: Capture Memory Snapshot
    • Click Capture Memory Snapshot to see memory usage in detail.
    • Launch your eclipse and YourKit.


    Step 3: Memory Statistics
    • You will see memory statistics.
    • For example, if you want to see who use char[], we can click "Click to start calculation"

    Step 4: Do Memory Calculation
    • You can see who use this object (ex: char[]).

    Step 5: Object Explore
    • You can use "Object Explore" to see data in memory.


    Step 6: Paths of GC roots
    • In Memory Statistics, right click class (ex: char[])
    • Click "Paths of GC roots", you can see the GC status of this object.
    References