Category Archives: Tips

Django Settings When Using Gmail As Mail Server

Remember my post entitled “CodeIgniter Email Preferences When Using Gmail As Mail Server“? Here is the Django version.

EMAIL_PORT = '587'
EMAIL_SUBJECT_PREFIX = '' # The default is [Django] so you may want to replace it.

Again, make sure to replace username with your real username and password with your real password.

Easy PDF Generation

Most web applications require some form of PDF generation for reports and other uses. These can already be done by many PDF libraries out there searchable by your favorite search engine. However, sometimes, a report has a certain format that it takes time and effort to create its template either by drawing it manually using a PDF library or creating a HTML/CSS file which will be converted later on.

In one of my projects, I need a report with lots of table cells. Creating a template using either one of the options I mentioned earlier is time consuming for me. I’m sure there are techniques to speed them up that I haven’t looked up yet but below is the one that I have found to be the easiest.

Since I need a lot of table cells, just use a spreadsheet application. It is easy to create a different sizes of rows and columns there. Formatting is also easy. One thing to look out for is the total width of all your cells. Make sure that the width fit in your target paper size.

Then, open the spreadsheet in your web application and fill it with your data. It is easy to put data there because you can specify the cell just by its row and column numbers. Just like PDF libraries, there are spreadsheet libraries out there. Choose the one you like the most.

Now that you have a spreadsheet with all the report data, convert it to PDF using the following command:

$ /usr/bin/libreoffice --headless --convert-to pdf --outdir <output folder> <spreadsheet file>

You now have a generated PDF! Note that you need to install LibreOffice for this. Also, you have to call a command outside of your application. You need to factor these before using this technique.

Out of the Park Baseball 13 on (K)Ubuntu 12.04 LTS 64-bit

I’ve been wanting to try the full version of Out of the Park Baseball ever since I tried its demo early this year. And since they have a special offer because of the MLB All-Star Game that reduces the price from $39.99 to $29.99, I decided it’s time.

So I bought 2 licenses and downloaded the installer. Here’s what I did to make it work.

First, let’s extract the installer and run the executable.

$ ./OOTP\ 13\ Installer 
bash: ./OOTP 13 Installer: No such file or directory

The error is caused by my distro being 64-bit since OOTP is 32-bit. So let’s see what libraries OOTP needed.

$ readelf -d OOTP\ 13\ Installer

Dynamic section at offset 0x1d32bc contains 31 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []
 0x00000001 (NEEDED)                     Shared library: []

After finding out the needed libraries, let’s look for their respective packages at Ubuntu Packages Search.

  • – libxpm4
  • – libgl1-mesa-glx
  • – libx11-6
  • – libstdc++6
  • – libxext6
  • – zlib1g
  • – libxxf86vm1
  • – libc6
  • – libasound2
  • – libgcc1
  • – libc6
  • – libc6

Then, we install the resulting packages. We need to append :i386 to the package name since we are installing the 32-bit version.

$ sudo apt-get install libxpm4:i386 libgl1-mesa-glx:i386 libx11-6:i386 libstdc++6:i386 libxext6:i386 zlib1g:i386 libxxf86vm1:i386 libc6:i386 libasound2:i386 libgcc1:i386

The installer should now run. After the installation, we can now run OOTP.

$ ./ 
ALSA lib conf.c:3314:(snd_config_hooks_call) Cannot open shared library
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default

But what’s this? OOTP can’t open a library. So we do what we did earlier and install the missing library.

$ sudo apt-get install libasound2-plugins:i386

OOTP should now run fine. Enjoy!

Formatting an External Hard Disk with Ext4

Recently, I bought an external hard disk formatted with NTFS. Not that there is something really wrong with NTFS but I prefer using ext4.

First, I deleted the existing partition and created a new Linux partition using fdisk:

# fdisk /dev/sdb

Assuming /dev/sdb is the external hard disk. Use d to delete the partition and use n to create a new partition. 83 is the ID of the native Linux partition.

Them, I use mkfs.ext4 to format the partition with ext4:

# mkfs.ext4 /dev/sdb1

Note that mkfs.ext4 expects a partition as its argument.

Finally, I use tune2fs to adjust some parameters:

# tune2fs -m 0 /dev/sdb1 
# tune2fs -L bakap01 /dev/sdb1

