Archive for October, 2010

Punjabi Chat iPhone app version 1

I have been running for over three years. At times, it has grown as a community and at times, it has shrunk in size. I rarely get time to work on the features of the website, so I felt like I owed the site something special, something the other Punjabi social networking websites lacked.

One of the most widely used features of Punjabi Janta is the PJ Chat. It has been the focus point of Punjabi Janta from the start. In fact I would go so far as to argue that it has been the cornerstone of PJ. So to propel that cornerstone, I have developed the Punjabi Chat iPhone app, which requires a PJ account to work.


  • Chat with users of PJ and on iPhone
  • Private message users
  • Smileys
  • Status: Away, BRB, Busy, Online
  • Rooms


PS: You must have a activated (email authenticated) account on PJ for it to work. Please sign up now at

Nginx with m4a/aac/mp4 seek support on CentOS 5

I was working on Sikh Sangeet website which serves a lot of static audio media files. For the past couple of months, we’ve been paying overage (i.e. bandwidth charges for surpassing limits). I either had the option of paying much more (hundreds) for a better server or keep paying the overage charges (usually less than a hundred). So, I wanted to convert all the listening audio to a smaller format, such that I could provide full quality mp3s for downloading and provide smaller format audio for listening. I ended up choosing H264′s aac-HE, because it is supported in flash, android and iphone.

Previously on our dedicated Sikh Sangeet server, I ran nginx because the server was very limited with hardware, yet needed to serve the huge files that were mp3s. I had the latest nginx rpm (0.6.39-5.el5) from epel setup, but to get mp4 support, I had to install nginx from source with mp4 support.

I will reproduce the steps in the hopes that if I or anybody needs to do this in the future, they can get a quick idea:

Install nero encoders (best encoders for aac).
Convert mp3 to wav: mplayer -vc null -vo null "orig_file.mp3" -ao pcm:fast:file="/tmp/out.wav"
Convert wav to aac/m4a: neroAacEnc -br 56000 -if /tmp/out.wav -of "new_file.m4a"
Tag the m4a file with proper info: neroAacTag "new_file.m4a" -meta:title="title" -meta:artist="artist" -meta:track="track" -meta:album="album" -meta:genre="genre"

Now we have a m4a (aac) file, but this file is still not interleaved like an mp4 should be for nginx to stream parts of it. We must now convert the m4a (aac) file to mp4.

Install MP4Box (best way to convert regular audio into mp4 containers).
Convert m4a to mp4: MP4Box -add new_file.m4a:sbr final_file.mp4

Now we have our audio part ready. Now we just need to setup nginx:
Use the compile/make instructions from the original creators of the mp4 streaming module for nginx.


  • If using the latest nginx server, the configure statement will not work. For two reasons:
    1. The nginx source requires pcre, even if you have pcre and pcre-dev(el) packages installed. For some reason nginx ./configure wasn't picking them up, so I downloaded pcre from pcre ftp. And without running make/configure or anything on it, used the following ./configure statement for nginx: ./configure --add-module=$HOME/nginx_mod_h264_streaming-2.2.7 --sbin-path=/usr/local/sbin --with-debug --with-pcre=$HOME/pcre-8.10
    2. The nginx_mod_h264_streaming-2.2.7 module has an incompatibility with the latest nginx (confirmed with 0.8.53):
      nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: ângx_http_request_tâ has no member named âzero_in_uriâ.
      So, you must patch the ngx_http_streaming_module.c file using this patch.
  • For Red Hat/CentOS/Fedora users: If you want to use service nginx start/stop/reload/etc, download this Nginx Init Script.

Once you have nginx ready serving regular files from your document root (public_html, www, etc). Then simply put this directive inside the server context:

