Friday, January 25, 2008

Buying the WRT54G Wireless Router in India

To make my home wi-fi enabled, I decided to buy a Wireless Router. Loads of such routers are available these days and after doing a bit of research online I decided to go for the Linksys WRT54G router.

WRT54G routers allow you to install certain open-source (linux) firmware. If you are the kind who likes to play around with hardware, then this is the one for you. It allows you to do all sorts of things like increase the range (using the Xmit power), port-forwarding etc. etc. For details please goto http://www.dd-wrt.com/.

A friend of mine suggested to go for WRT54G Version-5 or 6 since he already had one and it was working fine with Linux firmware. So... I went to Nehru Place (supposedly THE place to buy computer hardware in New Delhi) and asked for Linksys WRT54G router. Surprisingly the version information wasn't mentioned on the router's box.. I tried a few more shops.... but again, no version information. Hoping that the router will work with linux firmware I decided to purchase the router for Rs. 2150/-. Once I got home and opened the box 'version 7' was mentioned at the back of the router. After a bit of googling it was clear that this version of WRT54G CANNOT be upgraded to Linux firmware. Even if I try to install the firmware, the router will get 'bricked' (basically of no use and will have to be thrown).

If you are planning to buy the WRT54G router and install Linux firmware on it, please ensure that it's NOT 'version 7'. All versions (v5,6,8) can be upgraded to Linux firmware but not v7. The serial number of all WRT54G v7 routers starts with 'CDFE'. The serial number is mentioned on the router's box (wish I knew this early on).

Luckily I found someone who already had a 2 year old v5 WRT54G and was happy to exchange his router with my new v7 router :)

I have now successfully upgraded the v5 router to Linux firmware(dd-wrt) and its working fine.

Thursday, January 24, 2008

Hosting multiple sites on a single server using the same IP

Apache has a great feature which allows hosting multiple sites using the same apache instance and even the same IP address. To know more click here

Following example shows how this can be done.

Open the httpd.conf configuration file which is being used by apache.

Add following at the end:

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
ServerAdmin your@email.com
DocumentRoot /doc/root/for/first/domain/
ServerName www.firstdomain.com
ServerAlias www.firstdomain.com
ErrorLog logs/firstdomain_error_log
CustomLog logs/firstdomain_access_log common
</VirtualHost>

<VirtualHost 127.0.0.1:80>
ServerAdmin your@email.com
DocumentRoot /doc/root/for/second/domain/
ServerName www.seconddomain.com
ServerAlias www.seconddomain.com
ErrorLog logs/seconddomain_error_log
CustomLog logs/seconddomain_access_log common
</VirtualHost>

Replace 127.0.0.1 with the appropriate IP address, firstdomain and seconddomain as per the requirement.

Restart apache.

I tried this with apache 2.0.59 and it works fine.

Thursday, January 17, 2008

Finding Intersections between two sets in C++

Following C++ code (intersection.cpp) creates 2 sets ( a and b), creates a vector out of those (av and bv) and then finds the intersection between the two vectors.



#include <iostream>
#include <vector>
#include <set>
#include<sys/time.h>

using namespace std;

#define MAX_SIZE 1000000

int main()
{
set<int> a,b,un,in,di;
timeval tim;

srand ( time(NULL) );

cout << "Adding to a : " << endl;

for( int i = 0; i < MAX_SIZE; i++ ) {
int r = rand() % MAX_SIZE;
a.insert( r );
}

cout << "Creating vector av" << endl;
vector<int> av(a.begin(),a.end());
cout << "There are " << av.size() << " elements in av" << endl;

cout << "Adding to b : " << endl;

for( int i = 0; i < MAX_SIZE; i++ ) {
int r = rand() % MAX_SIZE;
b.insert( r );
}

cout << "Creating vector bv" << endl;

vector<int> bv(b.begin(),b.end());
cout << "There are " << bv.size() << " elements in bv" << endl;

gettimeofday(&tim, NULL);
double t1=tim.tv_sec+(tim.tv_usec/1000000.0);

set_intersection(a.begin(),a.end(),b.begin(),b.end(),insert_iterator<set<int> >(in,in.begin()));

gettimeofday(&tim, NULL);
double t2=tim.tv_sec+(tim.tv_usec/1000000.0);

vector<int> inv(in.begin(),in.end());

cout << "Elements in intersection " << inv.size() << endl;
cout << "Intersection time " << (t2-t1) << " seconds" << endl;
return 0;
}


