Tuesday, November 2, 2010

My favorite android apps

I have been using android for a month, and I do think it a great OS, from a geek perspective, of cause ;) Since Google does not provide paid app in Chinese market, I got only free apps, however some of them are already great, let me name some of them:

  • AndFTP is a powerful yet easy to use FTP client.
  • Android Terminal Emulator is definitely essential on rooted box (oops, can I call a mobile phone as box just like a PC?) Without it customizing your system would be much tougher.
  • Barcode Scannner by ZXing Team is the fastest scanner I found in market, and recognizing URI with camera is such a great invention!
  • Batteryminder tells me in percentage how much battery left, which is a must on a phone with a power-hungry large screen just like my milestone...
  • diviClock is a cute desktop clock widget offering shortcuts to your alarm clock and calendar
  • NetCounter is used to track how much traffic is spend in a day/week/month because CMCC's traffice is so expensive - 7MB for 1 USD!!!
  • Jorte provides various widget and calendar view, and connects to both Google calendar and a Japanese(?) calendar service.
  • TaskOS To Do List: writing TODO list in voice is great, hopefully web syn feature will be available soon.
  • Vplayer, though still in alpha stage, plays a great range of format of video.

At last I would be very happy if Google brings paid games, though I can get robo defense free and Angry Birds from Chinese market, and they are very interesting (and very time-consuming, too).

Monday, August 2, 2010

web is a mess…where is the hope?

Recently I am helping designing and coding a web site, which I thought would be a small project… I did know about the difference between old IE and other “standard” browsers and some hacks and work-arounds, but I failed to realize it would be so painful to do all things “right”.

In stead of insisting everything should look exactly the same in all browsers, I think it is natual that some design details could degrade in older browsers, like round corners and text shadow. The real troublemaker turns form elements, each browser (depending on the operating system and even system theme) displays them differently – an awful nightmare :( There aren’t any standard to style them, the only solution is to employ JavaScript to hide the original form and render a fake one with div and spans. Thus select element becomes an unsorted list with a CSS’s and scripts, which seems very bizarre…

Maybe it is time to re-invent the web. People have been talking about this for decades, but I see little progress. I don’t believen HTML5 is a solution, though it’s really hot. Semantics is important, but I don’t believe it the key issue. Web pages are no longer simply documents, but applications, and we are distributing service instead of content. JavaScript has many bad parts but is blessed as well, devil or angel, it should be the core of web. HTML should be fundamentally changed to be a better present layer of JavaScript. A lot of functions carried out by browser natively should be given to JavaScript or other future client-side code. With more power and freedom of client code, coding for web could certainly bring more good things to users.

Monday, May 31, 2010

Serving static file in nginx with a some check

Recently I developed  a small web site for my lab, and we are hosting it on Google App Engine (GAE), as Google provides quite enough resources for a site of several pages ;)

However we also need to provide download of huge files, which can not be store in GAE, thus we had to host it in one of our severs. Initially we do not want our content directly accessible, so we want to use dynamic URL but we don’t want to loose the performance of nginx.

My final solution is use rsa module by Sybren A. Stuvel (which is pure python) to encrypt the real url (with fixed private key) in GAE, and give the encrypted url to user. In the file host, I use nginx’s X-Accel-Redirect feature and a tiny cherrypy server to decrypt the url (with corresponding pub key), and simply set the X-Accel-Redirect header to the real internal path of nginx.

This solution works well in my case :)

Wednesday, May 12, 2010

Mount qemu harddisk image in host system

Recently I got to copy a lot of files from a qemu guest, and I think using network is too slow, so I googled for solutions to mount qemu image in host system (when guest is shutdown). And it turns out that only raw images are supported, therefore the first step is to convert the image format:

qemu-img convert –f qcow2 origin.qcow –O raw temp.raw

