»
S
I
D
E
B
A
R
«
Android Service with dynamic arguments
Aug 24th, 2010 by kanru

Recently when I was preparing some Android training material I found this little trick.

Android “init” can do a lot of things, including “on property change” trigger; one can image some applications use this to implement an ad-hoc IPC. One example is the system/libnetutil that monitors the “init.svc.dhcpcd” property to detect whether dhcpcd is running or not.

Android framework can execute some predefined command (service) via the “ctl.start” property, the most interesting part is you can supply dynamic arguments to the command just like you were calling a command from shell.

The format is

setprop ctl.start service:arg1 arg2 arg3..

It must be a oneshot service, for example you can define a dhcpcd service like:

service dhcpcd /system/bin/dhcpcd -B
    group dhcp wifi system
    disabled
    oneshot

And set the target interface dynamically:

setprop ctl.start dhcpcd:eth0

“init” will then execute “dhcpcd -B eth0″ with appropriate permissions.

iotop – monitor your disk usage
Dec 2nd, 2009 by kanru

Disk I/O 往往是效能的殺手,但是我們卻很難抓出現在到底是哪個程式正在 I/O。 iotop 是一隻 python script,用類似 top 的介面顯示各 process 的 I/O 狀況,還會顯示每個process 的 throughput 是多少。

要使用 iotop,編譯 kernel 時要選 CONFIG_TASKSTATS 與 CONFIG_TASK_IO_ACCOUNTING。

以下是截圖: iotop screenshot

註:PowerTop 將內建類似功能,參考 http://blog.fenrus.org/?p=38

救回部份檔案…
Apr 28th, 2009 by kanru

上禮拜還在煩惱檔案遺失的問題,尤其是舊的 gpg 金鑰,但必須收假回部隊了也沒辦法繼續處理。

再度放假回來之後,陸續在 reader 上看到不少有關資料救援的 blog,這些文章出現的時機還真是巧… 最有用的是今天看到的這篇 Recovering data from a broken NTFS hard drive 使用 foremost 或是 photorec 等不理會磁碟上用的是什麼檔案系統而直接搜尋檔案特徵來辨識檔案的程式進行救援。

photorec 執行後,60 GB 的映像檔分析了約三個半小時,找到 961920 多個檔案,其中文字檔太多了難以整理,某些還是支離破碎的… 大概只能建立索引方便以後搜尋吧,還取回不少照片,不過最最最重要的是 secring.gpg 終於拿回來了 :)

Parasite – Gtk+ UI 除錯開發工具
Mar 16th, 2009 by kanru

Parasite 是一個強大的 Gtk+ UI 除錯/開發工具,使用方法類似 Firefox 中很好用的 Firebug,可以附著於執行中的程式,顯示 widget tree 與 properties,動態修改 widget 屬性,甚至透過 python console 還可以隨時 coding 改變 widget 行為。

Parasite Python Shell

目前還沒有正式發行版,可以自己從 Git 拖回來編譯安裝。

$ git clone git://github.com/chipx86/gtkparasite

參考:

話說,現在 github 不只有 git hosting,還有 web page hosting 了,不少專案就這樣透過 github 快速成立,或許以後 github 會朝完整的 project hosting 發展?

Current state of Debian Chinese translations
Dec 18th, 2008 by kanru

整理一下目前 Debian 各部份的中文翻譯狀況:

transgraph

收錄於 Debian 中的軟體的翻譯

這裡大部分是各種有收錄在 Debian 中的軟體的 PO 檔的翻譯,不是 Debian 特有的,主要協調者是 Zh-l10n。

參考:

Debian 套件設定樣板的翻譯

也就是 po-debconf 的翻譯,這些翻譯會出現在安裝套件後的設定畫面。目前有翻譯的還不多,想要進行翻譯的可以參考 popcon 分數決定要先從哪個套件開始。

可以使用這隻 script 來幫助翻譯:

  • 取得 po 檔
    • transhelp get abook
  • 編輯
    • edit abook/zh_TW.po
  • 檢查翻譯結果
    • transhelp check abook
  • 模擬顯示結果
    • transhelp display abook
  • 提交
    • transhelp send abook

transhelp 只是簡化翻譯的流程,真正要翻譯前請先參考 README-trans

Debian 套件描述的翻譯

套件描述的翻譯,這些翻譯會出現在套件管理軟體中 (如 aptitude) 或是 packages.debian.org 網站上。

無論你是要翻譯或是要 review,都可以透過網頁介面進行。

參考摩托學園:DDTSS翻譯 Debian 套件訊息

Debian 網站的翻譯

