HOWTO: Parse URLs using Javascript to extract GET variables and more

Most server side languages have inbuilt capabillity of reading GET variables passed via the URL.

But in two (or more) cases, we may need to read these variabes on the client side using javascript. This might be when:

  • You need to find out what the server did/will do on recipt of a particular URL (usually the one on which you currently are)
  • You are building a dynamic AJAX based website, and you are making dynamically loaded content linkable using # in the URL (example: http://jrharshath.com/blog#Article?articleid=12345).

I am currently building an AJAX based application on jswaf and it faces second problem, so I wrote a script for this express purpose: to parse URL like strings into BaseURL and key-value paired parameters.

The code is located here, and a demo is located here.

The code is free to borrow. Just provide credits if you do, and drop me a line if you like it, or would like to learn how to use it.

HOWTO: Make Karaoke on your Ubuntu Box!

Update: If you enjoy Karaoke, you might want to try http://thesimsonstage.ea.com/. I tried it out once, and simply loved it.

Last week I searched the internet for a way to “make” karaoke – strip out the vocals from my songs.
This way, I get songs without the vocals – only instrumentals – so I can sing along instead of the real singer. Turns out this is called karaoke 🙂

So, my hunt led me to two things:

PyKaraoke (#fail)

This is a software that can be installed with a simple “sudo apt-get install pykaraoke“. But, this somehow did not do what it is supposed to do. 😦
So I figured out a new way to do this (after a LOT of googling).

Mplayer, your friend (#yay)

So here’s a DIY for how-to-make-your-own-karaoke:

1. Install the required software

You need mplayer and lame encoder. Installation is pretty simple: sudo apt-get install mplayer lame shntool

2. Remove the vocals from the song

Here’s how to do that: mplayer -ao pcm:file=<output file> -af karaoke <input file (song)>
This command will (try to) strip the vocals from the input song (audio, video, whatever) and will dump the output as “PCM Wav” encoded audio. Relax, this just means that the output song is NOT in mp3 format. And its size is huge.

3. Convert the wav output to mp3

Here’s how: lame -V2 <input wav file> <output mp3 file>
Make sure that there are no spaces in the file names during this “lame” operation. (I don’t know what happens if there are).

So far, so good.

And here’s the catch: not all songs respond equally well to this “procedure”. Some pointers:

  1. This procedure is meant to “attenuate” the voice, not remove it, like, completely. (#ref: http://www.linuxjournal.com/article/9787)
  2. Songs with male voice repond better than ones with female voice.
  3. Sometimes, drum beats are also badly attenuated along with the vocals. In any case, the “boom” of the beat gets killed.

So much for being a killjoy. But all said and done, I still use this method. It works on some songs, and it doesn’t on others.

Q: So what do you do if this method doesn’t work?

A: Search for a better method, and if you find it, post it in here!

HOW TO: Install Nvidia Graphics Card Driver on Ubuntu Intrepid

I’ve seen many methods on how to install the driver for Nvidia graphics card.
Here’s a method that is almost foolproof, involves no conf file editing, and can be done purely using apt-get package manager.

In case you are wondering, this method installs the “177” driver (the one that is supposed to be “recommended”).

So here goes:

  1. “sudo apt-get install nvidia-177-kernel-source nvidia-glx-177 nvidia-kernel-common nvidia-settings xserver-xorg-video-nv”
  2. Open System > Administration > Hardware Drivers
  3. Select the driver that says “Nvidia accelerated graphics driver 177 [recommended]”
  4. Click the Activate button (at the bottom of the window).
  5. You’re done!

After it completes successfully, you will need to restart your computer. And viola! Your graphics card is ready to use!

HOW TO: Guest OS Networking in VirtualBox

I am an ubuntu user and I am a web developer. So what do I do when I need to test web applications on IE6 or IE7? I don’t go to some other computer running windows. I run windows in a virtual machine using Virtualbox.

The only hurdle is: how to reach the host OS network from the guest OS network? I scoured the internet for solutions, and I found one that did it in the first go: so here it is.

Now my life is easier. I don’t trouble my friends by asking them to lend me some of their time. I don’t need to interrupt their counter strike or WoW game. I do it on Virtualbox!

BTW, there is this project called ies4linux – a software to install ie 5, 6 and 7 on linux using wine. I tried it, but it somehow didn’t hit the sweet spot. For those of you who want to try, find it here.

How to Make Amarok Work with MySQL

I promised earlier to show you how to make amarok work with MySQL. So here’s how.

  1. Install Amarok: This step is pretty simple. Just “sudo apt-get install amarok“. If you are using GNOME, then kde libraries will also be installed automatically. So it may take a bit longer.
  2. Install MySQL Server: This is easy too: “sudo apt-get install msyql-server“. During the installation, you will be asked for a “root password”. This is different from from your Ubuntu’s “root” account: this is a mysql user called root.
  3. Create a amarok user in Mysql:
    • Log into mysql as root: Type one the terminal “mysql -u root -p“. The “-u root” tells mysql that you want to log in as root, and “-p” says that you have a password that you want to supply. So you will be prompted with a password. Enter the one you supplied during mysql installation.
    • Create an amarok database: Once you have logged into mysql, you will have a mysql prompt (“mysql >”). To create the database, simply type “create database amarok;“. Yes, you need to terminate the command with a semi-colon. This creates a database named “amarok” (No prizes for guessing that).
    • Create amarok user: Now to create the user, type “grant all privileges to ‘amarok-user’@’localhost’ on amarok.* identified by ‘amarok-password’ with grant option;” This command will create a user in mysql with username “amarok-user” and password “amarok-password”.
  4. Tell Amarok how to talk to mysql: You can do this at two places –
    • In the First-Run wizard: Here, you will be asked to select the directories to include in “The Collection”, and how to store the collection. In the How, select “MySQL”. Fill out the “host” as ‘localhost’, port as ‘3306’ (this should be correct in 99.99% cases). Fill in database = amarok, username = amarok-user, and password = amarok-password. Note that these paramaters are the ones that you supplied in step 3.
    • Later on: Go to Settings > Configure Amarok > Collection tab. Set the folder(s) you want to monitor first. Then select the “database” as “MySQL”. In the configuration, enter host = localhost, port = 3306, database = amarok, username = amarok-user and password = amarok-password.

Ta-da! Its done!! Now Amarok will take some time to build your collection, and then you’ll be ready to rock and roll!