compile: c++ intersection.cpp -o intersection
Sample Output

./intersection
Adding to a :
Creating vector av
There are 632163 elements in av
Adding to b :
Creating vector bv
There are 631924 elements in bv
Elements in intersection 399250
Intersection time 0.65199 seconds

Monday, January 14, 2008

Technologies to look out for in 2008

Here are a bunch of exciting technologies to look out for this year:

1) Wireless USB: Tired of carrying all those wires with your USB devices. Well... there is hope of getting rid of them. Wireless USB is capable of high speed data transfer (much faster than Bluetooth). http://en.wikipedia.org/wiki/Wireless_USB

2) Solid State Drive (SSD): These are the next generation of Disk Drives. They should be hugely successful with mobile devices (like laptops n phones) coz they are mechanically very reliable. They have the ability to endure extreme shock, high altitude, vibration and temperatures. http://en.wikipedia.org/wiki/Solid_state_disk.

3) Organic Light-Emitting Diode (OLED): Much more efficient than the traditional LED and plasma due to their low power consumption and ability to provide more color depth without any backlight. Extremely thin TVs with amazing colors will be possible with this technology. http://en.wikipedia.org/wiki/Organic_light-emitting_diode.

4) Near Field Communication (NFC): This is a short range, high-frequency wireless communication technology aimed primarily at usage in the mobiles. This makes things like Mobile ticketing and payment possible. http://en.wikipedia.org/wiki/Near_Field_Communication.

Friday, January 11, 2008

Removing all non-ASCII characters from a string using php

ASCII characters have hex code from 00 to 7F (http://www.asciitable.com/).

Following php function removes all non-ASCII characters from a string:

function removeNonAscii($string) {
return preg_replace('/[^\x00-\x7f]/','',$string);
}

Sunday, January 06, 2008

Reliance Broadnet (Broadband internet connection)

I recently got a pamphlet of Reliance Broadnet (Broadband service provided by Reliance in India) which mentions that the service provides download speeds ranging from 150 Kbps to 2 Mbps.

Following are the plans mentioned:

1. Rs. 750/month for 150 Kbps (unlimited upload and download)
2. Rs. 999/month for 300 Kbps (unlimited upload and download)
3. Rs. 1799/month for 600 Kbps (unlimited upload and download)
4. Rs. 750/month for speed upto 2 Mbps with free usage of 4 GB (upload+download) and 90 paise/MB for additional usage

Installation charge is Rs. 500 + Service Tax.

Call 1-800-227773 or 3033 7777 for details.

Friday, January 04, 2008

Set Clipboard contents from command line using java

Following code(setClipboardContents.java) sets the Clipboard contents for 10 seconds:


import java.awt.datatransfer.StringSelection;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;

public class setClipboardContents{
public static void main(String[] args) throws Exception {
StringSelection stringSelection = new StringSelection( args[0] );
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents( stringSelection, null);
try{
Thread.sleep(10000);
} catch(InterruptedException e){
System.out.println("Sleep Interrupted");
}
}
}


Compile: javac setClipboardContents.java
Run: java -cp . setClipboardContents "add this content to the Clipboard"

Capturing string input without echo in java

Following code will demonstrate capturing a string without any echo using java:

Create a java file (noEcho.java) with the following code:

import java.lang.System;
import java.io.Console;

public class noEcho {
public static void main(String[] args) throws Exception {
char[] passwd;
Console cons;
if ((cons = System.console()) != null && (passwd = cons.readPassword("[%s]", "Enter Text:")) != null) {
String text = new String(passwd);
System.out.println("You Entered :"+text);
}
}
}


Compile: javac noEcho.java
Run: java -cp . noEcho
Sample output:

[Enter Text:]
You Entered :this is a test string

Wednesday, January 02, 2008

Hibernate instead of Shutdown for faster performance

When you boot your computer, certain critical modules (like kernel) are loaded into the Primary Memory (RAM) which allow the operating system to start. After this whenever you start an application (like Microsoft Word or Outlook) it first gets loaded into the Primary Memory from where the OS loads the Application. Thus, the first time you start an application there might be a delay of a few seconds and the next time it'll be much faster.

Hibernate saves the contents of the RAM into Secondary Memory (Hard Disk) and when you boot the OS next time, it simply loads the RAM image back from the Hard Disk.

Thus, even though time taken for a normal boot vs time for a boot after hibernate may be similar, you save a lot of time while working on the same set of applications.

Saturday, December 29, 2007

MTNL Broadband in Delhi

I was using an Airtel Broadband connection in Hyderabad last year and was pretty satisfied with their service. After shifting to Delhi, I wanted to get an Airtel connection again but unfortunately they do not provide telephone/broadband services in my area. Tried Tata Indicom also, but no luck there too.

So finally I decided to go with MTNL Triband and requested a connection on 25th August 2007. Its been 4 months and after a number of calls and mails I have still not been given a connection. I went to the MTNL office last week and they told me that the 'ports' are not available in my area and I will get a connection only if someone else releases their connection. This is really funny and I suggest anyone who wants to go for an MTNL Broadband connection to first ask their Local MTNL telephone exchange whether there is a possibility of getting a connection anytime soon.

Thursday, December 27, 2007

Gmail App using Airtel Live on Sony Ericsson K750i

Activating Airtel Live (skip if you already have Airtel Live)

1) Call the customer care and ask for Airtel Live activation (or send "PLIVE" to 170). It takes about 24 hours for the activation.
2) Once activated. Get the settings by sending "LIVE" to 52567.

