Tuesday, May 12, 2009

Monday, May 11, 2009

Difference between function, macro and special form in Lisp

A very good description of the differences between function, macro and special forms in Lisp. Read all the way through the end of the email thread.

Saturday, May 09, 2009

A list of WYSIWYG editors for content mangement

There are times when you would like to have a text area in your web site that resembles like a word processor's page, with a lot of controls to format your text. If you have worked with any content management system (CMS) or a wiki, you have most likely come across one. I was looking for a WYSIWYG editor and came across a few of them. Thought I sould share the list with everyone so that you don't have to waste your precious time. The list below is not in any particular order.

  1. FCKEditor. Looked like the editor that had the most features. This site provides a demo and a very good documentation as well.
  2. TinyMCE. Wherever people talk about WYSIWYG editor, they invariably mention both FCKEditor and TinyMCE. Provides a demo and by looking at the source of demo you can find how easy it is to integrate this editor.
  3. Xinha.They have an excellent demo page that allows you to customize the editor on the fly and see.
  4. Kupu. Kupu is from Open Source Content Management team. I could not see a demo anywhere (the site provides two links to Plone and Silva, unfortunately both are broken). I could only see a few screenshots.
Hope that helps for someone on the lookout for the right editor.

Friday, May 08, 2009

Django tutorial

I manged to complete the three parts Django tutorial today. I haven't worked with many web frameworks before. I have a very good experience in CGI and some flaky experience in JSP and PHP. I liked Django for the reason that they coupled the model and the database and provide the ability to almost worry nothing about writing database queries. I don't know how much more time it would have taken if I had written the poll application myself in either JSP or CGI. Especially setting up the database and the tables.

Now that I have first hand experience in developing application in Django, I am yet to see the performance under reasonable and heavy loads. I am also yet to discover how Django is deployed in production. As per my understanding, the design of the Python interpreter itself is not suitable for multi-threaded applications. The best way to scale Python is not to create a multi-threaded application, but to have more instances of Python running with some load balancing server in front of these applications.

Thursday, May 07, 2009

Mounting folder shares in xVM

In xVM, you can access folder shares from the host system in your guest Linux system. The prerequisite is to install all the guest additions. The following is the process that I followed to install guest additions and mount the shares in my Ubuntu desktop (Linux ubuntu-desktop 2.6.24-24-generic).

Installing guest additions is very easy. Once you start your guest OS, you click on the "Devices -> Install Guest Additions" in the xVM. Then it will mount a CD ROM for you. Once the CD ROM is mounted, just let it auto run or you can run the appropriate shell script from the mounted CDROM. Usually it is mounted under /media/cdrom. So doing an ls under that directory should tell you which shell script you need to run.

To create a share, go to "Devices -> Shared Folders". Click on the add share icon (the one that has "+" in it). Select the folder you would like to share with the guest and then give it a name. It is preferable to give a short name for the share. Let us say you give the name shared-folder. Depending on your need, you can mark it read-only. If you would like to make the share permanent across multiple invocations of the xVM, you can click on the "Make Permanent" too. Once this is done, click on "OK" and close this box.

From your guest, give the following command (I am mounting under /tmp/shared-folder) as root:
mkdir /tmp/shared-folder
mount -t vboxsf shared-folder /tmp/shared-folder
Thats it. You can access all the files under the shared-folder shared from the /tmp/shared-folder directory. BTW, there is no need that the share name and the mounted directory name should be the same.

For details, please refer to the user manual that comes with the xVM.

A useful regular expression tutorial

This is one of the most useful regular expression tutorials I have seen in the recent times. The tutorial is not only clear and concise, it just hits what is actually needed to be fully productive.

BTW, the tutorial was written by a high school student!

xVM's vboxmanage.exe command

You can view and edit the configuration of your guest OSs using the vboxmanage command. To view the list of guest OSs you have, give the following command:
C:\Program Files\Sun\xVM VirtualBox>VBoxManage.exe list vms
VirtualBox Command Line Management Interface Version 2.2.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

