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:
nolirc=yes
nojoystick=yes

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:

test-app
  -- .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

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

Output of hg clone:

test-app
  -- .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).

Python Scraping: Scrapy and BeautifulSoup

When I search for solutions to my problems, I often search the internet for “compare and contrast” or analytical posts on the best tools for the job, which in turn help me make an informed decision.

Recently, my problem was scraping a website for data using python. I searched online and a lot of users recommended Scrapy over BeautifulSoup. Well, that was easy, I naively said. Scrapy probably is the better option for most people (it supports XPath right out the box). Like Scrapy’s docs put it:

comparing BeautifulSoup (or lxml) to Scrapy is like comparing jinja2 to Django.

But Scrapy didn’t settle well with my Cent OS platform (or Google Apps Engine). For one, there were a whole lot of problems trying to install Scrapy in my virtualenv (safe python environment system) because of it’s dependency on libxml2/libxslt and their bindings. Examples:


etree.so "undefined symbol: libiconv"
Version 2.6.26 found. You need at least libxml2 2.6.27 for this version of libxslt
ImportError: /pyenv/test/lib/python2.6/site-packages/libxml2mod.so: undefined symbol: xmlTextReaderSetup
No module named libxml2
Failed to find headers. "update includes_dir"

Note: This may look overly dramatic. And it maybe is a little dramatic, because a lot of these errors/problems do have solutions. Most of them can be searched out of Google results.

I endlessly chased solutions at trying to integrate libxml2, libxml2 python bindings, libxslt and lxml in a virtualenv (with python 2.6; note Cent OS/RHEL only have python2.4 in their repositories). I eventually grew tired of trying to find what is linking to what shared library and what seems to be the missing culprit. And I figured, let me just give BeautifulSoup a try. I thought I’d spend the extra time learning the library that BeautifulSoup is, as opposed to learning the “framework” that Scrapy is.

In the end, BeautifulSoup was not that hard. It may be missing XPath support in its default setup, but I could easily implement the XPaths that I had with ones using BeautifulSoup syntax.

Lesson: Don’t let your ego get into it. Save time by going for fairly-efficient solutions that can be implemented in fairly-optimal time (as my Algorithms professor used to say).

Convert Django MySQL Database Tables to Unicode

When I created a Django application, I hadn’t noticed that my MySQL was defaulted to latin character set (probably by Virtualmin or CentOS’s default MySQL values). So I didn’t want to delete my current project and start again. So here are the commands to convert a database to unicode:

for the database

ALTER DATABASE djangodb CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

on each table do

ALTER TABLE djangotablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

UnicodeDecodeError (unexpected code byte) on a template

Started receiving this error after I pasted some template code from a WordPress blog (it could also happen from any word processing product like Microsoft Office’s MS Word). The solution to this problem was that I had to look through my code to hunt down the following characters and replace them with their equivalents:
” ‘ ’
Replaced with (respectively):
" ' '

Django: “Error importing authentication backend”

This is probably a very rare error that one may encounter in Django. But I think I should share it here, as it would save about an hour of anybody else who has this problem.

Problem
Exception Type: ImproperlyConfigured at /
Error importing authentication backend

Probable Cause
I was very desparate to change the name of an app inside my Django project. I renamed the folder name and all possible mentions of the application name anywhere in the code and the database tables (Please note: This is not recommended, there is probably a better solution to do this). Once I faced that problem with no clear indication of where I was going wrong, I looked everywhere in the code and the database. After going into panic mode, I tried desperately changing and removing anything that may break. In the end, I ran out of places to find the application name but the error still existed.

Solution
I had noticed after looking at my cookies that I still had cookies from my session, which meant that everytime I connected to the server, I was trying to pass my “delicious” cookies. But just deleting your own cookies won’t do it. The session object of the user was cached in the database inside the table “django_session”. This especially stores the “AUTHENTICATION_BACKENDS” last used. So, truncate the table: TRUNCATE TABLE django_session to finally get rid of this nasty problem.

DholCutz Bhangra Radio Android App v1

DholCutz Bhangra Radio Android App is out now! Get it from the Android Market.

The Story: I had planned to do a DholCutz Bhangra Radio app about 4-5 months ago, but I never got the time to do it because my initial plans were to do one big app. Apparently, the demand of the app was too much that I just let it go and programmed a quick version for now. The Android Market approval process (1 day) is the best, light years better than iPhone App Store (3 weeks).

The App: I decided to price this app for $1 USD, which might change when I release a much much better version of this app that allows requesting songs from inside the app. Until now, this will do for the punjabi music fans. The app plays music from the radio and shows the current playing song.

The Screenshots:

Thank you.