Then I fount in archlinux wiki that I should mount with –loop,offset=32256 option, but I fail to figure out where 32256 comes. Luckily I remenbered how I delt with dd images. Just get the offset with fdisk:

fdisk –u –l temp.raw


Then I have the sector size (512 in my case) and the offset (2048, start sector of my partation), so the offset should be 512*2048=1048576. (btw, you can calculate with bc: echo ‘512*2048’ | bc)



mount –t ext4 –o loop,offset=1048576 temp.raw /mnt/some-path


That’s it :)

Monday, April 12, 2010

Thursday, April 8, 2010

Link for X, HAL & udev

It seems we could thank HAL for all these years of great work and say goodbye in a short period of time (source below).

To be honest I still feel confused now and then about what (fill this blank) is doing for me. My understanding is:

linux kernel ─>─ udev ─>─ HAL ─>─ X server
                   │                │
└────────>───────┘
libudev

So I just try to find more about X/Hal/udev thing, and keep some links here. (Remember the best source of information is always the official web sites and the mailing list).

(Not) blaming HAL by Keith Packard (explains what X.org X server needs from HAL before 1.8)

Manage Linux Hardware with udev by Carla Schroder (tells a little history of udev and HAL, and how /dev, /sys works.)

* source: Free X.org Server 1.8.0 with udev to replace HAL

Friday, April 2, 2010

How to delete last 10 lines in a file with script

I find this question asked very frequently... So here is the present of day(not for the April 1st, it's already 2nd in China now ;)

$ tac file.in | sed '1,10d' | tac > file.out

Obviously, you could replace 10 with any number you like, Cheers!

Tuesday, March 23, 2010

Use LibSVM in WEKA in an Archlinux box

I found both WEKA and libSVM in AUR, however, neither maintainer considered that a user might use them together... It seem we Archie got to work it out ourselves, so here is what I did:

Dowload WEKA tarball from AUR, and Change weka.sh to

#! /bin/sh
# Note: the '-Xmx256m' flag is used to set the maximum memory that the java
# program is allowed. When working with large data sets, this number may need
# to be increased based on how much memory you wish to allow weka to have.
# Specifying command line arguments will override the defaults shown here.
# Example: '-Xmx512m'
DEFAULT_ARGS='-Xms32m -Xmx256m'
if [ $# -gt 0 ]; then
ARGS="$@"
else
ARGS="$DEFAULT_ARGS"
fi
java -classpath
"${CLASSROOT+CLASSROOT:}/usr/share/java/weka/weka.jar:/usr/share/java/libsvm.jar"
weka.gui.GUIChooser $ARGS

Do not forget to change the MD5SUM of weka.sh in PKGBUILD file :) Modify LibSVM PKGBUILD to:

# Contributor: Pierre Gueth
# Modified by: Yuanjie Huang
pkgname=libsvm
pkgver=2.9
pkgrel=2
pkgdesc="A library for Support Vector Machines classification, include
binaries and python bindings."
arch=(x86_64 i686)
url="http://www.csie.ntu.edu.tw/~cjlin/libsvm/"
license=('GPL')
groups=()
depends=()
makedepends=()
optdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=
source=("http://www.csie.ntu.edu.tw/~cjlin/cgi-bin/libsvm.cgi?+http://www.csie.ntu.edu.tw/~cjlin/libsvm+tar.gz")
noextract=()
md5sums=('c48109c825d8326d71c8c8564589736d')
build() {
cd "$srcdir/$pkgname-$pkgver"
make || return 1
install -D -m755 svm-train $pkgdir/usr/bin/svm-train
install -D -m755 svm-predict $pkgdir/usr/bin/svm-predict
install -D -m755 svm-scale $pkgdir/usr/bin/svm-scale
install -D -m644 java/libsvm.jar $pkgdir/usr/share/java/libsvm.jar
cd "python"
python setup.py build || return 1
python setup.py install --root $pkgdir
}

Then makepgk and install, have fun.

Monday, March 22, 2010

Where is mendeley user config stored?

Mendeley Desktop is a nice academic research resource management tool. However I messed its configuration up, and got to reset it. But there is no such a directory as .mendeley as I expect in my home directory, so I got to find it like this:

for f in `ls -a1F | grep -E '^\.[A-Za-z]+/$'`; \
do find $f -print | grep -E '[Mm]endeley'; done

Then simply delete everything I got, and bring Mendeley back happily ;)

