March 31, 2009

Google Ventures: Is it Google's April Fools Day Prank?

Today is 1st April, and Google launched Google Venture. It might be a possible Google Prank that Google plays every year on 1st April.

The reason being, doing such a thing close to 1st April with such an interesting topic, Google might be playing big with people.

I'm not sure though :-) and might be wrong. Let's wait and see, what happens.

Update: Some more possible google pranks this year are


February 13, 2009

Killer Text Parsing using Javascript

This Codeocolate (Code + Chocolate = Codeocolate ), presents a killer text parsing javascript. Our killer javascript does the following 7 tasks while parsing the text:

  1. Grab the text to parse
  2. Converts everything to lowercase
  3. Remove numbers
  4. Remove special characters
  5. Sorts words alphabetically
  6. Removes duplicates
  7. Prints sorted word list with a single word on each line

Let's consider each of the 7 task one by one:

Grabbing the text to parse: 

var textToParse = new String(form.textToParse.value);


form.textToParse.value is the text contained in HTML textarea control, that needs to be parsed.

new String(form.textToParse.value) creates a string using form.textToParse.value and assigns it to a variable textToParse.

Converting everything to lowercase: 

textToParse = textToParse.toLowerCase();


textToParse.toLowerCase() returns a string with all lowercase characters.

Removing numbers and special characters: 