Once you have the settings enabled you can start using your phone's browser to access your gmail account (http://mail.google.com/mail/x/). This works but you might find this slow to access your mails again and again (as I did). If your Phone is capable of running Java Applications (which most phones are these days) then using the Java Application for Gmail is a much better option.

Setting up Gmail App (On Sony Ericsson K750i)
1) Goto http://gmail.com/app/ from the phone's browser and download the java application (about 160 KB). This is required only one time.
2) Once download is successful. The phone asks for confirmations. Allow the phone to install the application.
3) Goto Menu->Settings->Connectivity->Settings for Java and select the appropriate Internet profile ("AIRTEL LIVE" in case you are using Airtel Live).
4) Goto Menu->Organizer->Applications and select "Gmail".
5) Enter the gmail username and password and sign in.

Note: Accessing mails using the Gmail App are charged as per the standard download rates.

Monday, December 24, 2007

Enable External Display on Thinkpad R60 with Linux (Ubuntu 7.10)

Followings steps got my external CRT Display working on ThinkPad R60 with Linux Ubuntu 7.10 installed:

1) cd /opt
2) sudo wget http://www16.plala.or.jp/mano-a-mano/i810switch/i810switch-0.6.5.tar.gz
3) sudo tar -xzvf i810switch-0.6.5.tar.gz
4) cd i810switch-0.6.5/
5) sudo vi i810switch.c
Insert the lines marked in BOLD below:

//#define I865STR "8086:2572"
#define I915STR "8086:2592"
#define I945STR "8086:27a2" //line 63
#define MEMSTR "Memory at"
...
...

i = (p = strstr(*buff_ptr, I830STR)) != NULL ||
(p = strstr(*buff_ptr, I945STR)) != NULL || //line 266
#if defined (I865STR)
(p = strstr(*buff_ptr, I865STR)) != NULL ||
#endif /*defined (I865STR)*/
(p = strstr(*buff_ptr, I845STR)) != NULL;
if (i)
...
...

6) sudo make
7) sudo make install
8) sudo i810switch crt on (turns on the external display)
9) sudo i810switch crt off (turns off the extrenal display)

To allow any user to perform this switch:

chmod u+s /usr/bin/i810switch

I use a simple script to toggle my external display:

STATUS=`i810switch | grep CRT | awk '{print $2}'`
if [ "$STATUS" = "off" ]
then
i810switch crt on >> /dev/null
elif [ "$STATUS" = "on" ]
then
i810switch crt off >> /dev/null
fi