Archive for category hacking

Extract Google Map Satellite Image Tiles


blesss all mighty google blesss all mighty google
blesss all mighty google blesss all mighty google

Click the tiles to zoom in for one level.
Clike the “back” button to go back.

The URL to extract Google’s satellite image tiles has a very simple encoding. It is simply "http://kh0.google.com/kh?&v=14?t=t" where the argument followed by t= is a string composed with letters “q”,”r”,”t” and “s”. These letters indicate the quarter of the image tile from the last image. For example, the first quarter (north-east) of the root image uses “t=tr”. The second quarter uses “t=tq”, the third quarter uses “t=tt” and the forth quarter uses “t=ts”. To get the next zoom level, you can just append either “r”,”q”,”t” and “s” in the argument. The longer the string, the higher the zoom level. As an example, the URL for the tile that shows Mt. Rainer is “http://kh0.google.com/kh?&v=14&t=tqtrtsqtrqrs/.” It would be straight forward to write a program to get the tiles you need by specifying longitude and latitude. This would be handy to composed satellite image for a region you like and print it out.

Tags: ,

Block web ad

We are living in a world where ads are everywhere. With powerful servers, web advertisement is ubiquitous. Unfortunately, I think they are too intrusive most of time. So, it is generally a good idea to disable the online ads. For a free solution, there are several common techniques. First, figure the ad servers’ IP, and use /etc/hosts to send the ad request call into void. Second, use a userContent.css to filter out ads. For example, if you don’t like the Google ads. You can put the following lines in your /etc/hosts (for OS X or other unix).

127.0.0.1   pagead.googlesyndication.com
127.0.0.1   pagead2.googlesyndication.com
127.0.0.1   domains.googlesyndication.com
127.0.0.1   googlesyndication.com
127.0.0.1   www.google-analytics.com
127.0.0.1   partner.googleadservices.com

For OS X, you will need to use the Terminal.app to run the command lookupd -flushcache to re-flush the DNS cache.

Now, with this setup, I am free from all mighty Google ads. You can do the same to block other ad providers. Combined with the userContent.css, I have regain the nice web browsing experience without the interferences from ads.

I also find out that the Safari plugin SafariBlock can block images and flash ads in a convenient way. Moreover, it can also block specific javascripts although you might have to type the URL pointing to the javascript in SafariBlock’s preferences by yourself. For example, you can block the annoying in-text pop-out type ads from Intellitext by putting a new rule in the SafariBlock preferences to block out the URL ‘http://*.intellitxt.com/*.js’. This will block all javascript from Intellitext without disabling javascript totally.

Tags: ,

Create DMG Automator

This is a simple bash script to create DMG under Finder.

for f in “$@” do b=$(basename “$f”) d=$(dirname “$f”) hdiutil create -format UDZO -srcfolder “$f” “$d/$b.dmg” done

You can use this simple script combined with Automator such that you can create disk image files by selecting files or directories and using the Automator context menu in Finder.

Automator setup

200607231435

Usage:

200607231435-1

Tags: ,

Fix firewire HD problem on a powerbook

After re-organizing some of my daughter’s video and pictures, it is time to backup my whole user directory. Unfortunately, my PB failed to write to two different firewire HDs. The PB mounted the firewire HDs but it hanged when writing some files (I got such log: Jun 4 23:42:26 ECHO kernel[0]: disk1s3: I/O error.). At beginning, I though it was a problem of my firewire enclosure, but it happened on two external HD. I had to conclude the problem was on my PB. So, it was voodoo time. I zapped the PRAM, reseted NVRAM. Reboot, it behaved much better. At least it only hanged after finished copying my /User. This was the message I got in syslog.log

Jun  4 23:57:40 ECHO kernel[0]: FireWire (OHCI) Apple ID 31 built-in:
handleARxReqInt - ARx Request packet error, status = 0xe00002c7

Well, I unpluged the HD and re-pluged it back. It seemed working fine. I tested to write large files to the other HD, it also worked while it failed consistently before I had reseted the PRAM. So, I guess the problem is solved. I still don’t know what NVRAM has any thing to do with firewire.

Tags:

Compress Canon A620 AVI and DV to H.264 mp4 file

Just a memo for myself.

With mencoder, mplayer, ffmpeg and mp4box, I can finally reduce the size of the video files created from my Canon A620 to reasonable sizes such I can put them in my powerbook without depleting the hard drive space.

This is the script for converting AVI to mp4,

mencoder $1 \
-ovc x264 -nosound -ni -sws 0 -x264encopts \
threads=1:me=2:qp_min=22:\
qp_max=51:i4x4:keyint=120:nocabac:deblock:nob_adapt \
-ofps 29.97 -vop harddup -of rawvideo \
-o $1.264

mplayer -vc dummy -vo null -ao pcm:file=$1.wav $1

ffmpeg -i $1.264 -i $1.wav -y -vn -f mp4 -acodec aac \
-ab 96 -ar 11025 -ac 2 -map 1.0:0.0 $1.aac.mp4

MP4Box -fps 29.97 -add $1.264 -add $1.aac.mp4 -new $1.mp4

rm $1.wav
rm $1.264
rm $1.aac.mp4
touch -r $1 $1.mp4

For convert DV to mp4, I use