Thursday, March 18, 2010

Linux Hibernation in short

In order to hibernate in Linux, you need a user space script and an backend. Two User space scirpts widely used are:

  • pm-utils : used in OpenSuse, Ubuntu, etc
  • hibernation-scirpt : used by gentoo, etc

The linux kernel comes with hibernate backend named swsusp but you can also try other tool, so your options are:

  • uswsusp : need to be installed
  • tuxonice : you got to patch the kernel
  • swsusp : comes without extra effords

My choise is pm-utils + uswsusp for I’m too lazy to patch and compile a kernel, and I’ve been using pm-utils for a long time.

And one more thing to mention, even hibernation-script comes with tuxonice, it can use uswsusp as backend.

GAE Hello world error

Google App Engine supports SSL now, however Python 2.5 does not come with SSL socket in stock :(

gae$ /usr/local/bin/dev_appserver.py \
~/projects/hello/
Traceback (most recent call last):
File "/usr/local/bin/dev_appserver.py", line 50, in <module>
execfile(script_path, globals())
File "/usr/local/google_appengine/google/appengine/tools/dev_appserver_main.py", line 338, in <module>
sys.exit(main(sys.argv))
File "/usr/local/google_appengine/google/appengine/tools/dev_appserver_main.py", line 297, in main
server = MakeRpcServer(option_dict)
File "/usr/local/google_appengine/google/appengine/tools/dev_appserver_main.py", line 259, in MakeRpcServer
host_override=option_dict[ARG_ADMIN_CONSOLE_HOST])
File "/usr/local/google_appengine/google/appengine/tools/appcfg.py", line 114, in __init__
self.opener = self._GetOpener()
File "/usr/local/google_appengine/google/appengine/tools/appcfg.py", line 317, in _GetOpener
opener.add_handler(urllib2.HTTPSHandler())
AttributeError: 'module' object has no attribute 'HTTPSHandler'

To resovle the problem you got to recomile Python with SSL support as instructed by Patrick Altman and then follow a regular  configure – make – make install routine.

Then you need to Edit the Modules/Setup.dist to uncomment a couple of lines:

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c 
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl 
-L$(SSL)/lib -lssl -lcrypto

Thursday, February 25, 2010

libpng12.so.0 missing problem in Archlinux

Archlinux has been offering libpng14 recently, however if some self-compiled packages are used in the system, it may turn out an disaster :(

I had cario, freetype2 & libxft compiled from abs so as to enable sort of cleartype effect in type rendering, however, after I updated libpng recently from version 12 to 14, I cannot boot into gdm correctly. I cannot even run vim in a console for it complains that libpng12.so.0 cannot be found.

So I have to:

  1. boot with run level 3 (adding 3 at the end of grub's kernel line);
  2. login as root and remove self-compiled packages that require libpng12, cario, freetype2 & libxft in my case (I found -d option useful since I will soon reinstall these packages);
  3. recompile new versions with libpng14;
  4. install those packages.

Sunday, February 21, 2010

Using English fonts in Windows 7 with Chinese local setting

Windows 7 comes with Lucida Console and Consolas as its default console fonts, but I find no option to enable either of them when my location is set to China. After a few tries, I managed to get them via the following steps:

  1. Right click the console icon and go to the default menu item;
  2. Set the default code page to '437 OEM';
  3. Switch to the font tab, and change the font to Lucida Console, press OK button;
  4. Restart the console and go to the code page setting back to '936 Chinese'.