Monday, November 27, 2006

My New Homepage.

Check my new homepage at
You can download all the scripts from the given page.
My stumble page


Friday, November 24, 2006

[perl] Create dir and links for a given dir.

#written by vaibhav gupta
#Creates a new directory for a given directory and creates links for files.
$dir = $ARGV[0];
&usages unless $dir ;
sub usages {
        print "Usages: <Dirname> \n";
sub copy {
        @result = `find $dir -type d`;
        $dirname = `echo "$dir"  | rev | cut -d"/" -f 1 | rev`;
        chomp $dirname;
        $desination = "$dirname";
        foreach $d(@result) {
                chomp $d;
                ($a,$b) = split(/$dirname/,$d);
                print "Creating $desination$b\n";
#               print "[$a -- $b]";
                @res = `mkdir -p $desination$b`;
                print @res;
        @result = `find $dir -type f `;
        foreach $d(@result) {
                chomp $d;
                ($a,$b) = split(/$dirname/,$d);
                print "Copying $d\n";
                @res = `ln -s  $d $desination$b`;
                print @res;

[perl] Popup window

# written by vaibhav gupta
use Gtk2 '-init';
$x=100;$y=100; #default Cordinates
$blue = 0xffff ;
$label = "Hello there";
$label = $ARGV[0] if $ARGV[0];
$delay = 5 ;
$delay = $ARGV[1] if $ARGV[1];
$x = $ARGV[2] if $ARGV[2];
$y = $ARGV[3] if $ARGV[3];
$blue = $ARGV[4] if $ARGV[4] ;

sub usages {
        print "\n $ARGV[0] <label> <delay> <x> <y> <color>\n";

$window = Gtk2::Window->new("popup");
$window->signal_connect( destroy => sub {Gtk2->main_quit}) ;
$label = Gtk2::Label->new($label);
$label->modify_fg('normal',Gtk2::Gdk::Color->new(0,0,$blue) );
Glib::Idle->add( sub { Gtk2->main_quit; 0 } );
print `sleep $delay`;

[python] Start Python

import sys
import os
import __builtin__

def helloworld():
    print "Dare to Challenge"
    print "Hello World\n";
    print "This is system Path : "
    print sys.path #this is search Path
    print "This is system Path after appending test path "
    print sys.path
    filename = os.environ.get('PYTHONSTARTUP')
    print filename
    if filename and os.path.isfile(filename):
    li = []
    print "Method of list ", dir(li) # list all the method of list
    info(__builtin__, 20) # gives the list of built in function

#Factorial Function Start
def fact(n):
    if n > 1:
        return n * fact(n-1)
        return 1
def info(object, spacing=10, collapse=1):
    """Print methods and doc strings.

    Takes module, class, list, dictionary, or string."""
    # note
    methodList = [e for e in dir(object) if callable(getattr(object, e))]
    processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
    print "\n".join(["%s %s" %
                      processFunc(str(getattr(object, method).__doc__)))
                     for method in methodList])

def datatypes():
    str = "This is a string."
    print str
    dict = {"server":"mpilgrim", "database":"this will be deleted"}
    print "Currnt Dictionary: ", dict # NOte that it printed in a sorted way.
    dict["server"] = "CHANGED"
    dict["uid"] = "added"
    dict["Uid"] = "case sensitive"
    dict[2] = "mixed data"
    dict["mixed"] = 123
    del dict["database"]
    print "Now Dictionary   : " , dict
    dict.clear() # To clear all the contents
    list = ["a", "b", "mpilgrim", "removethis", "example","pop"]
    print "Current List   :" , list
    print "Length of List : ", len(list)
    print "list[-1]   :", list[-1] #"li[-n] == li[len(li) - n]"
    print "Slicing    :", list[1:-1]
    print "Pop Element: ", list.pop()
    list.extend(["extend1","extend2"]) #note the arg is a list.  Concatenates
    list += ["Operators"]
    print "Now List   : ",list
    print "Searching extend1 (first occurence): Found at location ", list.index("extend1")
    print "Found c in list:" , "c" in list
    list = ["1","2"]
    print "List Operator  : ", list * 10
    tuple = ("son","mon","tue","wed","thu","fri","sat") # Ordered, fast, But can not be modified
    print tuple
    (a,b,c,d,e,f,g) = range(7)
    print "rnage d = ", d

#Calling main Functions.
#print fact(500)

"""  Notes
---------- and-or Trick  ----------

>>> a = "first"
>>> b = "second"
>>> 1 and a or b
>>> 0 and a or b
---------- and-or Trick Safely ----------
>>> a = ""
>>> b = "second"
>>> (1 and [a] or [b])[0]
---------- split With No Arguments ----------
>>> s = "this    is\na\ttest"
>>> print s
this   is
a       test
>>> print s.split()
['this', 'is', 'a', 'test']
>>> print " ".join(s.split())
'this is a test'


The Fastest Language

Though this post is a little digression from what this forum is meant
for. It is really an interesting one because many a times we think

Which language is the fastest?

Considering the same hardware/environments are provided, it will all
depend on how well a compiler/interpreter make use of underlying
hardware/environment to generate native/interpreted code.

In a computer language shootout [Survey]
differrent compiler for different languages tested against their
ability to translate code for Ackermann Function
[Ackermann_function], Fibonacci numbers[Fibonacci_number] and
Tak functions [TAKFunction.html].

I was really happy to see that my favourite compiler gcc rules :-)

-by sbjoshi

Wednesday, September 27, 2006

[Perl] Script to take backups

# Written By Vaibhav Gupta
# Modify @FILES_TO_BACKUP @DIRS_TO_BACKUP @FILES_PATH as per your need.

$Directory=`date +%Y%m%d%k%M`;
chomp $Directory; # you know why ?
@DIRS_TO_BACKUP=( "cvsroot","public_html/","bin");

print "\nCreating directory $Directory\n";
@message = `mkdir $Directory`;

foreach $filename (@FILES_TO_BACKUP) {
@message = `cp $HOMEDIRECTORY$filename $Directory`;
foreach $filename (@FILES_PATH) { #Absolute Filename
@message = `cp $filename $Directory`;
foreach $dirname (@DIRS_TO_BACKUP) {
@message = `cp -r $HOMEDIRECTORY$dirname $Directory`;
@message = `tar -cvzf $Directory.tgz $Directory`;
print @message;


Monday, September 11, 2006

[shell] To find the PPID of a PID and more.

1 #!/bin/bash
2 pid=$1
3 if [ -f "/proc/$pid/stat" ]; then
4 name=`cat /proc/$pid/stat | cut -d" " -f 2`
5 else
6 echo "Not a Valid pid $pid"
7 exit
8 fi
11 while [ "$pid" -gt "0" ]; do
12 echo -n $pid
13 echo -n [$name]
14 echo -n " --> "
15 name=`cat /proc/$pid/stat | cut -d" " -f 2`
16 pid=`cat /proc/$pid/stat | cut -d" " -f 4`
17 done
19 echo "0"


Writing Kernel Modules for 2.6

1 #include <linux/module.h>
2 #include <linux/kernel.h>
4 int init_module(void)
5 {
6 printk(KERN_INFO "Hello world \n");
7 return 0;
8 }
10 void cleanup_module(void)
11 {
12 printk(KERN_INFO "Goodbye world \n");
13 }

1 obj-m += hello.o
3 all:
4 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
7 clean:
8 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
9 fresh: clean all


Install Module# insmod hello.ko
Remove Module # rmmod hello.ko
Module info # modinfr hello.ko
List Module # lsmod
Check Log # tail /var/log/messages

Files :
/proc/modules | List of modules |
/proc/kallsyms | List of Symbols |


Sunday, July 02, 2006

[c++] Source code to find Prime numbers < n+1

/*Code is written by Vaibhav Gupta*/

int prime(int n){

bool *prime = new bool[n+1];
int i;
prime[i] = true;
int m = (int)sqrt((float)n);

for (i=2; i<=m; i++)
if (prime[i])
for (int k=i*i; k<=n; k+=i)

for (i=0; i<n+1; i++){
if (prime[i]) cout << i << " ";
cout << endl;
return 0;

Tuesday, June 20, 2006

[ebooks] Over 1 billion ebooks.......

Hi friends,

Some sites may not be working.....
fxp:// - flashget -
http:// - HUGE COLLECTION - Game Programming
ndlQuery=757312448&PageNum=0&g=0&d=0&ag=host&tg=1&q0=54598832&p= ...rials-tips.html (mcsd books)
(nice)( (nice)

Happy reading.......


Tuesday, May 30, 2006

How to set up thinclient in Linux

Thin Client How to by Vaibhav Gupta

How to set up Thintux Server
You need to setup dhcp server and copy thintux folder on the server.
Setting up dhcp server
a. Make dhcpd configuration file :-> /etc/dhcpd.conf
b. Starting dhcpd :-> /etc/init.d/dhcpd start

Configuring dhcpd.conf Manually:-
1. Set subnet,netmask,router and range of IPs.
2. Set Thintux session server address, resolution and color depth.
3. Detailed Information man dhcpd, man dhcpd.conf
4. Get Sample Configuration dhcpd.conf (For Linux)<a
href="thintux/dhcpd.conf" >[dhcpd.conf] </a>

Format of dhcp.conf :-
#global parameters...
subnet netmask {
# subnet-specific parameters...
option routers;
group {
#group-specific parameters...
host {
#host-specific parameters...
Configuring using config-dhcpd :-

Start X Display Manager
1. vim /usr/X11R6/lib/X11/xdm/xdm-config
2. Comment the last line as below :-
!DisplayManager.requestPort: 0
3. Save and Exit
4. vim /usr/X11R6/lib/X11/xdm/Xaccess
5. uncomment the following line (By removing #)
#* #any host can get a login window
6. Save and Exit
7. Start xdm :-> xdm

Help and Debug :-
1. man xdm
2. Error Logs :-> /var/log/xdm-errors
or :-> /usr/X11R6/lib/X11/xdm/xdm-errors
3. X -query

Check tftp is enable on server
1. vim /etc/xinetd.d/tftp
2. Change the disable option to "no" as Below.
disable = no
3. Save file and exit
4. Restart xinitd

Copy /thintux folder in /tftboot on server
<a href="thintux/thintux.tgz" >[thintux][tgz] </a>

How to setup thinclient
Client already contaning Linux OS
1. Copy "localdsk" as /root/thinlinux on Client <a
href="thintux/localdsk" >[localdsk][x86 boot sector] </a>
2. Modify /etc/lilo.conf
3. Run lilo
4. Restart the PC

Add following Entries to lilo.conf:-

default=thin-linux # Add or Modify this line for default Booting from N/w

Client that doesnot contain Linux OS
For all the following steps you have to use Dos Bootable Floopy
containg fdisk, format, and linux image(thintux) [as
downloaded above].

1. Delete all partitions on Hard Drive using fdisk.
2. Execute :-> fdisk /mbr
3. Create 20MB Dos Partion and Make active
4. Reboot
5. Execute:-> Format C:
6. Execute:-> syslinux c:
7. Execute:-> copy linux c: The above file "linux" is same as "localdsk". Only the name is
changed in this case.
8. Remove Floppy and Reboot

For Debugging
1. Use tcpdump as
tcpdump -n port 7100
tcpdump -n port tftp


C++ Programs [Interview]

Find the number which is odd number of times? [Interview]
Dated: Wed Dec 28 22:44:42 IST 2005

14 int findodd(int *n,int len)
15 {
16 int num=0;
17 for(int i=0;i<len;i++)
18 num^=n[i];
19 return num;
20 }

How would u sort of 0s and 1s in just single pass? [Interview]
Dated: Wed Dec 28 22:27:42 IST 2005

1 void sort_01 (int *n,int len)
2 {
3 int i=0,j=len-1;
4 while(1){
5 while((!n[i])&&(i<len)) i++;
6 while((n[j])&&(j>-1)) j--;
7 if(i>=j) break;
8 n[i]=~n[i]&1;
9 n[j]=~n[j]&1;
10 i++;j--;
11 }
12 }

Find all possible splits for any given number n. [Interview]
Dated: Wed Dec 28 21:33:48 IST 2005

Init : int array[5]={0,0,0,0,0};
Function Call : split(array,5,0);

1 void split(int *n,int count,int len)
2 {
3 if(count==1) {
4 int i;
5 for(i=0;i<len;i++)
6 printf("%d+",n[i]);
7 printf("%d\n",n[i]+1);
8 return;
9 }
10 else {
11 n[len]+=1;
12 split(n,count-1,len);
13 split(n,count-1,len+1);
14 n[len]-=1;
15 }
16 return ;
17 }

WAP to check a integer (as binary string) is pallindrome? [Interview]
Dated: Wed Dec 28 18:27:43 IST 2005

1 bool panlindrome(unsigned long i)
2 {
3 if(!(i&1)) return false;
4 unsigned long t=i,rev=1;
5 t>>=1;
6 while(t) {
7 rev<<=1;
8 if(t&1) rev |=1;
9 t >>=1;
10 }
11 if(rev==i) return true;
12 return false;
13 }

Find the number of ones in an integer? [Interview]
Dated: Wed Dec 28 18:17:14 IST 2005

1 unsigned noofone(unsigned long i)
2 {
3 int count=0;
4 while(i) i=i&(~(i&(~i+1))),count++;
5 return count;
6 }

WAP to convert a given integer to octal number? [Interview]
Dated: Wed Dec 28 17:45:04 IST 2005

1 #include<stdio.h>
2 void int2octal (unsigned long i)
3 {
4 if(i) {
5 unsigned long o = i&7;
6 i>>=3;
7 int2octal(i);
8 printf("%d",o);
9 }
10 else printf("0");
11 }

How to reverse a singly-linked list? [Interview]
Dated: Tue Dec 27 06:49:35 IST 2005

1 node* reverse_list(node *list)
2 {
3 node *rev=NULL;
4 while(list !=NULL) {
5 node *t = list->next;
6 list->next = rev;
7 rev = list;
8 list = t;
9 }
10 return rev;
11 }

How To Speed Up Firefox [Howto]

Here's something for broadband people that will really speed Firefox up:

1.Type "about:config" into the address bar and hit return. Scroll down and
look for the following entries:

network.http.pipelining network.http.proxy.pipelining

Normally the browser will make one request to a web page at a time. When you
enable pipelining it will make several at once, which really speeds up page

2. Alter the entries as follows:

Set "network.http.pipelining" to "true"

Set "network.http.proxy.pipelining" to "true"

Set "network.http.pipelining.maxrequests" to some number like 30. This means
it will make 30 requests at once.

3. Lastly right-click anywhere and select New-> Integer. Name it
"nglayout.initialpaint.delay" and set its value to "0". This value is the
amount of time the browser waits before it acts on information it recieves.

If you're using a broadband connection you'll load pages MUCH faster now!


How to Export sound in Linux [Howto]

Exporting sound :-

Run 'artsd -n -u -p 5001' on system on which u want to hear sound.
Run 'export ARTS_SERVER=ip_of_system_on_which_sound_it_to_be_heard:5001'
on system where sound application will be run (like mplayer)
Run 'mplayer -ao arts soundfile.mp3'

Monday, May 29, 2006

Vim Movements

Moving Around
k (up),
h(left) l (right).
j (down)
(Ex 5k,j,3l )

Word Movement
w (Forward Word Movement Ex. f,5f )
b (Backword Word Movement Ex. b,2b)
e (Forward Word Movement at the end of word Ex. e,3e )
ge (Backword Word Movement at the end of word Ex. ge,3ge )

Moving to the Start or End of a Line
$(End Of Line Ex. $,2$)
^(Start Of Line Ex. ^,3^)

Searching Along a Single Line
f<Charcter> (Searching Charcter Forward Ex. fa, 2fv)
F<Charcter> (Searching Charcter Backword Ex. Fg,2Ft)
t<Charcter> (Search till Forward )
T<Charcter> (Search till Backword)

Moving to a Specific Line
<Line No.>G (Go to Line No.)
CTRL-G (Where I am in the File)
g CTRL-G (Count col, line, words and bytes)
CTRL-O Jump to previous location.
<TAB> Jump to next location (line 10).

Where are you in File
:set number
:set nonumber

Scrolling Up and Down
CTRL-U (scrolls up half a screen of text.)
CTRL-Y (scrolls up a line of text.)
CTRL-B (scrolls up a entire screen at a time.)
CTRL-D (scrolls down half a screen of text.)
CTRL-E (scrolls down one line.)
CTRL-F (scrolls down one screen of text.)
z<Enter> (screen line on the top)
88z<Enter> positions line 88 at the top.
zt (Leaves the cursor where it is.)
z- (scrolls line to the end of the screen)
zb (Leaves the cursor where it is)
z. (Center of the screen)
zz (Leaves the cursor where it is .)

:set scroll=10
:set scrolljump=5
:set scrolloff=3

x delete character under the cursor (short for "dl")
X delete character before the cursor (short for "dh")
dw (Delete Word Ex. dw,3dw,d3w,3d2w,d$,d^,df> )
dd (Delete Line Ex. dd,3dd)
D (Delete up to end of line. )(short for "d$")
diw delete word under the cursor (excluding white space)
daw delete word under the cursor (including white space)
dG delete until the end of the file
dgg delete until the start of the file

CTRL-A Incrmenting Number (123, 0177, 0x1f,-98)
CTRL-X Decrementing Number

:set nrformats=""

Changing Text
cw (Change Word Ex cw,c2w)
C stands for c$ (change to end of the line)
s stands for cl (change one character)
S stands for cc (change a whole line)

The . Command
It repeats the last delete or change command.

Joining Lines
J (Join Lines to One. Ex J,3J)
gJ (Join Lines without Spaces)

Replacing Charcter
r<Charcter> (Replace Charater Under Cursour. Ex. ru,5ra,3r<Enter> )

Changing Case
~ (Change Case of Character Ex. ~,12~,~fq)
U (Make the text Uppercase)
u (Make the text Lowercase)
g~motion (It does not depend on tildeop)
g~~ or g~g~ (Changes case of whole line)
gUmotion (All uppercase)
gUU (Changes to uppercase for whole line)
gUw (Changes to uppercase for word)
guw (Changes to lowercase for word)

How to set up ssh keys for Linux

How to set up ssh keys for Linux

1. Run "ssh-keygen -t dsa" on the machine which is the client.
Files Generated :
$(HOME)/.ssh/id_dsa : Your private Key
$(HOME)/.ssh/ : Your public Key
You can enter empty passphrase.
Type can rsa and dsa for version 2 and rsa1 for version 1.
2. Now ssh into the server.You need to type password this time.
you have to transfer the publickey to server.
cd $(HOME)/.ssh
cat $(HOME)/.ssh/ >> authorized_keys2

Note : Don't introduce any extra spaces, slashes or any other characters
If the file already exists, append the output of to EOF.

3. Repeat for Other machine if you want.
4. Now you can login without entering passwords.
On some machines, it might ask you to verify the host key,
but will happen only for the first time.

Changing MySQL root password

Changing MySQL root password

Sometimes you forget the root password, or something went wrong
modifying it. Here's how to reset the root password for mysql on a
Redhat Linux box:

[root@host root]#killall mysqld
[root@host root]#/usr/libexec/mysqld -Sg --user=root &
[root@host root]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 3.xx.xx
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> USE mysql

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> UPDATE user
-> SET password=password("newpassword")
-> WHERE user="root";
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> exit;
[root@host root]#killall mysqld

Then start MySQL again:

/etc/init.d/mysqld start

Makefile for c++ project

# Written By Vaibhav Gupta
# wire - default target
# dwire - debug target
# tag - For generating tag file
# clean/fresh - clean obj files.
#-- Customized variables

CC = g++
CWARN = -W -Wall -Wshadow -Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -Wuninitialized -O

CDBG = -g $(CWARN) -fno-inline
DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1

CTAG = ctags
CTAGFILE = filelist
# src, object and bin files
#Debug Target

HEADERS = $(INCDIR)/global.h

COMMONOBJS = $(OBJDIR)/BaseStation.o $(OBJDIR)/SubscriberStation.o
$(OBJDIR)/Packet.o $(OBJDIR)/Queue.o $(OBJDIR)/Global.o $(OBJDIR)/Simulate.o


#-- Rules
all: $(TGT)
dbg: $(DBGTGT)

$(TGT): $(BINDIR)/$(TGT)
@echo "$@ uptodate"

@echo "$@ uptodate"

$(CC) $(CFLAGS) -o $@ $(DBGOBJS)

$(OBJDIR)/%.dbg.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -DDEBUG=1 -c -o $@ $?

$(CC) $(CFLAGS) -o $@ $(OBJS)

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c -o $@ $?

.PHONY : clean depend fresh
tag :
find src/*.cpp include/*.h > filelist

clean :
-rm -f $(OBJDIR)/*.o $(PARSE_C) $(PARSE_H)
-rm -f $(SRCDIR)/*.output $(LEX_C)
-rm -f */*~ *~ core
-rm -f $(BINDIR)/$(TGT) $(BINDIR)/$(DBGTGT)

fresh : clean all

Picking a random quote or signature from a file [perl]

Generates a Random Signature from a signature file


sub pick_quote {
my $path = "/usr/signature/";
my $sigfile = "$path/signature.txt"; # Signature FILE
open (SIGS, "< $sigfile" ) or die "can't open $sigfile";
local $/ = "%%\n";
local $_;
my $quip;
rand($.) < 1 && ($quip = $_) while <SIGS>;
close SIGS;
chomp $quip;
print $quip || "ENOSIG: This signature file is empty.\n";

Sample Signature File

Signatures are a waste of bandwidth.
Help stamp out signatures.
'Calm down -- it's only ones and zeros.'
According to my calculations the problem doesn't exist.
A day for firm decisions!!!!! Or is it?
A few hours grace before the madness begins again.
A gift of a flower will soon be made to you.
A long-forgotten loved one will appear soon.

Buy the negatives at any price.

Linux Tips

Who is SUPER USER in linux

awk -F: '$3 == 0{print $1,"superuser!"}' /etc/passwd
How to get Environment for a process
If the process id is 920.

(cat /proc/920/environ; echo) : tr "\000" "\n"
How to list files with their complete path
If 'childdir' is the name of directory.

find childdir -type f -printf "%AY%Am%Ad%AH%AM %p\n" : sort -r : gawk
'{print $2}'
How to find open files in linux

find /proc -regex "/proc/[0-9]*/fd/.*" -ls
Formatting man pages

man ls : col -bx > myfile.txt
Finding the biggest files

ls -l : sort +4n
Searching files for content

find / -name "filename" : xargs grep -n content
Largest Directories

du -kx : egrep -v "\./.+/" : sort -n
List today's files only

ls -al --time-style +%D : grep `date +%D`
Encrypt some plain text

perl -e 'print crypt("ke", "password");'
Look for unusual SUID root files

find / -uid 0 -perm -4000 -print
Look for unusual large files (> 10 Mb)

find / -size +10000k -print

Linux Command Line Tips

Linux Command Line Tips

Vim Folding Tips

# folding : hide sections to allow easier comparisons

zf{motion} or {Visual}zf :Operator to create a fold.
zf'a : fold to mark
zF :Create a fold for N lines.
zd :Delete one fold at the cursor.
zD :Delete folds recursively at the cursor.
zE :Eliminate all folds in the window.
zo :Open one fold.
zO :Open all folds recursively.
zc :Close one fold.
zC :Close all folds recursively.
za :When on a closed fold: open it.and vice-versa.
zA :When on a closed fold: open it recursively.and vice-versa.
zR :Open all folds.
zM :Close all folds:
zn :Fold none: reset 'foldenable'. All folds will be open.
zN :Fold normal: set 'foldenable'. All folds will be as they were before.
zi :Invert 'foldenable'.

[z :Move to the start of the current open fold.
]z :Move to the end of the current open fold.
zj :Move downwards. to the start of the next fold.
zk :Move upwards to the end of the previous fold.

My vimrc: Open a c/cpp/java/perl programm. Press <F6> and see the power of
vim :-)

nmap <F6> /}<CR>zf%<ESC>:nohlsearch<CR>


How to Search in Google

How to Search in Google

1. allintitle: graph partition triangle
2. +("index of") +("/ebooks":"/book") +(chm:pdf:zip:rar) +apache
3. allinurl: +(rar:chm:zip:pdf:tgz) TheTitle
4. allinurl:config.txt
5. allinurl:admin.txt
6. "Index of /something"
7. filetype:doc site:edu


Vim and HTML

HTML and vim Tips:

:runtime! syntax/2html.vim :convert txt to html
:%s#<[^>]\+>##g : delete html tags, leave text

My vim.rc : Type a word and press ",," without quote

imap <silent> ,, <ESC>"_yiw:s/\(\%#\w\+\)/<\1> <\\\1>/<cr><c-o><c-l>f>a


Extract links from a file [perl]

How to extractlinks from a file

use HTML::SimpleLinkExtor;
my $file = new HTML::SimpleLinkExtor();

# Extracts Links from a HTML File
# Written by Vaibhav Gupta
$filename = $ARGV[0];
$url = $ARGV[1]; #base url else empty string

if($filename eq "" ) {
print "\nUsages: ./ filename.html\n";
exit ;

my @links= $file->a;
foreach $link (@links){
print "$url$link\n";

Networking Hacks

How to chat without using talk

At Server side:
nc -l -p 5600 -vv
At client Side:
nc 5600

Here is the ip of server. 5600 is the port.

How to transfer file with out using ftp

At Server Side:
nc -v -w 30 -p 5600 -l > filename.back
At Client Side:
nc -v -w 2 5600 < filename

How to mail using telnet

C: client
S: Server

C:telnet 25
C:mail from:<root@>
S:250 ok
C:rcpt to:<>
S:250 ok
S:354 go ahead
C:Subject: This is subject line.
C:hi vaibhav,
C:how r u? i m fine.
C:bye for now
S:250 ok 1095622024 qp 2471
S:502 unimplemented (#5.5.1)
S:Connection closed by foreign host.

SMTP Commands

SMTP commands are ASCII messages sent between SMTP hosts.

*Command: Description
*DATA: Begins message composition.
*EXPN <string> : Returns names on the specified mail list.
*HELO <domain> : Returns identity of mail server.
*HELP <command>: Returns information on the specified command.
*MAIL FROM <host> : Initiates a mail session from host.
*NOOP : Causes no action, except acknowledgement from server.
*QUIT : Terminates the mail session.
*RCPT TO <user>: Designates who receives mail.
*RSET : Resets mail connection.
*SAML FROM <host> : Sends mail to user terminal and mailbox.
*SEND FROM <host> : Sends mail to user terminal.
*SOML FROM <host> : Sends mail to user terminal or mailbox.
*TURN : Switches role of receiver and sender.
*VRFY <user> : Verifies the identity of a user.

Tuesday, April 18, 2006

Forgot password for Windows 2000?

well, this trick can work only if you have got a dual boot machine with linux as one of the os. Also, either you should be a root or the windows partition should be mounten with appropriate permission.

just delete the file
and you are done. you can boot your machine in windows and can get entry with
user : administrator
passwd :

leave the password field null.

Saturday, April 15, 2006

Running commands using script

#Written by Vaibhav.
#guptav[at]cse[dot]iitb[dot]ac[dot]in on Mon Mar 7

use Expect;
#List of IPs in file 'IPS'
close IP;
my $newpassword = "yourpassword";

foreach $ip(@IPS) {
chomp $ip;
print "-------$ip-------\n";
my $timeout = 50;
my $aft = new Expect;
$aft->spawn("ssh $ip")
or die "Cannot ssh to the machine \n";
$aft->expect($timeout,'-re','\? $');
$aft->expect($timeout,'-re','password: $');
$aft->expect($timeout,'-re','# $');
$aft->send("ls\n"); # OR LIST OF COMMANDS
$aft->expect($timeout,'-re','# $');