"MySolaris" {dc6dc85f-5583-4a1b-bf3e-969941a2cd91}
"Ubuntu" {eb973bbf-d86e-4579-85eb-6ea2cd12bf95}
"Debian" {3e784597-89d8-4f17-90cb-63e866c651a3}
"openSUSE" {6862884e-60e1-4c65-8aab-b57ec38a3922}
"Debian-Lenny" {4b561432-abac-4a27-a501-b42af956b96b}

To view the specific guest, you can use the UUID of the guest. For e.g.
C:\Program Files\Sun\xVM VirtualBox>VBoxManage.exe showvminfo eb973bbf-d86e-4579-85eb-6ea2cd12bf95
VirtualBox Command Line Management Interface Version 2.2.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Name: Ubuntu
Guest OS: Ubuntu
UUID: eb973bbf-d86e-4579-85eb-6ea2cd12bf95
Config file: C:\Documents and Settings\roy\.VirtualBox\Machines\Ubuntu\Ubuntu.xml
Memory size: 512MB
VRAM size: 12MB
Boot menu mode: message and menu
ACPI: on

Remember a couple of things:
1) If you would like to view the guest OS by giving its alias, it is case sensitive. For e.g.
C:\Program Files\Sun\xVM VirtualBox>VBoxManage.exe showvminfo ubuntu
VirtualBox Command Line Management Interface Version 2.2.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

ERROR: Could not find a registered machine named 'ubuntu'
Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBox, interface IVirtualBox, callee IUnknown
Context: "FindMachine (Bstr(VMNameOrUuid), machine.asOutParam())" at line 1921 of file VBoxManageInfo.cpp
But the same command worked fine when I gave "Ubuntu" (without quotes) as argument.

2) If you would like to specify UUID, rememeber not to include curly braces ("{}") .

To know all the available options, you can just give the vboxmanage command. That will list you all the available operations.

Wednesday, May 06, 2009

Installing matplotlib - the hard way

I recently installed matplotlib from the source. It was quite an experience that I thought I would share my experience so that others don't have to waste time searching how to do that. So here it is!

What is matplotlib?
Matplotlib is a libarary to plot figures from your Python program. It has much more features than just plotting. You can read more about that from the library's home page.

If you are planning to install matplotlib on Linux everything from the source by building everything yourself, this guide is for you. Please read on.

You will have to install the dependencies first before you can install matplotlib. Matplotlib depends on numpy, zlib, libpng and FreeType libraries. You can get the full dependency list (including the optional dependent libraries) from here. Let us see how to install each one of these components.

Phase 1: Installing numpy
Numpy requires the same Fortran compiler that was used to build blas. There are two flavors of Fortran compilers possible: f77 or gfortran. Unfortunately, these two are not ABI compatible, hence make sure you identify which version you are looking for. It is easy to identify the Fortran compiler used by using ldd on the blas library:

roy@roy-debian:~$ ldd /usr/lib/libblas.so.3gf
linux-gate.so.1 => (0xb7f51000)
libgfortran.so.3 => /usr/lib/libgfortran.so.3 (0xb7e09000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb7de3000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7dd5000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7c7a000)
/lib/ld-linux.so.2 (0xb7f52000)

Hence in my case I know that it is gfortran that I should be making use of. Install gfortran, by following the steps below:
aptitude search gfortran
sudo apt-get install gfortran-multilib

Then download the Numpy from here. Once you have downloaded, untar the tar file and follow the steps below:
roy@roy-debian:~/Desktop$ tar xvfz numpy-1.3.0.tar.gz
roy@roy-debian:~/Desktop$ cd numpy-1.3.0/
roy@roy-debian:~/Desktop/numpy-1.3.0$ python setup.py build --fcompiler=gnu95
roy@roy-debian:~/Desktop/numpy-1.3.0$ sudo python setup.py install

Once you are done with compiling and installing numpy module, you come out of the numpy-1.3.0 directory and check if everything is okay:
roy@roy-debian:~/Desktop/numpy-1.3.0$ cd ..
roy@roy-debian:~/Desktop$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.version.version