ffmpeg -i $1 -y -vcodec h264 -f mp4 -acodec aac \
-deinterlace -b 1280 -aspect 4:3 -s 640x480 -naq \
-parti4x4 -deblock -copyts -keyint_min 120 -h264 1 \
-mv4 1 -bf 2 -coder 1 -parti4x4 -partp4x4 -parti8x8 \
partp8x8 $1.mp4touch -r $1 $1.mp4

The results seem pretty reasonable good, while the sizes are still under control.

Tags: ,

Open firmware password and firewire enclosure

I have a firewire enclosure using Genesys GL-711 chip. It has been working well. However, I tried to mount it under OS X.4.4 earlier today and failed. The System Profile showed the firewire bus but not the hard drive. My powerbook could still mount other external firewire hard drives using different chipsets and the GL711 box could also work with other computer too. I was very puzzled.

I tried to reset PMU and zapped PR ram. I needed to disable the open firmware password to do so. After the zapping PR-ram, resetting PMU, rebooting the computer, the hard drive controlled by GL-711 showed up. I thought it might be a good idea to set the password again, so I did it. Reboot, the powerbook could not see the hard drive anymore. After a few more rebooting and testing, I confirmed that setting open firmware password affected whether the powerbook 12 inch could see the hard drive or not.

This is such strange bug. How would the open firmware password affect the firewire bus? And why it is so specific to one kind of firewire bridging chip but not the others? I guess it would probably not be easy to figure that out.

Tags:

Safe Sleep

In the recent OS X 10.4.3, it is possible to “suspend” my powerbook into hibernate mode that does not use any power (see Andrew’s Blog). I write this simple script “sleepmode” to make life slightly easier with this feature.

#!/bin/sh
case ”$1” in
  deep)
    sudo pmset -a hibernatemode 1
  ;;
  safe)
    sudo pmset -a hibernatemode 3
  ;;
  normal)
    sudo pmset -a hibernatemode 0
  ;;
  go)
    omode=”`pmset -g | grep hibernatemode | cut -f 2`”
    sudo pmset -a hibernatemode 1
    echo The system is going to the deep sleep in 3 seconds
    sleep 3
    osascript -e 'tell application "Finder" to sleep'
    sudo pmset -a hibernatemode $omode
    echo The system is back to it orginal sleep mode
  ;;
esac

case ”`pmset -g | grep hibernatemode | cut -f 2`” in
  0)
  echo System is in the Normal Sleep Mode
  ;;
  1)
  echo System is in the Deep Sleep Mode
  ;;
  3)
  echo System is in the Safe Sleep Mode
  ;;
esac

Tags: ,

看看上個星期收集了多少和那些垃圾, Tiger’s Way

mdfind -0 -onlyin /Users/ "kMDItemUsedDates >= \$time.this_week(-1)" |\
xargs -0 du -k |\
sort -k 1 -n -r

當然,你也可以用 SmartFolder.

Tags:

看看上個星期收集了多少和那些垃圾

find  .  -newerct  '7 days ago'  -exec ls -ald {} \; > fileList

Tags:

Debian linux as a VPN server for OS X

最近決定來試看看把在學校裡工作用的 desktop 拿來當自己的 VPN server,這樣作最大的好處是可以在家裏工作時還是可以取用學校有訂閱的期刊論文的電子版。雖然學校其實有提供 VPN client 連到學校的 VPN server,但是好像還不支援 Tiger,要多裝一個 client 也是很煩的事。之前我是用 ssh tunneling 加上 tinyproxy 來『模擬』VPN,其實也已經很實用了。但是還是手癢,想來玩玩自己的 VPN server 然後用 Tiger 內建的 VPN client 去連結。

在 Tiger 可用的而 linux 有支援的 VPN 中,pptp 是最好設定的。在 Debian 下唯一比較麻煩的是要自行編譯 ppp_mppe.ko 的 kernel module。把 ppp_mppe.ko 編好後,在 /etc/modutils/aliases 中加入一行

alias ppp-compress-18   ppp_mppe

這樣 kernel 才會自動載入這個 module,當然妳也可以用 insmod 來載入所有 ppp_* 相關的 module。

要把 debian 設成 pptp 的 server 要先用 apt-get 安裝 pptd 套件:

apt-get install pptpd

然後再來要設定下面幾個檔案,

設定 pptp:

file: /etc/pptpd.conf

speed 115200
option /etc/ppp/pptpd-options
noipparam
logwtmp
bcrelay eth0
localip 192.168.0.1
remoteip 192.168.0.234-238,192.168.0.245

設定 ppp:

file: /etc/ppp/pptpd-options

name pptpd
ktune
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
# replace 127.0.0.1 with the remote server's DNS ip
ms-dns 127.0.0.1
proxyarp
nodefaultroute
lock
nobsdcomp
nodeflate

設定用戶代號與密碼:

file: /etc/ppp/chap-secrets

# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
VPNUserName pptpd VPNPassword *

把 ppp 連結的 traffic 導向到 server 的外部 ip/網路卡:

file: /etc/ppp/ip-up.local

#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
modprobe ipt_MASQUERADE
iptables -t nat -F
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

這些設定完成後。在 OS X 下就可以 Internet Connector 中的 PPTP VPN 來連到 server 上。記得要把 Internet Connector 的選單中 Connect -> Options 中的 Send all traffic over VPN connect 選起來。這樣再加上在 server 上的 iptable 的設定,當用 VPN 連線的時候,外界看起來就像你是從 server 連出去的(妳可以試著連到 checkip.dyndns.org 來看看外面的網站看到的 ip 是不是 server 的 ip)。

Tags: ,