Monday, November 27, 2006

My New Homepage.


Check my new homepage at  http://vaibhav.gupta.googlepages.com/
You can download all the scripts from the given page.
My stumble page http://vaibhav.stumbleupon.com/


Vaibhav.
 

Friday, November 24, 2006

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

#!/usr/bin/perl
#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";
        exit;
}
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

#!/usr/bin/perl
# 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->set_title("Hello");
$window->signal_connect( destroy => sub {Gtk2->main_quit}) ;
$label = Gtk2::Label->new($label);
$label->modify_fg('normal',Gtk2::Gdk::Color->new(0,0,$blue) );
$window->add($label);
$window->move($x,$y);
#$window->resize(300,30);
$window->show_all();
Glib::Idle->add( sub { Gtk2->main_quit; 0 } );
#$window->begin_move_drag(0,100,100,1);
Gtk2->main;
print `sleep $delay`;

[python] Start Python

#!/usr/bin/python
import sys
import os
import __builtin__

def helloworld():
    print "Dare to Challenge http://www.pythonchallenge.com/"
    print "Hello World\n";
    print "This is system Path : "
    print sys.path #this is search Path
    sys.path.append("this/is/test/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):
        execfile(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)
        else:
        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" %
                     (method.ljust(spacing),
                      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.append("append")
    list.extend(["extend1","extend2"]) #note the arg is a list.  Concatenates
    list.insert(2,"inserthere")
    list.remove("removethis");
    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
    #3.6

#Calling main Functions.
helloworld()
#print fact(500)
#datatypes();
#info(list)



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

>>> a = "first"
>>> b = "second"
>>> 1 and a or b
'first'
>>> 0 and a or b
'second'
---------- 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

Well,
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

#!/usr/bin/perl
# Written By Vaibhav Gupta
# vaibhav.gupta@gmail.com
# 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 ?
$HOMEDIRECTORY="~guptav/";
@FILES_TO_BACKUP=(".vimrc",".bashrc","public_html/cgi-bin/index.cgi");
@DIRS_TO_BACKUP=( "cvsroot","public_html/","bin");
@FILES_PATH=("/etc/httpd/conf/httpd.conf");

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;

#Vaibhav.

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
9
10
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
18
19 echo "0"
20

-Vaibhav

Writing Kernel Modules for 2.6

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

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

Commands:

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 |

Vaibhav.

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;
for(i=0;i<n+1;i++){
prime[i] = true;
}
prime[0]=false;
prime[1]=false;
int m = (int)sqrt((float)n);

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

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.....

http://www.freebookzone.com/
http://en.wikipedia.org/wiki/E-book

ftp://194.105.193.56/pub/warez/books/os/
ftp://194.85.35.67/BOOKS/
ftp://193.231.20.1/pub/books/
ftp://218.104.214.138/4tF/2003/Xmas/
fxp://fxp.runnet.ru/BOOKS - flashget
ftp://se-lab-server.ddns.comp.nus.edu.sg/ebooks/
http://sleekfreak.ath.cx:81/books/
http://preterhuman.net/texts/
http://www.waneesoft.net/books/
http://www.itcertifer.com - www.itcertifer.com
http://cgdn.net/books/
http://www.nerd-star.com/books/
http://publib-b.boulder.ibm.com/Redbooks.nsf/redbooks/
http://classics.mit.edu/Browse/index-Homer.html
http://www.cybersecurity.com.br/Livros/
http://amitmathur.8m.com/ebooks.html
http://mail.stibanas.ac.id/ebooks/
http://www.wolfgarten.com
http://johnny.ihackstuff.com
http://www.law.fsu.edu
http://mail.stibanas.ac.id/ebooks
http://www.comms.scitech.susx.ac.uk/fft/
http://www.cadforum.cz/cadforum_en/default.asp http://en.fixdown.com/eall_1.htm
http://en.fixdown.com/download.asp?id=1658...589&soft=sxdown
http://en.fixdown.com/download.asp?id=1588...886&soft=kldown
http://en.fixdown.com/download.asp?id=1588...886&soft=fjdown
http://en.fixdown.com/download.asp?id=1588...886&soft=bjdown
http://preterhuman.net/texts/
http://www.eicage.org/eicage.asp
http://bjxebook.myetang.com/pc.html
http://www.about-flash.com/
http://docs.rinet.ru:8080/DEFAULT.HTML
http://www.bsmooth.de/BSolutions/
http://newdata.box.sk/raven/books.html
http://www.maththinking.com/boat/computerbooks.html
http://dhruvaraj.150m.com/
http://podgoretsky.pri.ee/ms.html
http://www.comms.scitech.susx.ac.uk/fft/
http://www.intelinfo.com/free_computer_books.html
http://www.e-book.com.au/freebooks.htm
http://www.mcsedirectory.com/books.shtml
http://www.gorkhali.com/kamal/download.htm
http://www.winnetmag.com/windowsnt20002003faq/
http://www.2000trainers.com/
http://www.w3schools.com/
http://members.rogers.com/thekickman/ebooks.htm
http://www.techtutorials.com/Applications/
http://sunsite.iisc.ernet.in/virlib/
http:// www.bdsoft.com/links.html
http://www.python.org/doc/
http://www.graphic-design.com/Photoshop/
http://bjxebook.myetang.com/pc_ebooks/db.htm
http://neworder.box.sk/box.php3?gfx=neword...0Unix%20systems
http://www.exameware.com
http://www.comms.scitech.susx.ac.uk/fft/
http://rahmat.zikri.com/books.html
http://freebooks.by.ru/
http://www.mindview.net/Books/DownloadSites
http://www.maththinking.com/boat/computerbooks.html
http://docs.rinet.ru:8080/
http://www.ebone.at/files.php?show=Books
http://www.empowermentzone.com/#unix
http://skaiste.elekta.lt/Books/
http://content.443.ch/pub/
http://www.ods.com.ua/index.phtml
http://kavosh.irost.net/books/library.htm
http://stommel.tamu.edu/~baum/programming.html
http://digital.library.upenn.edu/books/
http://zikri.indoglobal.com/books.html
http://www.greylib.align.ru/index.html
http://www.itcertifer.com/en/download/default.asp
http://www.lib.ru
http://lib.km.ru
http://aldebaran.ru
http://lib.bigmir.net
http://books.myweb.ru
http://book.pp.ru
http://www.biglib.com.ua/
http://www.lib.com.ua/
http://www.bestlibrary.ru/
http://www.citforum.ru/
http://i2r.rusfund.ru/
http://www.yaxoo.com/books/
http://docs.gets.ru/
http://bookz.ru/
http://www.bestbooks.ru/
http://leoslibrary.on.to/
http://www.bomanuar.ru/
http://molbiol.ru/review/index.html
http://lib.rin.ru/
http://www.bomanuar.ru/
http://www.voronezh.net/library/
http://www.xnt.info/category.php?all=44&start=5&id=9
http://www.emc.maricopa.edu/faculty/farabe...BioBookTOC.html
http://netfoo.net/unix_iso/unixbook.iso
http://maui.fornex.net/e-book/pdf-books/
http://books.dimka.ee/ - HUGE COLLECTION
http://cgdn.net/books/ - Game Programming
http://www.whitefreespeech.com/sub/TurnerDiaries.pdf
http://www.solargeneral.com/library
http://classics.mit.edu/Browse
http://www.nerd-star.com/books/
http://web.starman.ee/winxp/Windows%20XP%2...nside%20Out.rar
http://www.comms.engg.susx.ac.uk/fft/
http://www.vdr-era.cjb.net/documentos/
http://devsaa.narod.ru/books
http://www.ibiblio.org/obp/electricCircuits
http://www.highend3d.com/artists/artist.3d...=yinako&iid=197

http://narod.yandex.ru/cgi-bin/yandmarkup?...og=0x2757571A&H
ndlQuery=757312448&PageNum=0&g=0&d=0&ag=host&tg=1&q0=54598832&p=

http://onlinebooks.library.upenn.edu/webbi...le=&tmode=words

http://macbeht.narod.ru/bucher.htm
http://www.pcworld.com/resource/PDF/circ_2.asp
http://www.emc.maricopa.edu/faculty/farabe...BioBookTOC.html
http://netfoo.net/unix_iso/unixbook.iso
http://maui.fornex.net/e-book/pdf-books/
http://books.dimka.ee/
http://www.click-now.net/ebooks.htm
http://www.baen.com/
http://www.ebookmall.com/ebook/5613-ebook.htm
http://etext.library.adelaide.edu.au/
http://www.freebooks4doctors.com
http://gutenberg.net/cgi-bin/search/t9.cgi
http://gutenberg.net/gutenberg/find.shtml
http://freetechstuff.netfirms.com/dotnet/books.htm
http://www.soldierx.com/books/ACTIVEX_PROG...SHED/index.html

http://www.soldierx.com/books/CHARLIE_CALV...SHED/index.html

http://www.strath.ac.uk/IT/Docs/Ccourse/
http://www.brpreiss.com/books/opus4/html/book.html

http://onlinebooks.library.upenn.edu/webbi...le=&tmode=words

http://www.xatrix.org/index.php
http://www.fintech.ru/Library/prog/Getstrt...DB/getstart.htm
http://www.commandprompt.com/ppbook/
http://www.vijaymukhi.com/documents/books/...oap/xmlsoap.htm
http://www.vijaymukhi.com/documents/books/wap/wap.html
http://www.vijaymukhi.com/documents/books/...sp/javajsp.html
http://www.vijaymukhi.com/documents/books/...s/j2me/j2me.htm
http://www.vijaymukhi.com/documents/books/...s/j2me/j2me.htm
http://www.vijaymukhi.com/documents/books/...cs/csharp1.html
http://www.vijaymukhi.com/documents/books/...dv/csharp2.html
http://www.vijaymukhi.com/documents/books/...vbnet/vbnet.htm
http://www.vijaymukhi.com/documents/books/...ta/metadata.htm
http://www.vijaymukhi.com/documents/books/...net/content.htm
http://www.vijaymukhi.com/documents/books/...2net/vs2net.htm
http://www.vijaymukhi.com/documents/books/...et1/aspnet.html
http://docs.rinet.ru/Cold/
http://www.syncfusion.com/FAQ/WinForms/default.asp#86

http://www.ssuet.edu.pk/~amkhan/cisco/(ebo...ching/Table.htm

http://www.blindprogramming.com/
http://ssuet.edu.pk/taimoor/books/1-57521-...163-7/index.htm
http://www.manastungare.com
http://world.std.com/obi/
http://www.itebooks.net/onlineebooks/Networking.html
http://www.itebooks.net/onlineebooks/Certi...tification.html
http://www.itebooks.net/onlineebooks/Opera...ingSystems.html
http://www.itebooks.net/onlineebooks/Enterprise.html
http://www.itebooks.net/onlineebooks/Internet.html
http://www.itebooks.net/onlineebooks/Programming.html
http://www.itebooks.net/onlineebooks/Database.html
http://www.itebooks.net/onlineebooks/Graphics.html
http://www.itebooks.net/onlineebooks/DesktopApps.html
http://www.itebooks.net/onlineebooks/Hardware.html
http://freebooks.boom.ru
http://the-tech.mit.edu/Shakespeare/
http://www.vecpix.com/
http://kristi.erdves.lt/books/
http://www.zionwap.net/books/main.html
http://www.nopayweb.com/computerbook/
http://leon83.com/download/book/FreeBookList.htm
http://www.mslit.com
http://www.python.org/doc/current/tut/tut.html
http://esspc-ebooks.com
http://en.fixdown.com/eall_3.htm
http://www.xnt.info/category.php?id=9
http://www.bluesfear.com/v5.php
http://www.teamphotoshop.com/photoshop/tut...ials/ps_tut.php
http://www.80four.co.uk/tutorials/photoshop.html
http://www.eyesondesign.net/pshop/tuts.htm
http://www.good-tutorials.com/
http://www.grafx-design.com/tutorials.html
http://myjanee.home.insightbb.com/tutorials.htm
http://www.photoshoproadmap.com/photoshop- ...rials-tips.html
http://rainworld.com/psworkshop/

http://131.128.51.37/se-lab-server.ddns.....edu.sg/ebooks/
http://www.et.utt.ro/public/Docs/
http://www.docs.rinet.ru
http://www.tutorialized.com
http://books.malonus.com/ebooks/computer_science/
http://www.intersoftlb.com/blog4.aspx (mcsd books)
http://131.128.51.37/se-lab-server.ddns.....edu.sg/ebooks/
(nice)(electronic...computer)
http://www.et.utt.ro/public/Docs/
http://www.docs.rinet.ru
http://www.tutorialized.com
http://books.malonus.com/ebooks/computer_science/ (nice)
http://cip.uni-trier.de/jia/links/weball.htm
http://www.gorkhali.com/kamal/download.htm
ftp://ftp.runnet.ru/BOOKS/

Happy reading.......

Bye

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 :-
[code]
#global parameters...
subnet 10.105.0.0 netmask 255.255.128.0 {
# subnet-specific parameters...
range 10.105.13.101 10.105.13.210;
option routers 10.105.1.250;
option THINTUX_SESSION_SERVER "10.105.11.23";
option THINTUX_SCREEN_RESOLUTION "800x600";
option THINTUX_SCREEN_COLOR_DEPTH "8";
}
group {
#group-specific parameters...
host abc.iitb.ac.in {
#host-specific parameters...
}
}
[/code]
Configuring using config-dhcpd :-
1. http://config-dhcpd.sourceforge.net/

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 10.105.11.23

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>

http://thintux.sourceforge.net/


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
image=/root/thinlinux
label=thin-linux
read-only


Client that doesnot contain Linux OS
For all the following steps you have to use Dos Bootable Floopy
containg fdisk, format, syslinux.com 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

Links
http://thintux.sourceforge.net
http://www.dhcp.org
http://www.dhcp-handbook.com/dhcp_faq.html
http://syslinux.zytor.com
http://www.vlug.org/vlug/meetings/X-terminal_presentation/overview.html

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
network.http.pipelining.maxrequests

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
loading.

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!

Vaibhav.

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

Deleting
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

Arthemetic
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> )
R<Charcter>

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)