Asleep from Day

June 11, 2009

android-pdk

Filed under: 0xlab, Android, tip — John @ 6:13 pm

Android porting development kit could be obtained by

make pdk pdk_all

in your top repo dir. You can find the pdk doc in out/target/common/docs/online-pdk . If you open index.html directly you will find the css is all messed up. The quickest way might be moving the directory to /var/www, install one web server (I use thttpd) then open http://localhost/online-pdk/ .

The document is far from complete but it’s still a good reference to save a lot of time.

June 8, 2009

Integrate emacs23 with emacsen on Debian

Filed under: tip — John @ 12:05 am

I’m quite disappointed about the unicode support of emacs22 so I decided to give emacs23 pretest a try. It turns out to be quite nice but it doesn’t include Debian’s debian-startup.diff patch and I don’t want to add it to the source code. So, I decided to solve it in my .emacs file. Here is the related script:

;; hacks to use debian emacsen in emacs23
(if (not (string-match "^23." emacs-version)) nil
  (setq load-path
;; more paths could be added here
	(append (list "/usr/share/emacs/site-lisp"
                      "/usr/share/emacs/site-lisp/global") load-path)
	)
  (defconst debian-emacs-flavor 'emacs22
    "A symbol representing the particular debian flavor of emacs running.
Something like 'emacs21, 'xemacs21, etc.")
  (load-library "debian-startup")
  (debian-startup debian-emacs-flavor))

And I also realized the GUI version of emacs doesn’t bring me any good then the console version, so I’m running it without X now. Much easier to use.

May 17, 2009

Doxygen and Android source code

Filed under: 0xlab, Android, tip — John @ 1:18 am

It turns out doxygen can be quite handy if you want to read android code. It supports javadoc style, so it could generate documents for the java files. It supports qt style, so the c++ code is also taken care of. Inheritance diagrams, integration with gnu global, etc. are quite useful as well.
android-doxygen

May 15, 2009

My choice of desktop recorder

Filed under: tip — John @ 2:53 pm

Just a quick note: after tried out all choices in 5 Ways to Screencast Your Linux Desktop, my pick is gtk-recordmydesktop. It’s much much easier to use then vnc2swf without the bugs of Istanbul.

December 14, 2008

Portege 2000 and Ubuntu 8.10

Filed under: linux hardware, tip — John @ 12:46 am

8.10 Release Notes

BAD :(

Now I have to use this to do presentation:

john@john-laptop:/etc/acpi$ cat videobtn.sh
#!/bin/sh
test -f /usr/share/acpi-support/key-constants || exit 0
. /usr/share/acpi-support/key-constants
acpi_fakekey $KEY_VIDEOOUT
CRT=/proc/acpi/video/VGA/CRT/state
LCD=/proc/acpi/video/VGA/LCD/state
if grep "state:.*0x0d" $CRT 1>/dev/null 2>&1
then
echo 0x80000001 > $CRT
# echo 0x80000001 > $LCD
else
echo 0x80000000 > $CRT
echo 0x80000001 > $LCD
fi

September 27, 2008

udev and allow-hotplug on ubuntu and debian

Filed under: Openmoko, tip — John @ 3:07 pm

I finally got bothered enough to fix the /etc/network/interfaces problem on my Ubuntu notebook. The problem is that when my neo got connected, I want to do some automatic setup. On Debian lenny, it’s quite easy:

allow-hotplug usb0
iface usb0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        post-up iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        pre-down echo 0 > /proc/sys/net/ipv4/ip_forward
        pre-down iptables -t nat -D POSTROUTING -s 192.168.0.0/24 -j MASQUERADE

But on Ubuntu gutsy it doesn’t work. I have to replace “allow-hotplug” by “auto”. Even if I changed that, it will only work for the first time you plugged the device. That’s because of a bug listed here. The solution is to remove the DRIVER=”?*” in /etc/udev/rules.d/85-ifupdown.rules .

Now, finally, if works even after multiple plug/unplug. However, there is still one problem left: “auto usb0″ basically means the system will try to bring up the device during booting. It works for “lo”, the local loopback network interface because it’s always there. But the usb0 won’t be there everytime we boot. That causes some error messages. My solution is to modify /etc/udev/rules.d/85-ifupdown.rules again, replace “auto” by “hotplug”, and use “allow-hotplug usb0″ in my /etc/network/interfaces . The final 85-ifupdown.rules looks like this:

# This file causes network devices to be brought up or down as a result
# of hardware being added or removed, including that which isn't ordinarily
# removable.
# See udev(7) for syntax.

SUBSYSTEM=="net", GOTO="net_start"
GOTO="net_end"

LABEL="net_start"

# Bring devices up and down only if they're marked auto.
# Use start-stop-daemon so we don't wait on dhcp
ACTION=="add",          RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifup -- --allow hotplug $env{INTERFACE}"

ACTION=="remove",       RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifdown -- --allow hotplug $env{INTERFACE}"

LABEL="net_end"

Some further digging shows the difference between debian lenny and ubuntu gutsy in the handling of the “interfaces” file. On Debian:

john@buddha:/etc/udev/rules.d$ grep net.agent *
80-drivers.rules:SUBSYSTEM=="net",                              RUN+="net.agent"

so it runs net.agent, a script under /lib/udev/ to bring up the interfaces. On Ubuntu, this is simply the job of the 85-ifupdown.rules above.

March 29, 2008

利用 ssh 連到 NAT 內的電腦

Filed under: tip — John @ 3:53 am

在 NAT 內的電腦 (暫名為 A) 上下指令:

autossh -R :1234:localhost:22 my.server.com
  1. autossh will automatically reconnect
  2. -R :1234:localhost:22 意思是連到 my.server.com,在 my.server.com 上頭開 port 1234 回連到 A。
  3. my.server.com 上頭 sshd_config 必須要設定 GatewayPorts clientspecified or yes

然後在外頭的 linux 電腦連到:

ssh -p 1234 my.server.com

這樣就可以連回 A 了。如此這般就算沒有 VPN 也可以在家工作。

February 10, 2008

DPI果然好用啊。

Filed under: tip — John @ 2:49 am

話說不知道從哪次更新之後,notebook的字型就一直很鳥,調到12號字還是有點小,更加上還很醜,因為其實很多相對應的效果都是針對一般預設10號字左右去調的。剛剛才想到,應該是因為DPI差太多的原因吧,於是拿出尺量了一下螢幕的大小,然後在xorg.conf中加入DisplaySize的設定:

Section "Monitor"
    Identifier	"Generic Monitor"
    Option		"DPMS"
    HorizSync	28-49
    VertRefresh	43-72
    DisplaySize	245 185
EndSection

嘿,果然搞定。嚴格說起來,在不同的顯示器底下,理想狀態應該是同一個theme只要調整DPI以後都可以得到相同的視覺效果。Microsoft Windows在一開始就忽略掉DPI的設定,還把它誤導成「調整字型大小」用,實在不是很好的觀念。

December 6, 2007

My .emacs

Filed under: tip — John @ 2:55 pm

emacs當然不是最好上手的editor,不過功能強大、擴充容易,目前仍然是程式開發最佳選擇之一。我的.emacs設定檔設定了[f4]為關檔、[f5]為執行make、[ctrl-enter]為設定記號,因為原先的[ctrl-space]會跟輸入法衝到。另外(windmove-default-keybindings)是超好用的視窗切換熱鍵,例如要移到下方的視窗,就是按shift-down。印象中這功能在21版還沒有。剩下的功能都是直接在emacs裡頭執行customize來設定的,建議就不要手動改了。

幾個比較特別或有用的設定:

‘(current-language-environment “Chinese-BIG5″) 用來指定預設環境為BIG5中文。這環境在UTF-8以及BIG5底下都工作正常,但這到22版才真正有用。

‘(default-major-mode (quote text-mode)) 由於 emacs 是我預設用來寫email的editor,所以設定預設模式為text-mode會比原本的fundamental-mode方便。

‘(initial-frame-alist (quote ((width . 80) (height . 60)))) 改變預設視窗大小。

‘(server-mode t) server-mode是個很好用的新功能。打開之後,只要在其他視窗打emacsclient xxx就會自動用已經在執行的emacs開檔。我目前環境變數EDITOR的內容為”emacsclient -a emacs”,試試看。

‘(winner-mode t nil (winner))) 視窗調大小以後可以用winner-mode還原/重做。熱鍵是Ctrl-C, left/right.

調字型的方法:22版對gtk支援,應該是不用調。真的要調的話,用shift-滑鼠左鍵叫出字型視窗,選到自己喜歡的以後,進入customize-group, basic-face, default底下,把那邊的值寫入.emacs即可。

;; global set key
(global-set-key [f4] `kill-buffer)
(global-set-key [f5] `compile)
(global-set-key [C-return] `set-mark-command)
(windmove-default-keybindings)

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(c-default-style (quote ((c-mode . "stroustrup") (java-mode . "java") (awk-mode . "awk") (other . "gnu"))))
 '(current-language-environment "Chinese-BIG5")
 '(default-major-mode (quote text-mode))
 '(initial-frame-alist (quote ((width . 80) (height . 60))))
 '(prolog-system (quote gnu))
 '(scroll-bar-mode (quote right))
 '(server-mode t)
 '(show-paren-mode t)
 '(tool-bar-mode nil)
 '(user-mail-address "cylee@programmer.net")
 '(winner-mode t nil (winner)))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:stipple nil :background "black" :foreground "grey" :inverse-video nil :box nil :strike-through nil :o verline nil :underline nil :slant normal :weight normal :height 105 :width normal :family "adobe-courier")))))

Blog at WordPress.com.