目前最重要的頁面都已經是最新了,其他常用頁面以及一些曾經翻譯過的頁面也在陸續整理中。我用 graphviz 畫了一張目前翻譯狀況的圖示,紅色代表目錄中有未翻譯網頁,綠色代表網頁已經跟原文同步。

想要參與翻譯的可以參考這裡這裡

Debian Installer 的翻譯

這裡整理了 Debian Installer 會用到的套件的翻譯,目前只剩下少數還未更新。

Lenny Release Note 的翻譯

很早就開始進行了,就我所知 Tetralet 已經翻譯了一部分。想要幫忙的可以聯絡他。

Lenny Install Manual 的翻譯

之前是 dreamcryer 翻譯的,現在聯絡不到人。簡體中文版已經翻譯的差不多了,想幫忙的人可以由此下手。

Debian Wiki 的翻譯:

不知道,Wiki 變化太快也許不適合進行翻譯。

其他

歡迎提供其他相關訊息 m(_ _)m

TODO: 整理到 Wiki 上

參考網站:http://www.debian.org/international/l10n/

Git branch in bash prompt
Dec 13th, 2008 by kanru

之前提過 zsh 有支援在 prompt 上顯示多種 VCS 資訊的功能,不知道 bash 上是否有人寫好同樣支援這麼多種 VCS 的 library,不過目前 git 附帶的 bash completion script 中有提供自訂 PS1 的函式。

只要呼叫 __git_ps1 即可得到目前的 git branch 的格式化輸出,可以自訂 prompt 如下

GITPS1='$(__git_ps1 ":%s ")'
export PS1="\w ${GITPS1}\$ "

就會顯示如

/usr/src/awesome :next $

這樣的 prompt

Pdnsd – cache your DNS query
Dec 8th, 2008 by kanru

pdnsd 是一個小型的 proxy DNS server,主要功能就是 proxy 與 cache,而不是像 bind9 那樣的完整 DNS server。

雖然 DNS 通常不是網路延遲的主因,但有時候就是很慢,使用 pdnsd 前後可以差非常多。

% time host blog.kanru.info 168.95.1.1
0.00s user 0.01s system 0% cpu 0.963 total
% time host blog.kanru.info 127.0.0.1
0.00s user 0.00s system 65% cpu 0.011 total

在 Debian 系統上,如果你原本就有使用 resolvconf 的話,那麼只要在 configure 時選擇使用 resolvconf 就會動態的把 resolv.conf 內的 DNS server 包含,而 resolv.conf 只會剩下 127.0.0.1,如:

% /usr/sbin/pdnsd-ctl status
...
label: resolvconf
ip: 168.95.1.1
server assumed available: yes
ip: 192.168.1.1
server assumed available: yes
port: 53
...
% cat /etc/resolv.conf
nameserver 127.0.0.1

apt-get install pdnsd 完全零設定 ;-)

為什麼 Git 比 X 好?
Dec 6th, 2008 by kanru

當初一看到這個標題心裡想的是 Git 怎麼拿來跟 X 比?原來這個 X 是指其他 SCM…

http://whygitisbetterthanx.com/

很多人都注意到了,但是現在有

http://zh-tw.whygitisbetterthanx.com/

囉,小小替 Git 宣傳一下 :p

Vim – 以游標位置為基礎捲動螢幕
Dec 1st, 2008 by kanru

不是人人都有大螢幕可以一次容納幾百行程式碼,且看文件時我們常會希望可以從頭看到尾,或者是寫文章時我們會希望可以從螢幕的最上頭開新段落然後一次寫一整個螢幕。

如果不熟悉以下命令,你可能常常要用 hjkl 或方向鍵去移動游標,調整顯示的範圍。但是,其實不用這麼辛苦。

zt 把游標下這行放到螢幕最上方

zz 放到中間

zb 放到最後

比如說,要開始寫新段落我只要 L 移動游標到最後,然後 zt ,我就會有一整頁空白的空間可以開始揮灑 :)

Vim – 檔名太長怎麼辦
Nov 30th, 2008 by kanru

這是 vim 的一個小技巧,考慮以下情境:

  1. 我現在在 ~/ 目錄
  2. 因為某個原因我打開 vim 編輯 /usr/src/foodir/src/bardoor.c
  3. 看了看,發現需要參考同目錄下的 bardoor.h,於是打入命令 :tabe
  4. 接下來怎麼辦?因為目前工作目錄是 ~/,如果要用 vim 的 tab 補完的話還是需要把路徑再打一次
  5. 想一想再看答案 :)

    Read the rest of this entry »

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2004-2009 Kan-Ru Chen