Archive for category hacking

How to save PDF/Images from Mobile Safari to WebDAV compatible iPhone program?

Unlike most desktop browser, there is no “download” option to save an image, a PDF file, etc., from the Mobile Safari so one can read thoses files offline. Well, this is purely a restriction imposed by Apple for security or whatever other stupid reasons. Fortunately, with the most recent update of the operation that support cut and paste and some third party WebDAV compatible file viewer, there could have a workaround.

I have recently set up a system such that when I found an interesting URL, I can cut and paste the URL to a widget served from my own host such that it will fetch the resource from the URL, and save it to a location that corresponds to the location of a WebDAV service in my web host account. Then, I can setup the WebDAV compatible file viewer (currently, I am using Air Share Pro) to view the file in my WebDAV direcotry. Specially, you can also download the files in the WevDAV server locally for future offline reading. This is extreme useful. Once the file is local, you don’t have to worry if you get wifi, EDGE, or 3G signal, and you might also save some battery power since you don’t have to reload the files from the network when you read a document on and off.

The main caveat is that you probably need your own web hosting service or iDisk that supports WebDAV. Beside that, you will need to some simple CGI/AJAX programming and spend some money to buy a WebDAV compatible file viewer like Air Share Pro. I won’t be surprised that one day there will be an iPhone app that implements something like this using a similar idea in a more polished way. Nevertheless, such application is always at Apple’s mercy. Once Apple opens some policy in the OS allowing sharing data and files between application like an real operation system, all workarounds will be totally useless. Wait, actually, the way I set up getting file to iPhone is not limited for submitting URL from Mobile Safari. Any browser can push the resource from an URL to the WebDAV directory, regradless if an desktop OS supports mounting a WebDAV volumn. Not bad as an quick method to get some useful document in the Internet from a desktop system to iPhone.

Tags: , ,

Using Safari on iPhone to read CHM file

iPhone is a fancy toy with a lot of power but Apple deliberately locks a lot of the potential power. One thing I like to do on an iPhone is to be able to read CHM files. As a weekend project, I setup the tool chain for iPhone following the instructions. Then, I grabbed the source code of chmlib. With some minor modification, I was able to compile the chmlib as an iPhone binary library. That was very encouraging.

This provides a convenient way to make iPhone as a CHM reader. In the chmlib source code distribution, there is an example program that runs as a http-server that serves the content of a CHM as standard web page. The “mobileSafari” has no problem to render the results, but the fonts are usually too small to read and the text is typically rendered too wide such that a lot horizontal scrolling becomes annoyingly necessary.

I decided to combine some python code with the chm_http server from the chmlib source code. I modified the source code of chm_http so it can call python code to modify the HTML code in the CHM file, replacing the original CSS with new setting for reading on small screen. Furthermore, I found it was tedious to start the chm_http from a terminal every time when you want to read a different book. I wrote another small python script that can scan a directory and find all CHM files in the directory to output an index html page. At the end, I was able to use the mobileSafari pointing to the index page and select the book I want to read. The “chm_http” server would start automatically to get the book I like to read.

If you are interested in reading CHM on your iPhone. Get this iphoneCHM.tgz (the file would be upload soon). Copy the “chm_http2“, “rewriteHTML.py“, and “CHMServer” to “/usr/local/bin/” in your iPhone. Change the permission of these files such that you can run all of them. Put some chm files in /var/root/Media/CHM_Ebooks/. Open a terminal in the iPhone or ssh into the iPhone to run “CHMServer”. After that, ask the Safari to open this URL http://127.0.0.1:8000. You should see the links to the CHM files. You can now click on any of them and enjoy a nice reading time.

Tags: ,

More on google map image tiles

Lat (-90 ~ 90):
Lon (-180 ~ 180):
Zoom (0-17):


bless all mighty google
bless all mighty google

This is another google map hack. I will write some details about this in the furture. In the mean time, you can also check this out. If you are interested in my source code for this hack, you probably know how to get it anyway.

Tags: ,

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: ,