The -m option is for adjusting the percentage of reserved blocks. The reserved blocks are used by privileged processes which is by default 5% of the hard disk size. Since I’m using the external hard disk solely as a storage, I set this to 0 so I can also use those 5% for storage. The -L option is for labeling the filesystem.

Adding an Ubuntu Repository Key Behind a Firewall

When you want to add an Ubuntu PPA repository using add-apt-repository and you’re behind a firewall. more often than not, you will receive a nasty error saying “Error reading <some PPA URL here>: <urlopen error [Errno 111] Connection refused>“. And when you tried to install something, you will get a GPG warning.

What happened is that add-apt-repository failed to download the keys of the PPA repo because the PPA key server uses 11371 as its port which is usually blocked when you’re behind a firewall. To solve this, you need to find the PPA repo key manually. For example, the key in is 8C6C1EFD. It can be found under the “Signing key” when you click “Technical details about this PPA”. Only the numbers and letters after the slash are considered.

After finding the key of the PPA repo, just execute this command:

$ sudo apt-key adv --keyserver hkp:// --recv-keys <the key here>

You will not be bothered again by a GPG warning when installing from the PPA repo. This is tested using Ubuntu 10.04 (Lucid Lynx).

Enabling Nvidia Legacy Driver on Ubuntu 10.10

The release of X.Org Server 1.9 brought upon an incompatibility issue with the legacy driver of Nvidia (nvidia-96 package in Ubuntu) resulting in a non-working driver which forces users to use the nv or the nouveau driver. While the mentioned two drivers do work, 3D support is not good. Fortunately (unfortunately?), the legacy driver has now been updated.

To enable the legacy driver on Ubuntu 10.10 (Maverick Meerkat), add the maverick-proposed repository in /etc/apt/sources.list:

deb maverick-proposed restricted main multiverse universe

Then, update the package listing:

$ sudo apt-get update

Then, install the driver by going to System->Administration->Additional Drivers.

Reboot and enjoy.

Converting WAV to MP3 using LAME

If you have a bunch of .wav files, say from ripping a CD, and want to convert it to .mp3, here is a simple way to do it using LAME.

$ for i in *.wav; do basename=`basename "$i" .wav`; `lame --preset insane "$i" "$basename".mp3`; done

Inside the for loop that iterates through all .wav files, we execute two commands. First is the “basename” command which let us extract the file name minus its extension. For example, “Track 01.wav” will become “Track 01″. We will use this in the output file name of LAME. The second command is “lame” which does the converting from .wav too .mp3. We set the preset option to insane. Other options can be found by running “lame –preset help” in the command line. The first parameter is just the .wav file name given by “$i” and the second parameter is the extracted file name from the “basename” command earlier appended by “.mp3″ since the output file we are expecting is a .mp3 file.

That’s it. Run the command, wait, and enjoy.

Creating PostgreSQL Database with a Different Encoding

To create a database in PostgreSQL with a different encoding, let’s try doing this:


But an error will occur.

ERROR:  encoding LATIN9 does not match locale en_PH.utf8
DETAIL:  The chosen LC_CTYPE setting requires encoding UTF8.

So let’s try creating with a template. By default, the template used in creating database is template1. Let’s try template0 instead.


But the same error as last time happened.

Let’s try adding more options like LC_COLLATE and LC_CTYPE. The values for these two options can be derived by doing this in the terminal.

$ locale -a

Here are the results.


Let’s try C since en_XX.utf8 gives us the error.


And yes, the database is successfully created. Yay!

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding | Collation  |   Ctype    |   Access privileges   
 db        | postgres | LATIN9   | C          | C          | 
 postgres  | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 | 
 template0 | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 | =c/postgres
                                                           : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 | =c/postgres
                                                           : postgres=CTc/postgres
 test      | postgres | UTF8     | en_PH.utf8 | en_PH.utf8 | 
(5 rows)

This is tested on Ubuntu 10.04 (Lucid Lynx).

Installing Sun … Oracle Java on Ubuntu 10.04

To install Sun … Oracle Java on Ubuntu 10.04, simply uncomment the following lines from /etc/apt/sources.list.

#deb lucid partner
#deb-src lucid partner

Then do a sudo apt-get update and sudo apt-get install sun-java6-jdk and you’re ready to go.

In previous versions of Ubuntu, Sun … Oracle Java is in the multiverse repository, I think. So this can confuse borap people like me.