var regex = /[`~!@#$%^&*()_+={}|:";'<>,.?0-9]+/g;

textToParse = textToParse.replace(regex, "");


First, a regex representing all the special characters and numbers is defined. Then, all the special characters and numbers are removed from the string.

Splitting the string into of individual words

regex = /\s+/;

var arr = textToParse.split(regex);


First, a regex representing one or more space is defined. Then, using regex we split the string into an array of words and store inside arr.

Removing duplicates

for ( i = 0 ; i < arr.length-1 ; i++ )
    for ( j = i + 1 ; j < arr.length ; j++ )
        if ( arr[i] == arr[j] )
            arr[j] = '';

Converting array back to string

var killerOutput = new String();
killerOutput = arr.toString();

Putting each word on its own line

var regex = /[,]+/g;
killerOutput = killerOutput.replace(regex,"\n");


Using regex we insert a newline character ('\n') after each word.

Printing the Killer Output! 

form.killerOutput.value = killerOutput;


Setting the text of form.killerOutput HTML textarea to killerOutput string.

The source for the above Codeocolate can be downloaded from here.

Hope, you found this killer Codeocolate useful. Cheers.

The Amazing 1234567890 Moment

Time is among those things in the universe that never stops. On Friday, Feb 13 at exactly 3:31:30 PM Pacific Standard Time the Unix Time will equal 1234567890.

For Indians, this amazing moment will  come on an amazing day, The Valentines Day i.e. Feb 14, at 5:01:30 AM Indian Standard Time.

The moment will work like an additive in the love enriched environment of Valentines Day, with the Unix lovers and fans joining too in the celebration.

By the way, for folks who do not know what Unix Time is, it is the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970.

January 16, 2009

Introduction to Web-Caching

The revolution in Internet and World Wide Web began with the introduction of Server Side web development platform. This new platform made the web dynamic. The web pages can now be generated on-the-fly based upon request parameters.

The above said is very well supported with the success of Content Management Systems like Wordpress, Drupal and Joomla.

But the dynamic generation of content made the sites with large user base slow, because generating a single web page requires a number of database transactions like retrieving site settings, current user details, etc. The content was dynamically generated on every user request. This increased load on web-servers and created a lag in the fulfilment of user requests.

When web developers started exploring the solution for the above problem they found that the web pages do not change often and regenerating the same unchanged web page was sheer wastage of web-server resources. So, they came up with the concept of Web-Cache.

Web cache stores copies of documents passing through it and subsequent requests can be satisfied from the cache until the cache time expires and after time expires the page is regenerated. Hence, Web-Cache was able to reduce the load on server.

The following algorithm will provide a deeper insight on working of a simple Web-Cache:

for a requested URL, try finding that page in Web-Cache
if the page is present in the Web-Cache:
return the cached page (i.e. do not regenerate the page)
generate the page
save the generated page in the Web-Cache
return the generated page

The above algorithm can be used to implement a basic Web-Cache. But, to make caching more effective and robust, more complex algorithms are developed.

In this series of articlowers we will discuss how popular Content Management Systems and frameworks implement Web-Caching. So, stay tuned for more.

January 1, 2009

Happy New Year

I'd like to wish all CodeBasket readers a Happy New Year. Gone 2008 and here comes 2009, lets fill the CodeBasket with more codeocolates, articlowers, and tutoruits

December 29, 2008

Connecting to the Internet on Ubuntu Linux using GPRS, Bluetooth enabled mobile

Mobile phones can act as a gateway between our computer and the Internet. In this post I will discuss how to connect your computer(with Ubuntu 8.10 Interpid Ibex as operating system) to the Internet using a mobile phone(Nokia, Sony Ericsson, Treo etc.) with Bluetooth and GPRS functionality.

To make the connection, we first need to setup a link between mobile phone and Ubuntu system. Steps:

Discovering the mobile phone
will use hcitool utility to discover the mobile phone. First of all, TURN ON the bluetooth on both mobile phone and computer. Then launch the Terminal from Applications->Accessories->Terminal. Now type the following:

mohit@mohit-laptop:~$ hcitool scan
Scanning ...
00:16:BC:F4:6E:EF mNokia

Note down the address of your mobile, in my case it was 00:16:BC:F4:6E:EF.

Adding the mobile device to /etc/bluetooth/rfcomm.conf
We will now add an entry for our mobile phone in /etc/bluetooth/rfcomm.conf. Open the rfcomm.conf using the command given below.

mohit@mohit-laptop:~$ sudo vim /etc/bluetooth/rfcomm.conf

Now, we have to specify our mobile phone's address ( which we found in the previous step using hcitool scan)
My rfcomm.conf looks like this:

rfcomm0 {
bind yes;
# Bluetooth address of the device
device 00:16:BC:F4:6E:EF
# RFCOMM channel for the connection
channel 1;
# Description of the connection
comment "Nokia";


Making the connection
Use the command sudo rfcomm bind rfcomm0 to make the connection. Now we have a modem on /dev/rfcomm0

Creating some PPP Scripts
First of all we will create a chatscript
/etc/chatscripts/BluetoothPhone. Here APN should be replaced with the Access Point Name that the service provider uses. In my case it is "".

SAY 'Starting GPRS connect script\\n'

# Get the modem's attention and reset it.
"" 'ATZ'

# E0=No echo, V1=English result codes

# Set Access Point Name (APN)
SAY 'Setting APN\\n'

# Dial the number
SAY 'Dialing...\\n'
OK 'ATD*99***1#'

Second, we have to create /

""      "\\K"
"" "+++ATH0"
SAY "GPRS disconnected."

Finally, we have to create /etc/ppp/peers/BluetoothPhone

/dev/rfcomm0 # Bluetooth modem
115200 # speed
defaultroute # use the cellular network for the default route
usepeerdns # use the DNS servers from the remote network
nodetach # keep pppd in the foreground
crtscts # hardware flow control
lock # lock the serial port
noauth # don't expect the modem to authenticate itself
local # don't use Carrier Detect or Data Terminal Ready

# Use the next two lines if you receive the dreaded messages:
# No response to n echo-requests
# Serial link appears to be disconnected.
# Connection terminated.
lcp-echo-failure 4
lcp-echo-interval 65535

connect "/usr/sbin/chat -V -f /etc/chatscripts/BluetoothPhone"
disconnect "/usr/sbin/chat -V -f /etc/chatscripts/BluetoothPhone-Disconnect"

Connecting to the Internet
Now to connect to the Internet, type the command sudo pppd call BluetoothPhone. Internet can be disconnected anytime by pressing Ctrl+C.

December 28, 2008

About Me

Who are you?
I'm Mohit Soni. I started hacking computers at the age of 10 with my PC. My exploration of computers started with Microsoft Windows 98 and QBasic. I continued my computer journey  with Visual C++ 6.0. I also spent significant time with Visual Basic 6.0 and Visual Foxpro 6.0. I am now quite comfortable with Java, PHP, C, C++.
I started hacking GNU/Linux when I was 17, with Ubuntu 6.06. But now, I am an avid openSUSE user and fan.