Sunday, November 26, 2006

Rename a JPG File to Photo Taking Time

If you use DC to take photos, the file names are in form of a prefix following by a sequence number. This form of file name is meaningless and not convenient for looking up. Recently, I found a tools called jhead which can rename JPG files to their photo taking time in a batch. To do the batch renaming, just issue a single command:
jhead -n%Y%m%d-%H%M%S *.jpg
jhead is more than a file rename util. It is a exif Jpeg header and thumbnail manipulator utitliy. Please visit jhead's web site for details: http://www.sentex.net/~mwandel/jhead/

Friday, November 24, 2006

STL list size() method is slow

In STL list, the size() method is o(n), where n is number of elements in the list. The implementation of size() is by traversing the linked list and counting the nodes one by one. So, it sounds stupid.
I have written a simple program to test the performance of size() method in STL list and STL vector. For a STL list with 10M integers, it takes 0.17 sec. to get the size. However, for a STL vector with 10M integers, it takes 0.4 micro sec to get the size() in same machine.
There are some suggestions:
  1. Use vector instead of list.
  2. If the application need to check whether the list is empty or not, uses "list.emtpy()" instead of "list.size() != 0".
  3. use an extra counter variable to counting the size of a list.

Sunday, November 19, 2006

VMWare Server with ALSA DMix

In Linux, the sound-card drivers normally do not support concurrent access. This means when you playing MP3, your instant-chat program (e.g. gaim) will be mute. To solve this problem, there are some projects -- ALSA DMix, ESD, ARTSD, JACK.... However, most of them are not compatible each other and the applications needs to use the API provided by the specific project.

In my Ubuntu desktop, I use ALSA DMix with ESD approach. Most applications should support ALSA or ESD. However, VMWare support neither of them. VMWare only use native /dev/dsp device for sounding. After some searching on the web, we can use the LD_PRELOAD libossa.so trick.

After half day of try-and-error, the following is the summary of how to make VMWare work with ALSA:
  • make sure you installed the package "olsa-oss".
  • add suid bit to /usr/lib/libaoss.so by command chmod +s /usr/lib/libaoss.so
  • rename the /usr/lib/vmware/bin/vmware-vmx to vmware-vmx-real
  • create a shell script /usr/lib/vmware/bin/vmware-vmx with the following contents
#!/bin/sh
LD_PRELOAD=libaoss.so exec /usr/lib/vmware/bin/vmware-vmx-real $@
  • make sure the shell script is executable (i.e. chmod a+x /usr/lib/vmware/bin/vmware-vmx-real)
  • If your guest OS's disk image file is "single growable virtual disk" type with size large than 2G, you should use the vmware-vdiskmanager to split it into several files. Otherwise, you will encounter the problem of "File too large".
Related Link:
A Post about VMWare works with ALSA
ALSA DMix

Friday, November 10, 2006

Switch To Ubuntu

I have been used Linux as my primary desktop OS since 2001. At that time, I used Mandrake because it was easy to install. Then I switched to Debain because of its good package management and package update. Today, I decided to switch to Ubuntu.

Ubuntu is based on Debian's package management and adds user-friendly installation. No wonder Ubuntu is the most popular Linux distribution (http://distrowatch.com).

Today, I tried to install Ubuntu and don't encounter any difficulty. It can auto detect and configure all my hardware (sound card, video card, network card....). So, everything works properly!

One year ago, I have tried to install Ubuntu and I found it was not mature. So, I remained to use Debian. Now, Ubuntu 6.10 is much better. I love it!