Phase 2: Installing zlib and libpng
You can downlod the zlib from here. This is required for libpng. Once you download the zlib, do the following:
roy@roy-debian:~/Desktop$ tar xvfz zlib-1.2.3.tar.gz
roy@roy-debian:~/Desktop$ cd zlib-1.2.3/
roy@roy-debian:~/Desktop/zlib-1.2.3$ ./configure
roy@roy-debian:~/Desktop/zlib-1.2.3$ make test
roy@roy-debian:~/Desktop/zlib-1.2.3$ sudo make install

Once this is done, you are ready to install libpng. You can download libpng from here. Once you have downloaded, follow similar instructions:
roy@roy-debian:~/Desktop$ tar xvfz libpng-1.2.35.tar.gz
roy@roy-debian:~/Desktop$ cd libpng-1.2.35/
roy@roy-debian:~/Desktop/libpng-1.2.35$ ./configure
roy@roy-debian:~/Desktop/libpng-1.2.35$ make check
roy@roy-debian:~/Desktop/libpng-1.2.35$ sudo make install

Phase 3: Installing FreeType library
You can download FreeType library from here. Then follow the instructions below:
roy@roy-debian:~/Desktop$ tar xvfz freetype-2.3.9.tar.gz
roy@roy-debian:~/Desktop$ cd freetype-2.3.9/
roy@roy-debian:~/Desktop/freetype-2.3.9$ ./configure
roy@roy-debian:~/Desktop/freetype-2.3.9$ make
roy@roy-debian:~/Desktop/freetype-2.3.9$ sudo make install

Final phase: Installing matplotlib
Oooh ... Now we come the final phase of our installation. Yes, we are actually going to install matplotlib.

You can download the matplotlib from here. Once you have downloaded the tar file, follow the instructions below:
roy@roy-debian:~/Desktop$ tar xvfz matplotlib-
roy@roy-debian:~/Desktop$ cd matplotlib-
roy@roy-debian:~/Desktop/matplotlib-$ python setup.py build
roy@roy-debian:~/Desktop/matplotlib-$ sudo python setup.py install

Testing the installation
Well, that was quite a long process. Now let us check if everything went well.

roy@roy-debian:~/Desktop$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.use('Agg')
>>> import matplotlib.pyplot as plt
>>> plt.plot(range(10))
>>> plt.savefig('myfig')
>>> exit()

'Agg' backend saves the file in the png format. (Remember we installed the libpng not long time ago!) To know more about back ends, please refer here. Once you come out of Python shell, you can view myfig.png by giving the following command:
gimp myfig.png

For some reason, if you don't have gimp installed, you can make use of firefox or iceweasel to view the png file file.

Friday, May 01, 2009

Paper on garbage-first (G1) garbage collector

This is the paper on garbage-first (G1) garbage collector. It is an interesting read.

A better way of printing heap usage in Java

If you rely on getting the heap usage by methods provided in Runtime, then consider making use of the MemoryPoolMXBeans. The code to print the memory usage is extremely simple:
List mpool = ManagementFactory.getMemoryPoolMXBeans();
for(MemoryPoolMXBean b:mpool) {
System.out.println(b.getName() + ": " + b.getUsage());
You will see something like this when you run this:
Code Cache: init = 163840(160K) used = 468672(457K) committed = 491520(480K) max = 33554432(32768K)
Eden Space: init = 917504(896K) used = 202792(198K) committed = 917504(896K) max = 4194304(4096K)
Survivor Space: init = 65536(64K) used = 0(0K) committed = 65536(64K) max = 458752(448K)
Tenured Gen: init = 4194304(4096K) used = 0(0K) committed = 4194304(4096K) max = 61997056(60544K)
Perm Gen: init = 12582912(12288K) used = 108360(105K) committed = 12582912(12288K) max = 67108864(65536K)
Perm Gen [shared-ro]: init = 8388608(8192K) used = 6162160(6017K) committed = 8388608(8192K) max = 8388608(8192K)
Perm Gen [shared-rw]: init = 12582912(12288K) used = 7282024(7111K) committed = 12582912(12288K) max = 12582912(12288K)
This is a lot more informative than the information provided by the Runtime. This works only in versions 1.5 or later.

SublimeText 3/Anaconda error

When I installed Anaconda manually by downloading and untarring the file (as given in the manual installation instructions here ), I got th...