Friday, January 25, 2008
Buying the WRT54G Wireless Router in India
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
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++
#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
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)
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
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
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
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.