location ~ \.mp4$ {
root /your/document/root/full/path/here;

The mp4 line will take care of the final_file.mp4?start=25 variable (i.e. start at 25 seconds) that flash players send to the server and cut off the mp4 at the right place.

Vim’s powerful navigation

I was reading about the Mac OSX Terminal app and somebody complained about vim being slow. A vim programmer shed some light on how to use vim’s amazing keyboard navigation:

Using Vim in, I can easily scroll about 5100 lines in 10 seconds, using ctrl-F or ctrl-B (scroll one page forward or back), if you’re trying to move a long distance in a hurry. I get the same speed in MacVim (which can update the screen much faster than, so I’m pretty certain that the limiting factor (at least in MacVim) is the keyboard repeat rate, not Vim’s ability to update the screen.

The only way I get roughly 120 lines in 10 seconds, is scrolling Vim (or MacVim) line-at-a-time by holding down “j” or the down arrow, and that’s clearly the default keyboard repeat rate (about 12 per second) limiting things.

You can easily adjust the keyboard repeat rate in System Preferences, in the Keyboard pane, by fiddling with “Key Repeat Rate” and “Delay Until Repeat”. But I’ve been using Vi/Vim/MacVim for a loooong time, and have never felt the need to have the keyboard repeat faster; the key (no pun intended) is to use Vim as it was intended…

If you want to move 3 lines down (or up) hit “j” (or “k”) 3 times (much faster than waiting for key repeat to kick in). If you want to move 10 or 20 lines down, then maybe hold down “j” (“k”) and let it repeat. But if you want to go further, that’s the wrong way: ctrl-D (ctrl-U) will take you half a screen Down (Up), ctrl-F (ctrl-B) will take you a full screen Forward/down (Back/up)… holding any of these down will get you somewhere fast. If you’re trying to get to somewhere in particular: “]]” (“[[") will jump forward (backward) to the start of the next (previous) function (in C/Obj-C/Perl/Java/Javascript or any other language where "{" by itself at the start of a line indicates the start of a function), or use "/" ("?") to search for some text and "n" to jump to subsequent occurrences until you reach the right one. Or use tags (see ":help tags"), build a tags file for your code, then you can use ":tag yourfunctionname" to jump to a function definition in any file, or sit on the function's name in a call somewhere and hit ctrl-] to jump to the definition (and ctrl-T to jump back to the call). Or even more lazily, in Vim, if you sit on any identifier and hit “*” (“#”), Vim will select that identifier as search text and take you to the next (previous) occurrence, where you can use “n” to keep searching further — this is more than sufficient in smaller files. And turn on incremental searching and search highlighting (“:set incsearch hlsearch”, worth putting in your ~/.vimrc), then the search results will be more obvious on the screen.

Finally, nearly everything in Vim (and Vi before it) takes a repeat count argument. If what you want is really to jump 179 lines down, then type “179j” (and if you wanted to get to line 423, that’s “423G”). Use the full power of Vim as it was intended, and keyboard repeat rate will never be a limiting factor.

And if you’re using Vim on the Mac extensively, you owe it to yourself to check out MacVim — you can still start it from (an included helper script lets you type “mvim file1 [ file2... ]” at a command line prompt), but it’s much more Mac-like — cut’n’paste and drag’n’drop interact well with other programs, you get real scroll bars (drag those to move through a file really quickly), multiple editing windows, and you can use the mouse for selecting text, along with (practically) unlimited colors for color syntax highlighting (you do use that, right? “:help syntax” or just “:syn on” to switch it on), instead of the 16 colors you’re limited to in And it’s fast.

Vim (and MacVim) is the ultimate programmer’s editor, if you take the time to really learn how to use it — it requires the smallest amount of hand movement to make changes (especially since one never has to reach for the mouse), it’s insanely customizable/programmable, and it has a very smartly laid out command set — yes, it has a steep learning curve, but for something that I use 10 hours a day, I’ll take easy/powerful to use over easy to learn any day.


Source: MacRumors

Titanium Mobile integrating Admob/Smaato with Android on Mac OSX

Titanium doesn’t have Admob/Smaato support, so it is really hard to monetize free applications without using Webview Onclick Trickery (even then you’re not utilizing the full potential of Admob’s seamless integration). Thankfully, David Ashwood has released source code for Admob and Smaato Integration on his (branch). Unfortunately, the instructions in his posts are clear but not working (some only work on Linux), however I’m using Mac OSX for development, so it doesn’t help me much. Although I had learned java jar files are platform independent, but they didn’t work in my project (but that’s topic for another day). So I figured I’ll give a broad overview of how to get it working:

Note: I’m not sure if each of these steps are necessary, but this is the way I went on doing it, so you’re welcome to ignore any step that you feel is redundant. But please do leave a comment specifying it, so in the future other developers may not face the same problems.

  1. Follow Titanium Documention to get Titanium built from source (for practice and setting up paths/classpaths that you need later)
  2. Install Android SDK and Google APIs (if you haven’t already)
  3. Clone dasher’s fork
  4. Checkout the branch
  5. If using scons, edit the android/build.xml file to fix the two paths: android.platform and google.apis. They point to the older way If using Eclipse, you can specify these two CLASSPATH variables: ANDROID_PLATFORM and GOOGLE_APIS (as the Titanium Documentation to build from Source (Step 1) suggests).
  6. Run scons or Eclipse to generate jars. I got a zip archive at the end of the process in distribution folder. (I don’t know if Eclipse does it, because I did it through scons. I would argue the regular eclipse build does it as well.)
  7. Unzip this archive in your Titanium application directory, where the following directory structure exists: mobilesdk/{platform}/{version}. Be careful if replacing files/folders. I created a new directory for the {version}, because if this build doesn’t work for whatever reason, you’ll have an option to fallback on the original Titanium version.

And amazingly, you have Admob support in (the latest version for Mac OSX).

Last tidbit: I noticed that moving these jars are very easy, just be sure to carry the other jars along with you, like the admob-sdk-android.jar and SOMAAndroidSDK.jar. I’m not sure if you need these, but I got rid of some crashes that were happening earlier.

Javascript/JSON: Find Index in an Array of Objects

JSON is one of my favorite data models notation (xml = :(). A lot of times, I get arrays of objects (hash tables) that I then have to search again an again to find the index of the object inside that array. Here’s a quick function to find it:

function findIndexByKeyValue: finds "key" key inside "ob" object that equals "value" value
example: findIndexByKeyValue(students, 'name', "Jim");
object: students = [
   {name: 'John', age: 100, profession: 'Programmer'},
   {name: 'Jim', age: 50, profession: 'Carpenter'}
would find the index of "Jim" and return 1

function findIndexByKeyValue(obj, key, value)
	for (var i = 0; i < obj.length; i++) {
		if (obj[i][key] == value) {
			return i;
	return null;

Mplayer’s useless warnings at startup

Installed an mplayer rpm from RPMForge repository (mplayer.i386 1.0-0.40.svn20090711.el5.rf) to my CentOS 5 server. I was setting up a bash script to decode and encode several media files. Everytime mplayer was called from the script, I would get the following useless warnings:

MPlayer SVN-r29417-4.1.2 (C) 2000-2009 MPlayer Team
Can't open joystick device /dev/input/js0: No such file or directory
Can't init input joystick
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

It was building up my logs. So I put the following two lines in my mplayer configuration file at /etc/mplayer/mplayer.conf:

And like linux magic, the errors on each load disappear.

Import error while building Eclipse Plugin in a Java Project

I was trying to build a Java project I got from somebody using the Eclipse Gallileo install. Since the workspaces were different, my Eclipse install was confused about the eclipse plugins jar files, and it threw the following error:
"The import org.eclipse cannot be resolved"
on line: import org.eclipse.core.runtime.Plugin
and other cryptic errors: "BundleContext cannot be resolved to a type"

I resolved this by adding the appropriate jar library files from my eclipse directory. Here’s how I searched which files I needed.

  1. Go to eclipse plugins: cd eclipsedir/plugins
  2. For each suspecting jar, I do jar -tvf filename.jar | grep "searchingforthisClass"
  3. In the end I found my Plugin class: jar -tvf org.eclipse.core.runtime_3.5.0.v20090525.jar | grep Plugin
  4. Right click on the project in Eclipse, choose Properties, under Libraries tab, click “Add External JARs” button, then just locate that jar that you found above.
  5. Rebuild

PS: This is more of a reference for myself than for other Java developers, because this is probably as basic as it gets.

DholCutz Bhangra Radio iPhone OS App v1

DholCutz Bhangra Radio iOS App is out now! Get it from the Apple App Store.

This is the same application as the Android App for DholCutz Bhangra Radio I blogged about a few days earlier. So check out the screenshots on that page.

Note: The apps were made on the same day, but due to the approval processes for the Android Market and iOS AppStore being vastly different (1 day as opposed to 2 weeks, respectively), they have been published online on different dates.

Mercurial/Bitbucket: How to get a Repository name with a Space

I had iPhone mobile development code on my Mac OSX and I wanted to commit it to an online repository, Bitbucket (just like Git’s GitHub, except it is for the Mercurial DVCS).

So I created a private BitBucket repository with the name “Test App”. Surprisingly, BitBucket renamed my basename to “test-app”. However my folder structure was:

Current Folder Structure:

"Test App" (notice it has spaces)
  -- File 1
  -- File 2

Now I can just as easily clone the “test-app” repository and change my folder structure to this:

Possible Solution’s Folder Structure:

  -- .hg/*
  -- "Test App"
    -- File 1
    -- File 2

But that means I have to change my application file/folder paths. (Although I will note that a sane developer would use relative paths, I unfortunately did not have that option.) Surprisingly, this is not documented in the BitBucket documentation or on any online resource.

Possible solutions I looked at:
- “Hard” Symbolic Links – Unfortunately Mac OSX does not support hard linking to directories.
- Use a script to copy/paste code from “Test App” to test-app, each time I need to check it in – Highly inefficient

I cloned “test-app” to a folder. So I got:

Output of hg clone:

  -- .hg/*

Now I took the .hg directory and just moved it to my “Test App” folder, like this:

Final Folder structure:

"Test App"
  -- .hg/*
  -- File 1
  -- File 2

Thankfully, there are no problems with hg commands. Apparently, the Mercurial coders are not hardcoding paths. :)

Upgrading WPMU 2.x to WordPress 3.0: Multisite Problems

When upgrading WordPress MU installation to a WordPress 3 multisite installation, I faced a lot of “Internal Server Error” problems, such as:

Premature end of script headers: *.php
an error occurred while processing this directive

A lot of people suggested disabling plugins before, or even removing them all from the /wp-content/plugins/ folder. But one crucial detail was missing from most of these suggestions. WPMU keeps a special set plugins for itself in the folder /wp-content/mu-plugins/. It is very important to disable these, because chances are these are the most “incompatible” plugins that you have (because they are not updated like the regular WordPress plugins).

Return top