Sunday, May 25, 2008

Cscope

I was first introduced to cscope through my job at Cisco. At that time, I never cared much about it. But now I realize it's one of the major productivity enhancement tools where source navigation through a pile of code written by many other people is concerned.

http://cscope.sourceforge.net/

This document provides a tutorial on how to set up cscope for large projects, using the example of the linux kernel.

http://cscope.sourceforge.net/large_projects.html

And this document teaches how to use cscope very efficiently from within vim.
http://cscope.sourceforge.net/cscope_vim_tutorial.html

Also, there are many other frontends to csope besides the simple ncurses based one. Try kscope.

http://kscope.sourceforge.net/

.

Tuesday, May 6, 2008

Next Laptop PowerPro P 11:15 (based on Compal JFL92)

In a previous post I was looking at my next laptop and considering Sager NP 2092 for the same. ( http://varghese85-cs.blogspot.com/2008/03/next-laptop-sager-np2092.html )

This laptop is a Sager rebranding of the Compal JFL92 laptop. However, since I read on a few forums about sluggish customer support from Sager, I was getting a bit worried.

Now I realize that PowerNotebooks.com (http://www.powernotebooks.com/), the retail outlet from where I planned to buy the Sager NP2092 has an in-house rebranding of the Compal JFL92: PowerPro P 11:15 (http://www.powernotebooks.com/category.php?catId=78#id2269)

PowerNotebooks.com is an online retailer for whom I found the customer ratings to be impeccably excellent. The company seems top notch, and hence I am happy that I can get the Compal JFL92 which I wanted, with a reasonable assurance of reliable customer support.

Customisations I am going for:
- 1680x1050 WSXGA+ MATTE LCD
- Intel Core 2 Duo 2.1 GHz processor
- 2GB (2x1GB) memory
- 250GB SATA 5400rpm hdd
- Bluetooth
- RainShield Backpack black/silver
- NO Windoze XP / Vista (I'll run OpenSUSE 11.0 !!)

Also, check this thread (http://forum.notebookreview.com/showthread.php?p=3320508)
Owners of Compal JFL92 have confirmed linux compatibility for the JFL92. Hence I'm delighted.

Other pertinent posts (these are on the IFL90 though)
http://lddubeau.com/avaktavyam/linux-on-a-compal-ifl90/
http://tiago.estima.googlepages.com/Install_log_Linux_OpenS.html

--------- --------- --------- --------- --------- --------- --------- ---------
This one seems to be the same compal JFL92 with ubuntu pre-installed.
(Check the last option, titled "Serval Performance")
http://system76.com/index.php?cPath=28

.

The Linux Kernel book

http://www.linuxhq.com/guides/TLK/tlk.html

Looks like a good resource to learn the linux kernel..

.

Wednesday, April 30, 2008

gparted vs partition magic

Guess Partition magic is familiar to most folks around.

However, I wanted an Free Open Source solution addressing the same purpose.

My searches have led me to parted
(http://www.gnu.org/software/parted/index.shtml)
and it's gui-enabled frontend gparted
(http://gparted.sourceforge.net/)

There's a gparted live cd,
(http://gparted.sourceforge.net/livecd.php)
which is a bootable linux cd which takes you straight to the gparted gui.

Also, gparted is available on the "SystemRescueCd" liveCD distribution.
(http://www.sysresccd.org/Main_Page)

Also, here's a good link on using gparted to partition hard drives on Windows Vista preinstalled laptops.
(http://www.howtogeek.com/howto/windows-vista/using-gparted-to-resize-your-windows-vista-partition/)

.

Saturday, April 26, 2008

Video lectures on computer science

http://freescienceonline.blogspot.com/

.

Programming from the ground up

An apparently good resource for programming in assembly under linux.

Bartlett, Jonathan - Programming from the Ground up

This is the first book I've seen so far on assembly programming using the gnu toolset.
And the book is available as soft copy under GPL

http://programminggroundup.blogspot.com/2007/01/programming-from-ground-up.html
http://savannah.nongnu.org/projects/pgubook/

Thanks again to my friend Haynes for pointing me to this.

.

Thursday, April 3, 2008

Devpit

This looks like a repository for all kinds of developer's info (*nix primarily)

http://devpit.org/wiki/Main_Page

As they describe themselves: http://devpit.org/wiki/Devpit:About

.

Monday, March 31, 2008

xournal - just what I wanted !!

I have had two independent requirements for wish I have long wished I had some applications.

One was for note taking.. I was trying to use notepad for note taking.. But then, unlike on a notebook, there was no quick way for drawing rough figures alongside my notes.. Paint wouldn't fit the bill either because, I can not go on taking notes endlessly.. And now that I'm moving on to linux (with bias for KDE) kate and krita are the analogues, and they wouldn't fit the bill either.

The second was regarding PDF files.. I was finding a major difficulty in getting accustomed to PDF files rather than printed matter because I could mark, highlight, underline etc; annotate in general, on printed matter, but not on pdf files.

One fine day, I was browsing through the kmenu on my opensuse virtual box, and bingo ! I came upon xournal. The claims were big, but the default version bundled with OpenSUSE 10.3 didn't work.

Somehow, I'm grateful that my lazybones didn't kick in, but instead I searched an located the sourceforge site for the xournal project: http://xournal.sourceforge.net/

From there, I got the latest version source+binary package, and installed that.. And yes! all my problems are solved. The software allows me to take notes, and draw on the same canvas; take notes on multiple A4 pages, bundled as a book; open a pdf and annotate the same; and export my notes/my annotated pdf back to pdf !

In sum, xournal is simply what I've been looking for !!!

--------- --------- --------- --------- --------- --------- --------- ---------
Monday 2008-03-31 12:14 UTC+5:30

On a further note; how to handle pdf encrypted files..
[Attribution] This I took from a post on the sourceforge xournal forum.
The pdftops command can be used to decrypt and convert a pdf to a ps file.
pdftops -upw {password} file.pdf file.ps
Thereafter, the ps2pdf command can be used to convert the ps back to an unencrypted pdf.
ps2pdf file.ps file.pdf 
Note that, xournal doesn't come into the picture here at all.

.

Sunday, March 30, 2008

Skype to the rescue ?

In my linux migration, one of the biggest obstacles I have been facing was the lack of a reliable, free messenger allowing voice and video.

Looks like skype will solve that problem for me.

Skype has versions for linux as well as windows. Just installed the linux version; voice works fine.. Can't check out video right now as I don't have a linux compatible webcam..

Anyways, if I can get my parents to use skype too, then one major issue gets sorted out..
And as a bonus, skype allows conference calls too !

.

Webmin for configuring linux

Had tried Debian Etch, and was wondering how to configure firewall etc using GUI.

Looks like Webmin is a good solution

However, for now I guess I'll stick with opensuse.
Somehow liked it more than any other distros so far.

.

Saturday, March 29, 2008

L4 microkernels

So much for the monolith that the linux kernel has become!
Stallman and team are working on speeding up hurd on top of the mach microkernel..

But then, mach is a first generation microkernel..
And subsequently, the L4 was designed to overcome the insufficiencies of mach.

Looked at this wikipedia page on l4 microkernels: L4 Microkernel Family
It took me to Fiasco (http://os.inf.tu-dresden.de/fiasco/), a GPL variant of L4.
And know what !
- Fiasco's done in C++ !
- There's an ongoing GNU project for Hurd on L4 !

The TUDOS wiki page
http://wiki.tudos.org/Main_Page

Planning to learn more on L4..
Although I must confess, my learning ventures are not progressing the way I want them to,
this one being built on C++ should help I hope..

More links:
The home of the l4 community: http://www.l4hq.org/

--------- --------- --------- --------- --------- --------- --------- ---------
Sunday 2008-03-30 22:53 UTC+5:30

Somehow I felt I should include this here as a tribute to the genius
Prof. Dr. Jochen Liedtke
http://i30www.ira.uka.de/aboutus/people/liedtke/inmemoriam.php

.

Thursday, March 27, 2008

Encrypted filesystems

This one's further to my two previous posts concerning losetup
1. Virtual Drives on Linux
2. Playing with mount and loopback devices

Here we try to create encrypted file-systems using the dm_crypt modules.
These are the wikipedia links for cryptoloop and it's successor dm_crypt.

In the earlier cases, we have a file-resident filesystem. We interface it with a loopback device to access it as a device, and the mount it to access it.Now, we incorporate one more block; one which acts as our encryption layer.
Ok, that's enough of the theory; lets roll up our sleeves and get our hands dirty.
So first, we create a 100 mb file for our filesystem
dd if=/dev/zero of=testfile bs=512k count=200
Next, we attach that to a loopback device
losetup /dev/loop0 testfile
Now, we add our encryption layer
cryptsetup -c aes -y create secret /dev/loop0
Or you might use aes-cbc-essiv:sha256 for encryption layer.

Note that in the above, -y option will cause the passphrase to be asked twice for verification. The above command will result in /dev/loop0 being mapped post encryption to the device /dev/mapper/secret.

The command is the same each time you need to mount the loop device; only, the first time you give the passphrase, it becomes _the_ passphrase.

(Internally, cryptsetup doesn't seem to care if your passphrase matches what you used earlier. It just dumbly setups up the encryption layer with the passphrase you provde. So, if you give the correct passphrase second time and every subsequent times, you can access what you already have on the device. If you give a wrong passphrase, you can't. Eitherways, cryptsetup doesn't care! But then, if your passphrase is wrong on second and subsequent times, mount won't work as it can't make sense out of the superblock)

Also, to use a native partition as the encrypted filesystem, instead of a file-resident-filesystem, use the appropriate device name instead of /dev/loop0. In such a case, the previous steps can be omitted.

Next, you make a filesystem on the device; We'll use ext2. Note that you do this only the first time. Subsequent times, you can just skip this step as you already have the filesystem set up.
mkfs -t ext2 /dev/mapper/secret
Now, we mount the device
mount -t ext2 /dev/mapper/secret {mount-point}
Once mounted, you can use the device just like any other device. The encryption and decryption are transparent to you.

Once you are done, you need to clean up

Unmount the device secret
umount {mount-point}
Disassociate the crypto layer
cryptsetup remove secret
sync
You need to atleast do the above cleanup steps to prevent the misuse of your encrypted filesystem, and to preserve its integrity. This next step of disassociating the loopback device is optional, unless you need to reuse the loopback device for something else.
losetup -d /dev/loop0
There are many other options other than "cbc" for the encryption algorithm. Please refer to the cryptsetup manpage and to various related online pages for the options and their advantages.

The dm_crypt wiki for further details: http://www.saout.de/tikiwiki/tiki-index.php

Likewise, if you need to use a physical drive / partition rather than a flat file, you will need to know the device that linux maps it to. Use the command
dmesg | tail
to find the device corresponding to the removable drive you plugged in.

--------- --------- --------- --------- --------- --------- --------- ---------
Friday, 2008-03-28 22:59 UTC+5:30

Additional to that
1. My friend had to
modprobe dm_crypt
modprobe dm_mod
before this would work for him

2. to change password of the encrypted device (say /dev/loop0 )
# create a device mapping using the old password
# remember to use old password here
cryptsetup -c aes -y create secret-old /dev/loop0

# create another device mapping using the new password
# remember, this will be your password hereafter
cryptsetup -c aes -y create secret-new /dev/loop0

# now copy block-by-block from old mapping to new mapping
dd bs={block-size} if=/dev/mapper/secret-old of=/dev/mapper/secret-new

# cleanup
# Actually you can remove the old mapping and continue using the
# new mapping if you'd like
cryptsetup remove secret-old
cryptsetup remove secret-new
References
[1] http://forums.gentoo.org/viewtopic.php?t=163762

.

Monday, March 24, 2008

Virtualization and Virtual machine monitors

pages on this topic..

Hypervisors a.k.a. Virtual Machine Monitors

The XEN Hypervisor

x86 virtualization

Virtual Machine

VirtualBox (this one's GPL)

This also seems like a viable research area !

.

Sunday, March 23, 2008

Printing to pdf file on linux

The easiest way to do it is
1. Print whatever to file.. This produces a ps file (.ps extension preferred)
2. Convert the postscript to pdf with ps2pdf command
However, I also wanted to try setting up a pdf printer, primarily because I remember the redhat 9, which I used to use once a long long time ago, to have had one.
To do it this way on OpenSuSE 10.3
1. Download and install the cups-pdf package.. You can find an RPM if you search on http://rpmfind.net.. OpenSuSE 10.3 doesn't seem to have an rpm for this.
2. If using kde, go to: kmenu > utilities > printing > manage printers. Gnome should have something similar.
3. There, choose to add a new printer..
4. In the step 1 there, choose the "Virtual PDF printer"in the detected list.
5. In the step 2 there, choose "Generic" for manufacturer, "postscript printer" or "PostScript color printer rev4" as model, and "Standard" as driver..
6. Apply.. Your new printer should now become listed
7. Right click on the new printer and choose properties. There, fiddle around and configure things as you want. Once you are done, click print test page.
8. The pdf generated is saved to your home folder.

Now on, you can use this printer to print to pdf file from any application. The generated pdf is saved in your home directory with the filename ".pdf"
.

A tab on linux preinstalled and NO-OS pcs

As it's not particularly helpful that the standard vendors etc keep their Linux preloaded laptop pages not properly linked to the main page, I've decided to make this collection

Do help me make it bigger :) Post a comment if you find other URLs

Lenovo thinkpad on Linux

Dell on Ubuntu

ASUS Eee PC (catch: this is a 7" screen, 2gb-8gb solid state hard drive)

Will be updated with more !

.

OS Support for Intel Wireless cards

Found this link upon a bit of googling..
Am thinking 4965 a/g/n card and was worried if that is supported on linux..

http://www.intel.com/support/wireless/wlan/sb/CS-025330.htm

Posting it here to keep a tab on it..

.

Playing with mount and loopback devices

Here, I managed to mount some swap space through a file, which I mounted as a loopback device

# creating the file to setup the swap on.
varmathe@opensuse103-vm:~> dd bs=1024 if=/dev/zero of=./testfile count=102400
102400+0 records in
102400+0 records out
104857600 bytes (105 MB) copied, 4.25891 s, 24.6 MB/s

# for the rest, I need to be root
varmathe@opensuse103-vm:~> su
Password:

# mounting the file as a loopback block device.
opensuse103-vm:/home/varmathe # losetup /dev/loop0 testfile

# formatting the device as swap space
opensuse103-vm:/home/varmathe # mkswap /dev/loop0
Setting up swapspace version 1, size = 104853 kB
no label, UUID=853895fe-e4cf-4741-8106-cc7e88f89210

# asking linux to use that too for swap
opensuse103-vm:/home/varmathe # swapon /dev/loop0


Here is another example where I manage some more playing around with losetup


# Creating a 10 mb disk image. It's just a file of size 10mb full of zeros.
varmathe@opensuse103-vm:~> dd bs=1024 if=/dev/zero of=./testfile count=10240
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 1.03734 s, 10.1 MB/s

# Now on, I'm root
varmathe@opensuse103-vm:~> su
Password:

# Setting up the loop device
opensuse103-vm:/home/varmathe # losetup /dev/loop0 ./testfile

# Creating an ext3 filesystem on the loop device.
opensuse103-vm:/home/varmathe # mkfs -t ext3 /dev/loop0
mke2fs 1.40.2 (12-Jul-2007)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
2560 inodes, 10240 blocks
512 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks:
8193

Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

# creating a folder to mount the device on.
opensuse103-vm:/home/varmathe # mkdir test-point

# mounting..
opensuse103-vm:/home/varmathe # mount -t ext3 /dev/loop0 ./test-point/

# Dumping a file there..
opensuse103-vm:/home/varmathe # cd ./test-point/
opensuse103-vm:/home/varmathe/test-point # ls
lost+found
opensuse103-vm:/home/varmathe/test-point # cat > testfile.txt << EOF
> this is a test file to check the making of
> the filesystem with loop devices thing
> hope this thingy will work
> if it does, this file will be reclaimable
> when I remount this filesystem
> EOF
opensuse103-vm:/home/varmathe/test-point # ls
lost+found testfile.txt

# Unmounting the device..
opensuse103-vm:/home/varmathe/test-point # cd ..
opensuse103-vm:/home/varmathe # umount test-point/

# Disassociating the loopback..
opensuse103-vm:/home/varmathe # losetup -d /dev/loop0

# Reassociating..
opensuse103-vm:/home/varmathe # losetup /dev/loop0 ./testfile

# mounting again..
opensuse103-vm:/home/varmathe # mount -t ext3 /dev/loop0 ./test-point/

# Ah yes, it's all still there..
opensuse103-vm:/home/varmathe # cd test-point/
opensuse103-vm:/home/varmathe/test-point # ls
lost+found testfile.txt
opensuse103-vm:/home/varmathe/test-point # cat testfile.txt
this is a test file to check the making of
the filesystem with loop devices thing

hope this thingy will work
if it does, this file will be reclaimable
when I remount this filesystem


Thursday, March 20, 2008

Debian KDE

To install Debain Linux with KDE on your system, use the command

install tasks="kde-desktop, standard"

at the boot prompt.

If you would also like to make use of the graphical installer, you can try the command

installgui tasks="kde-desktop, standard"


Reference
http://pkg-kde.alioth.debian.org/kde3.html

.

Wednesday, March 12, 2008

Writing bootsector - The GNU "as" (aka gas) way

My friend Haynes pointed me to this quick hands on tutorial..

http://susam.in/articles/boot-sector-code.php

Simple, brief and neatly explained tutorial on how to write bootsectors with GNU tools for the x86 architecture.


Also, objcopy can be used to convert between binary formats.

--------- --------- --------- --------- --------- --------- --------- ---------
Sunday 2008-03-30 02:19 UTC+5:30

I used the snippet of code given at the above webpage
# Author: Susam Pal 
#
# To assemble and link this code, execute the following commands:-
# as -o char.o char.s
# ld --oformat binary -o char char.o
#
# To write this code into the boot sector of a device, say /dev/sdb:-
# dd if=char of=/dev/sdb
# echo -ne "\x55\xaa" | dd seek=510 bs=1 of=/dev/sdb

.code16
.section .text
.globl _start
_start:
mov $0xb800, %ax
mov %ax, %ds
movb $'A', 0
movb $0x1e, 1
idle:
jmp idle
Assembled and linked the same using the commands given in the comment part of the code.
Then, had the ".com" file pushed into a floppy image file. And it worked !

When I pushed the binary into a floppy image formatted as "mkfs -t vfat", the filesystem went corrupt
even though the booting was successful. When I tried formatting the floppy as ext3, everything worked
and the filesystem was also preserved. Wondering why writing the bootsector corrupted the vfat filesystem.

Used qemu to test the stuff !!

.

OpenSuSE 11.0 on Jun 19

http://en.opensuse.org/Roadmap/11.0

Target release date for OpenSuSE 11 is jun 19th 2008 !!

Waiting for this !!

.

Tuesday, March 11, 2008

GNU as a.k.a. Gas

My first assembly program ..
Ah it sux, but demonstrating how to use Gas, gdb etc. with a program which is too simple, anyone would understand..
varmathe@opensuse103-vm:/temp/varmathe> cat test.S
/*
* First gas assembly program by Varghese Mathew !
* simply to add two numbers on the x86
* Purpose: demonstrate the usage of gas, gdb etc
*/

.global main /* define the main to be callable from libc */
.text /* text segment */
main: /* the prodigal main function */
movl $100, %eax # load 100 in eax
movl $200, %ebx # load 200 in ebc
addl %eax, %ebx # add the two and store in ebx

/* the end */

varmathe@opensuse103-vm:/temp/varmathe>
varmathe@opensuse103-vm:/temp/varmathe>
varmathe@opensuse103-vm:/temp/varmathe> gcc -g test.S
varmathe@opensuse103-vm:/temp/varmathe>
varmathe@opensuse103-vm:/temp/varmathe> gdb a.out
GNU gdb 6.6.50.20070726-cvs
Copyright (C) 2007 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb)
(gdb) break main
Breakpoint 1 at 0x8048394: file test.S, line 10.
(gdb) run
Starting program: /temp/varmathe/a.out

Breakpoint 1, main () at test.S:10
10 movl $100, %eax # load 100 in eax
Current language: auto; currently asm
(gdb) info registers
eax 0x1 1
ecx 0xbfa61264 -1079635356
edx 0xbfa61200 -1079635456
ebx 0xb7edbff4 -1209155596
esp 0xbfa611dc 0xbfa611dc
ebp 0xbfa61238 0xbfa61238
esi 0xb7f25ca0 -1208853344
edi 0x0 0
eip 0x8048394 0x8048394

eflags 0x200246 [ PF ZF IF ID ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
(gdb) info reg eax
eax 0x1 1
(gdb) info reg ebx
ebx 0xb7edbff4 -1209155596
(gdb) n
11 movl $200, %ebx # load 200 in ebc
(gdb) info reg eax
eax 0x64 100
(gdb) info reg ebx
ebx 0xb7edbff4 -1209155596
(gdb) n
12 addl %eax, %ebx # add the two and store in ebx
(gdb) info reg eax
eax 0x64 100
(gdb) info reg ebx
ebx 0xc8 200
(gdb) n
0x080483a0 in __libc_csu_fini ()
(gdb) info reg eax
eax 0x64 100
(gdb) info reg ebx
ebx 0x12c 300
(gdb) c
Continuing.

Program exited with code 0144.
(gdb) q
varmathe@opensuse103-vm:/temp/varmathe>


.

Sunday, March 9, 2008

Usenet newsgroups / NNTP

What do I say, a powerful but forgotten resource !

To all my friends who read this page, try the usenet newsgroups.

To try..
1. Download and Install mozilla thunderbird.
2. Click cancel when it initially asks you to set up an account (just to do it the "usual" way)
3. go to Tools > Account Settings, for windoze (maybe so named because it puts the brain to sleep)
or to Edit > Account Settings, for Linux (ah even she's not the best courtesan, waiting for hurd)
4. There, click on the Add account button.
5. choose newsgroup account, and next.
6. Enter the name you want displayed, and a syntactically valid email address; next.
7. NNTP server "aioe.cjb.net"; next
Thank god, there's someone hosting a free server allowing posting..
If you know more, please add as a comment..
8. Give a name if you want to, or use the default; finish.
9. Now you have an aioe.cjb.net entry on your left pane. Right click on it and choose subscribe.
10. Subscribe to "alt.test"
11. now, you have an alt.test entry under aioe.cjb.net on the left pane. Click on it. It will ask you to download headers. Choose to download some 10 or so max.
12. Now, while having the alt.test folder selected, click on the write button on the top left. compose a test post and send it to alt.test.
13. After sometime / once you open and close thunderbird, your post should show up in alt.test.

Configure thunderbird further to check the news group for new messages on startup and every 10 minutes etc. I'm not detailing these.. Also download a larger number of headers if you want to browse archives

alt.test is a newsgroup for sending test posts etc.. it's not worth browsing the alt.test archive.. people use it to send test posts to verify connectivity. now that you have the newsgroups set up, you can unsubscribe from this group..

Check out the many wonderful groups ranging from comp.os.minix to comp.lang.c++ to alt.os.development to alt.hobbies.* to sci.math.* to misc.kids.pregnancy to whatever you want !

You will be overwhelmed by the expanse of the resource which you never until now knew existed !

--------

On further thoughts, the server "textnews.news.cambrium.nl" might be a better choice for digging archives, but you can't post - it's read only.. or you can use the google groups thingy to dig deepest.. But posting the usenet way far surpasses the google groups experience.

--------

A page on usenet http://www.openusenet.org/

some paid news-servers (keeping a track, just in case i need later in life.)

http://www.newsfeeds.com/ Uses a seemingly secure payment gateway.

http://www.octanews.com/ have to give credit card info directly - is this safe ?
http://www.teranews.com/ have to give credit card info directly - is this safe ?
http://www.bubbanews.com/ have to give credit card info directly - is this safe ?

This one's free but seems to be down often http://www.readfreenews.net/

A further list of servers http://news.aioe.org/spip.php?article26

.

Linus vs. Tanenbaum

Found couple of links for the 1991 ish time mega debate between Linus Torvalds and Andy Tanenbaum on Microkernel vs. Monolithic kernel.

On groups.google.com

A hosted version

I really got to say, that guy Andrew Tanenbaum is a visionary !! But alas, the world is a non-pseudo random number generator !

.

Saturday, March 8, 2008

alt.os.development

Hit upon this usenet newsgroup through some other osdev website. Seems like a hangout for hobbyist OSDevelopers.

And this is a compilation of various content, sites etc that came across through alt.os.development over time.. Looks good, looks huge.. :D
http://www.aarongray.org/AODUBL/bookmarks.html

comp.os.minix is also a good hangout; though this one's specifically for minix, historically, it's where linux was born :D

.

The PC booting process

A certain mjvines had this explanation as a comment in his bootsector tutorial example. Thanks to him.. Just pasting it here lest I forget at a later point in time.

; Here's a quick summary of what the BIOS does when booting up.
;
; 1) Loads Sector 1, Track 0, Head 0 of the boot drive( A or C ) to
; absolute address 07C00h-07DFFh
;
; 2) Checks the 16 bit word at absolute address 07DFEh for AA55h. This is
; the boot signature and is used by the BIOS to ensure that the sector
; contains a value bootsector.
;
; If this signature isn't present, the BIOS will display a message like
; "Operating System Not Found"
;
; 4) Loads DL with
; 00h if the boot sector was loaded from drive A,
; 80h if the boot sector was loaded from drive C
;
; This way, the bootsector can determine which drive it was booted from.
;
; 5) Jumps to 0000:7C00h, which is the start of the bootsector

Link: http://gaztek.sourceforge.net/osdev/boot/index.html

And on top of that, remember reading somewhere.. A CD boot is done by actually having a floppy image at the beginning of the cd.. This floppy image is loaded as a ramdisk and the ramdisk is used for the booting.. Can't remember the reference nor the exact details off the top of my head right now :(
Update: Found one reference now http://www.tldp.org/HOWTO/Bootdisk-HOWTO/cd-roms.html
http://en.wikipedia.org/wiki/El_Torito_(CD-ROM_standard)

While still on bootloaders, a good tutorial on using grub by Christopher Giese.
http://my.execpc.com/%7Egeezer/osd/boot/grub-how.txt

.

Friday, March 7, 2008

osdev/crossgcc first try

Started working on learning to build a custom OS. First step is the cross compiler. Went to the GCC Cross-Compiler page on osdev-wiki. That page lists the steps to get my cross compiler up and running.

Got the binutils, gcc-core and g++ sources.. Created a new login on my linux box and set it up as recommended in the LFS tutorial, to have minimal environment.. This was my pure whim :D.

Then went by the steps mentioned in the osdev page; made my binutils; made my gcc.. Then came the problem.. What libc to use?

Tried PDClib but found it lacking in cross compilation support etc.
Then got a newlib downloaded and built that.. It seems to have worked..

Then recompiled the gcc with headers.

And once all that was done, your's truly tried to compile a very simple .c file using the cross-compiler..

The linker failed saying no crt0.o !

crt0.o

hm.. vaguely remember something about crt0.o from my hardware classes at NITC.. or was it from some unix system programmer's reference I read back at college?

Anyways.. searched on the osdev wiki.. Hit a page on how to install "newlib" !! Now that could have helped me a little earlier :D.. I just broke my head figuring out what was already documented :D..
doesn't harm.. things learned the hard way stick longer :)

But coming back, somebody had cooked up a simple crt0.S on that page.. used that..

And know what! IT WORKED !!

Well, not exactly.. ld still cribs about missing syscall wrapper function definitions..
I need to take the newlib-libc-documentation, go to chapter 12 - Syscalls, and then either implement wrappers for each of those syscalls (thankfully not too many) aimed at my kernel (ah, but I still haven't even started thinking about it !! ) .. or I have to provide a set of stubs for those syscalls .. or maybe route those syscalls to my hosts syscalls ( possible in this case because my host is a Centrino processor, and my cross compiler target is i586 :D )

Anyways.. so far so good..

But there are some things which still worries me..
1. I still don't know shit about that newlib internal implementation and it's source is over 11 Megs !!
2. I did a "du -sh" on the final build environment I have (excluding all intermediate files) and it's a whopping 162 Megs.. Guess programmers really have lost the ability to make efficient code, as Andrew Tannenbaum puts it.
3. What if the present generation who maintains glibc, gcc, binutils, newlib etc dies out and it's the next generation's turn to maintain all of that.. my generation's turn.. Will there be anyone left who has a holistic understanding of all that code to maintain it ?

Ah, but I'm a small fry making too much noise; and staying up at 4:30 AM to set up a cross compiler.. no wonder I'm an oddity.. maybe that explains why I still don't have a girlfriend :D

.

A collection of free clip-art images on the web..

http://www.wpclipart.com/

.

Links for Operating System Development

Sorry, this is a bit unorganized.. I'm just starting out on this arduous peregrination :D.. Hope to keep the momentum going.. If that happens, you can hope to see more detailed step by step, for the dummies instructions here.. But till then..

OSDev.org

The Operating System Resource Center

Gareth Owen's OSDev site at sourceforge

Bran's Kernel Development

How to write your own OS: part 1, part 2.

http://my.execpc.com/~geezer/osd/index.htm

http://www.osdever.net/


Assembly Language: intel x86

The Art of Assembly Language

Linux assembly guide

Links for assembly programming

http://library.n0i.net/hardware/

.

Wednesday, March 5, 2008

Full Screen issue with mplayer

I was having a small issue with mplayer.. When I full screen the video, the whole screen is occupied, as in the screen goes black, but the video is played still at the original resolution in a small rectangle in the center.

As always, google saved the day..

http://ubuntuforums.org/archive/index.php/t-204.html

A "-zoom" parameter needs to be passed to mplayer, to zoom the video to the window size.

Alternatively, a config file can be set up for mplayer as

##
## MPlayer config file
##
## This file can be copied to /usr/local/etc/mplayer.conf and/or ~/.mplayer/config .
## If both exist, the ~/.mplayer/config's settings override the
## /usr/local/etc/mplayer.conf ones. And, of course command line overrides all.
## The options are the same as in the command line, but they can be specified
## more flexibly here. See below.
##

vo=xv # To specify default video driver (see -vo help for
# list)
ao=oss # To specify default audio driver (see -ao help for
# list)

fs=no # Enlarges movie window to your desktop's size.
# Used by drivers: all

vm=yes # Tries to change to a different videomode
# Used by drivers: dga2, x11, sdl

bpp=24 # Force changing display depth.
# Valid settings are: 0, 15, 16, 24, 32
# may need 'vm=yes' too.
# Used by drivers: fbdev, dga2, svga, vesa

zoom=yes # Enable software scaling (powerful CPU needed)
# Used by drivers: svga, x11, vesa

#double=yes # use double-buffering (recommended for xv with
# SUB/OSD usage)

# monitoraspect=4:3 # standard monitor size, with square pixels
# monitoraspect=16:9 # use this for widescreen monitor! non-square pixels

##
## Use GUI mode by default
##

gui = yes
The zoom=yes line is what we need to fix the issue.
And on that "Powerful CPU needed" line, a 640x480 DivX video zoomed to 1024x768 will probably require a 1.2 GHz processor at most.

.

Next Laptop.. Sager NP2092 ?

This post has been obsoleted by http://varghese85-cs.blogspot.com/2008/05/new-laptop-powerpro-p-1115-based-on.html
--------- --------- --------- --------- --------- --------- --------- ---------

Had been thinking sometime about which laptop to buy when I go for higher studies. Had a fixation for the IBM Thinkpad. Was planning to buy it.. And the Lenovo T61 can be bought direct from Lenovo with Linux preloaded rather than the Microsoft Proprietory OS. Yet only flaw was, that does not have an integrated webcam.

Further hunting has led me to this laptop, Sager NP 2092
http://www.powernotebooks.com/category.php?catId=78#id2296

Sager, as wikipedia mentions it, is a retailer specializing in performance laptops for gaming purposes. And of-course, a performance laptop for gaming is a performance laptop for any conceivable purpose :D

The ODM of the specified laptop is Compal which is the world's second largest laptop maker. This particular Sager laptop is built on top of the Compal JFL 92..

Pictures: http://www.powernotebooks.com/specs/images/2090/

Found this blog on installing linux on the immediate predecessor model of this laptop
http://lddubeau.com/avaktavyam/linux-on-a-compal-ifl90/

Planning to buy the laptop from powernotebooks.. They seem to have a good reputation online.. And most importantly, they sell the "NO-OS" version of the laptop, so I won't need to pay microsoft for a license which I will not use anyway.

Further reading..
About "Brands" for laptops: http://www.powernotebooks.com/articles/index.php?action=fullnews&id=17
About the dead-pixel policy:
http://forum.notebookreview.com/archive/index.php/t-85367.html
http://forum.notebookreview.com/showthread.php?t=62496
http://forum.notebookreview.com/showthread.php?p=1404255

Also, Hum X ground loop eliminator, if I understand right, is a piece of circuitry integrated into the plug-point, and not into the notebook. Hence I guess, I'll not buy it right off, and buy it if I find a need for it later..

.

Monday, March 3, 2008

Ext2Fsd vs NTFS-3g

A tool to mount ntfs devices on linux. I have tried it out.. works fine both for reading and writing.

http://www.ntfs-3g.org/

You might have to compile the thingy from source.. but it's rather simple.. and compiled without any issues on my OpenSuSE 10.3 installation.

But then, I've started thinking.. If I'm planning to keep a pure linux box (Yeah yeah, I caught Penguinitis ! ), then I might as well have my storage devices as ext3 and get an ext3 driver for windows..

Tried wikipedia on Ext3, and bingo! it had a link to the sourceforge project developing a windows driver for using ext3 devices.

http://sourceforge.net/projects/ext2fsd/
http://www.ext2fsd.com/

Albeit the name it fully supports ext3 devices..

Once you install it, you need to go to it's "Ext2 volume manager".
From that
1. File -> Enable Ext2Mgr autostart
2. Tools -> Service Management : and start the service.

Once these are done.. plug in your ext3 devices and use them like any other storage media on windows.

I converted my 2GB usb pen drive to ext3 and am using that on windows with ext2fsd.. Call it "Proof of Concept" for myself in my tux migration drive.. :D

.

Sunday, March 2, 2008

Linux support matrix for webcams

This site gives support matrix and driver information about
using webcams with linux

http://linux-uvc.berlios.de/

Unfortunately for me, I have a
"046d:08c7 - Logitech Quickcam OEM Cisco VT Camera II"
:(

--------- --------- --------- --------- --------- --------- --------- ---------
Sunday 2008-03-30 12:19 UTC+5:30

A link about setting up logitech webcam for OpenSuSE 10.3
http://forums.quickcamteam.net/showthread.php?tid=212

Another link on logitech webcams
http://www.quickcamteam.net/hcl/linux/logitech-webcams

.

Friday, February 29, 2008

Virtual drives on linux

One of the issues I was facing in my linux migration efforts was how to create and use virtual drives, so that I can mount ISO images of CDs etc.

So here is how to do it..

Virtual devices are achieved in linux using loop devices.
To create a new loop device, we use the losetup command. For eg. say we need to mount the cd image file /temp/varmathe/damn-small-linux.iso ad a cd drive. Here is how to do it.

1. Locate the first available loop device
opensuse103-vm:/temp/varmathe # losetup -f
/dev/loop0
2. Associate this device node to the iso file
opensuse103-vm:/temp/varmathe # losetup /dev/loop0 damn-small-linux-3.4.4.iso
3. Now mount the cd somewhere on our filesystem hierarchy.
opensuse103-vm:/temp/varmathe # mount -t iso9660 /dev/loop0 /mnt/vcd
opensuse103-vm:/temp/varmathe # cd /mnt/vcd
opensuse103-vm:/mnt/vcd # ls
boot index.html KNOPPIX lost+found
Additionally, it might be a wise idea to mount cd/dvd images etc as read only..

4. Use the volume.. (he he :D )

5. Now that we are done and want to unmount the device and release the file
opensuse103-vm:/temp/varmathe # umount /mnt/vcd
opensuse103-vm:/temp/varmathe # losetup -d /dev/loop0
The -d option detaches the file from the loop device

Steps 1,2, and 3 can be combined into a single step as
opensuse103-vm:/home/varmathe # mount -t iso9660 -o loop /temp/varmathe/damn-small-linux-3.4.4.iso /mnt/vcd
While the above single step approach looks like it should have been explained first; I deliberately explained the broken approach for a reason. If you only need the device node, say for eg, to pass that on to a virtual machine; then you don't need to do the mount.. The "losetup" steps alone would do.

.

Wednesday, February 20, 2008

C++ language standards

Find the official standards for the language at

http://www.open-std.org/jtc1/sc22/wg21/

A GPL licensed thorough c++ reference

http://www.icce.rug.nl/documents/cplusplus/

A bunch of open source c++ libraries

http://www.boost.org

.

Wednesday, February 13, 2008

Setting up qemu with networking on a linux host

I wanted to install Qemu with networking enabled on my linux box (Which incidentally is on a Virtual Machine built on vmware). Through the setting up process, I had a tough time figuring out how to go about with the whole thing as I could not find any single document which precisely described what I wanted. But anyways, now I've figured it all out.. And so I've decided to share whatever I've garnered with you through this post.

Objective: To set up Microsoft Windows XP on a Qemu simulated PC with an OpenSUSE 10.3 linux box serving as host.

Host machine: OpenSUSE 10.3 linux on Intel i386 based PC

Packages used:
qemu-0.9.1-i386.tar.gz : http://fabrice.bellard.free.fr/qemu/
vde2-2.1.6.tar.gz : http://vde.sourceforge.net/

I wanted to compile qemu from source, but apparently qemu needs the gcc3.x compilers whereas OpenSUSE 10.3 I have on my system has the gcc4.x version.

Step1: extract qemu-0.9.1-i386.tar.gz int '/' as root.

Step2: extract vde2-2.1.6.tar.gz into a temporary location and build it
./configure
make
and then as root

make install
Step3: (As root) set up a VDE switch with one port connected to the host using a tap interface
host$ vde_switch -s /tmp/switch -tap tap0 -m 666 [-daemon]

The "-daemon" part is option; it will cause vde_switch to run in the background, whereas, if you do not give it, you get access to the switch console
Step4: (As root) set up an ip address for the newly created tap interface on the host
host$ ifconfig tap0 10.0.0.1
Step5: set up our virtual machine. For this,
5.1 Create a working directory for the machine and copy bios files into it.
host$ mkdir qemu-vm
host$ cd qemu-vm
host$ cp /usr/local/share/qemu/{bios,vgabios-cirrus}.bin ./
5.2 Create a disk for the machine.
host$ qemu-img -f qcow win-xp.qcow 4G
5.3 Now start the virtual machine as follows, with the windows-XP CD in the /dev/cdrom drive. Have the Product key ready at hand.
host$ vdeqemu -L . -m 128 -boot d -hda win-xp.qcow \
-cdrom /dev/cdrom -soundhw all -localtime -M pc \
-net nic,vlan=0 -net vde,vlan=0,sock=/tmp/switch
here, "-m 128" gives the virtual machine 128 mb RAM
"-boot d" makes cdrom as the default boot device.. Later you can set this to "-boot c" once you have an OS installed on the hard disk, to make hard disk as the default
"-net nic,vlan=0" adds one network interface card onto the virtual machine
"-net vde,vlan=0,sock=/tmp/switch" connects the above NIC to the switch we created.

5.4 When the system boots up, install windows on this guest machine. You will notice that it has one ethernet adapter for which the cable is already plugged (to our switch as we specified).

5.5 Configure IP address on this interface so that this interface is on the same Network (subnet) as the host's tap interface. In our case, we use "10.0.0.2" as the IP. Also set the guest's default gateway as 10.0.0.1 and provide your service provider's DNS ip to the guest.
Step6: Now you can try pinging 10.0.0.1 from the guest and 10.0.0.2 from the host. You will see that the pings go through successfully. However, the guest still cannot access the internet. For this we need to set up NAT (Network Address Translation) on the host ( or some form of bridging b/w the tap0 interface and the host's eth0 interface)

Step7: (As root) Set up the NAT.
host$ echo "1" > /proc/sys/net/ipv4/ip_forward
host$ iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
host$ iptables -A FORWARD -i tap0 -o eth0 -j ACCEPT
host$ iptables -A FORWARD -i eth0 -o tap0 \
-m state --state RELATED,ESTABLISHED -j ACCEPT
Now we are up and running!!



References:
[1] http://wiki.virtualsquare.org/index.php/VDE_Basic_Networking

.

Tuesday, February 12, 2008

FreeBSD

Check out the freeBSD operating system.

Another member of the family of UNIX operating systems.

Ports to most common comp architectures available.

http://www.freebsd.org

.

qemu

A sexy emulator !

Qemu: http://fabrice.bellard.free.fr/qemu/
Qemu for Windows: http://www.h7.dion.ne.jp/~qemu-win/

This program can emulate x86, MIPS, Sparc, ARM, PPC etc. I tried both the windows and linux x86 versions.. on the windows version, I tried loading a linux livecd.. And on the linux version, I tried out Windows XP

The project is still under development though.. Some bugs here and there are evident. I didn't like the networking support for the thingy. And I hate having to type out configs.. vmware virtualPC etc are gorgeous for their GUI alone, I'd say. Yet, neither vmware nor virtualPC support that entire gamut of processors, and best of all, this thing is FREE !

------------------------------------
Related links I found to be useful..

The OpenVPN tool which can be used for host-only networking / bridged networking on a windows host: http://openvpn.net/
- a how to for the same: http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html

VDE - Virtual Distributed Ethernet, to use for host-only / bridged networking on linux hosts: http://vde.sourceforge.net/
- how to: http://wiki.virtualsquare.org/index.php/VDE_Basic_Networking

.

autobook

A free online book on Autoconf Automake and Libtool..
http://sourceware.org/autobook/

For all those people who have been mystified by
./configure
make
make install
I'm yet to read the book.. Placing this post lest I lose the url

--------- --------- --------- --------- --------- --------- --------- ---------
(2008-05-12)
Another book on auto-tools

http://www.freesoftwaremagazine.com/books/autotools_a_guide_to_autoconf_automake_libtool

.

Saturday, February 9, 2008

Linux from the scratch !

Learn to
- install linux from source yourself
- build liveCDs and distributions
- build embedded linux systems
and lot more

http://www.linuxfromscratch.org/

.

Thursday, February 7, 2008

Tuesday, December 4, 2007

Coolest bugs

The URL gives a list of 10 cool bugs caused by software/hardware glitches..

http://news.zdnet.com/2424-9595_22-177729.html

.

Thursday, October 18, 2007

Damn Small Linux, aka DSL

Ever wanted a really small Linux live CD? This is the perfect one.
http://damnsmalllinux.org/
It supports the X windowing system, and comes with Firefox web browser, a VNC viewer, basic word processors, media players, USB support and in short, everything you will need out of a basic computer.
And the punch line is its amazingly small size of ~ 50mb!

.

Wednesday, October 10, 2007

BonaFide OS Development

A place all you folks interested in operating systems should check out !
Some good documents on Operating Systems, oriented at the lesser discussed practical side.

http://www.osdever.net/goal.php

.

Sunday, September 30, 2007

The Minix3 Operating System

This is an Operating System created and maintained by Prof. Andrew S Tanenbaum, for use in the academia to provide students with first hand experience on OS code. Also among the design goals thankfully are readability, modularity, and control over code size.

http://www.minix3.org/

A good blog on minix
http://www.minixtips.com

Earliest posts:
http://www.minixtips.com/2006_06_01_archive.html

.

UIUC Choices

This is a research project going on at the University of Illinois, Urbana-Champaign, into developing an Object Oriented Operating System, called Choices. The various links of interest are

.

Thursday, May 24, 2007

Python References

[This post has been translocated from my python blog to this blog, as I'm planning to close down my python blog.. It's not seeing much attention from me anyways :D ]

Hm.. Now where do I learn python from.

Well, I started with the book "A Byte of Python" [pdf]. This book is a concise and succinct tutorial for someone who has a background in some or other programming language. I would recommend it to anyone who wishes to learn python, and you can learn from this book in under two weeks even at a relaxed pace of learning.

Likewise, the book "Dive into Python" also seems to be a good resource. I must admit I haven't dived into the book much to make a more accurate comment.

The python official website can be found at http://www.python.org . You can download the version of python for your particular operating system. Python is free !

You will also find Python documentation available for download at the site. [http://www.python.org/doc/] There's one particular tutorial in this documentation [online copy @ http://docs.python.org/tut/tut.html]. The tutorial is very exhaustive and will make you pretty much the guru of Python. However, on the flip side, I found the tutorial a little too involved. If you can bolster the patience to pore through it, there's nothing like it.

Have fun charming the python !

Wednesday, May 23, 2007

The Python programming language

[This post has been translocated from my python blog to this blog, as I'm planning to close down my python blog.. It's not seeing much attention from me anyways :D ]

Python was a buzzword around that time. Like an intelligent babe, this language was being exalted as simple and yet tremendously powerful. Well I never bothered; but instead just cleaved to the faith that the prodigious C++ was _the_ panacea for all programming imbroglio.

That went on until I stumbled upon this book: 'Byte of Python' by Swaroop C H [http://www.byteofpython.info/]
And that day, I was bitten.

Well, my old buddy C++ is still my best buddy because she is the most adaptable and reliable programming language that I've learned. In fact C++ and her object oriented lineage teaches you to think of programming situations from an entirely different perspective than what used to be conventional. C++ made you think more like you normally would.

But then Python too borrows heavily from the same Object oriented approaches and additionally allows you the flexibility of more expressive expressions and concise statements. Also somewhere in her lineage python had some functional programming ancestry which allows scope for expressing certain situations more flexibly.

So.. What exactly is this python?

Well I'd qualify python by the following salient features
- It's an interpreted programming language.
- It's a language which uses type inference and dynamic typing, which means you needn't specify the type of variables at compile time, and variables can be assigned values of different types without having to worry too much about the risks involved.
- It's an object oriented programming language.
- Seasoned with condiments from functional programming, it delivers that flexibility too, without the concomitant obscurity associated with functional languages.
- It has a _huge_ standard library base catering to almost all conceivable requirements.
- It is concise and succinct, reducing code size to probably 30% of the C++ analogue.

On the whole, it's one hell of a language.

Sunday, April 29, 2007

[python] image converter

[This post has been translocated from my python blog to this blog, as I'm planning to close down my python blog.. It's not seeing much attention from me anyways :D ]

The following is a code for an image format converter cum resizing program. It takes a source directory, a destination directory and a target file format as parameters and converts all images in the source directory to the target format and writes them at the destination, after resizing them.


This is only a prototypical version and is rather rigid. You might have to modify it to suit your requirements.

Also note that the program requires Python Image Library (PIL) installed in addition to python.

import os
import Image

def imageConvert (source, dest, ext):
if os.path.isdir(source) and os.path.isdir(dest):
result = [True,[]]
for i in os.listdir(source):
if os.path.isdir(source + os.sep + i) == False:
outfile = dest + os.sep + \
os.path.splitext(i)[0] + ext
infile = source + os.sep + i
if infile != outfile:
try:
im = Image.open(infile)
if ( im.size == (1024,768) ):
# Landscape Image
im = im.resize( (640,480) )
elif ( im.size == (768,1024) ):
# Portrait Image
im = im.resize( (480,640) )
im.save(outfile)
#Image.open(infile).save(outfile)
except :
result[0] = False
result[1].append('cannot convert %s'\
% infile)
return result
else:
return [False, ['Error, either the source or the' + \
'destination given is not a directory']]

def main ():
source = raw_input('Enter source directory: ')
dest = raw_input('Enter destination directory: ')
ext = '.' + raw_input('Enter file format extension: ')
r,l = imageConvert ( source, dest, ext )
if r == False:
for i in range(len(l)):
print l[i]

if __name__ == '__main__':
main()

Friday, January 12, 2007

[Python] Permutations of a string

[This post has been translocated from my python blog to this blog, as I'm planning to close down my python blog.. It's not seeing much attention from me anyways :D ]

Given a string of any length, this python program generates all permutations of the characters in the string. The program is capable of taking care of repeated occurrences of the same character


count = 0 # a global counter to give a unique id to each permutation
# that is generated


def constructDict (s):
"""Constructs the dictionary.

Constructs the dictionary of
unique character to no-of-occurance mapping.
"""
d = {}
for i in range(0,len(s)):
try: # if the character is already present
d[s[i]] = d[s[i]] + 1 # increment its count
except: # if the character is not already presetn
d[s[i]] = 1 # put it in and set its count as 1
return d


def recursivePermuter ( d, strSoFar, maxDepth, thisDepth = 0 ):
"""Constructs all permutations.

d: the dictionary
strSoFar: the prefix part of the string which
has been constructed so far
maxDepth: this is same as the length of the
user input string
thisDepth: this level of recursion (Default value 0)

Each place in the permutation can be occupied by
an "available" character. An "available" character is
one whose value in the dictionary d is not zero.
When we use/borrow an available character, we decrement
its value in the dictionary; and when we backtrace/return
the available character, we restore its value by
incrementing once.
"""
global count
if (thisDepth == maxDepth): # if we have completed one permutation
count = count + 1
print str(count) + ": " + strSoFar
return
for key,value in d.items():
if value == 0:
continue
# all elements in d with value > 0 are "candidates" to go
# into this place.. We give each a chance systematically..
d[key] = value - 1
recursivePermuter ( d, strSoFar + key, maxDepth, thisDepth + 1 )
d[key] = value


def __main__ ():
"""The perpetrator of all evil.
"""
s = raw_input("Enter String: ") # get the user input string
d = constructDict(s) # construct the dictionary
recursivePermuter(d, "", len(s)) # despatch to the guy
# who churns out permutations


# you have to explicitly call the main
# main, in python is a convention rather than
# a mandate..
__main__()


How it works..

  1. get all the unique characters in a pool of pairs, each pair (symbol, no_of_occurances)
  2. consider each permutation as a set of n blanks, n = strlen(given string)
  3. for each position/blank in the permutations,

    1. we pick a symbol to go into that blank.. In picking, we reduce the number of occurance..
      So obviously also note that we may not pick a symbol whose number of occurances is already zero.
    2. now we go down the line to the next blank and repeat 3 //this is a recursive step..
    3. once the recursive function returns, we return the symbol we had borrowed for this instance
      of the recursive function.. We do so, by incrementing the number of occurances by one ..