Wednesday, November 10, 2010

Be Rational, Get Real


I think the picture conveys it all !!

- - [edit, 2011-12-05] - -

A fellow blogger after seeing the above pic, promptly forwarded me this picture
 
This is aptly titled, "Keeping it real"

Saturday, November 06, 2010

Happy Diwali (software engineer style)

 
In this auspicious day, may you get,
  • independence of JAVA
  • popularity of WINDOWS
  • security of LINUX
  • luxury of .NET
  • efficiency of C
  • simplicity of HTML
  • vastness of GOOGLE
  • robustness of IBM
Happy Diwali

Saturday, October 09, 2010

Bash Auto-Completion Trick

Most of us who use the bash shell in *nix environments, often find the Tab-key auto-completion to be a very helpful timesaver. But one of the main problems is that he feature is not adaptive, i.e. it does nothing to learn from my previous commands. For example in my home directory I have two folders: “picture” and “programming”. Usually there is no reason for me to traverse the “picture” folder using bash, I’d rather use nautilus for that. So when I type something like “cd p” and press Tab, I would ideally like to get “programming” rather than “picture”. What if we could somehow use the history of commands to help this auto-complete feature?

Here is a cool bash trick that I have been using for quite sometime. It helps me search the history of typed commands that begin with what I have typed so far. Here is the way to enable it in your system.

Edit the “~/.inputrc” file by appending the following lines to it and save it:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

Note that the file “~/.inputrc” might not be present in your system, so in that case you will have to create it.

Now to use this feature, open a new instance of the shell and type something like “cd p” and press the PageUp and PageDown keys to search the history of commands that begin with “cd p” backwards or forwards and cycle through them.

Personally I find this quite a time saver. However note that the completion feature is not directory aware, so like in the previous example it might just give you the name of a directory that does not exist in your current path.

Sunday, October 03, 2010

12 Coins puzzle

The puzzle goes like this:

A set of 12 coins of similar shape and size contains one counterfeit coin, whose weight is different from that of the other coins. Find the coin using a balance and minimum number of weighing.

The catch of the problem is that it is not mentioned whether the counterfeit coin is lighter or heavier than the rest of the normal coins.

Lower Bound

Let us first examine what is the minimum number of weighing required to find the coin. We use information theory based approach for getting this.

Each weighing can have three different outcomes,

  1. left_side < right_side
  2. left_side = right_side
  3. left_side > right_side

Thus min number of weighing >= ceiling (log 12 base 3) = ceiling ( log(12)/log(3) ) = 3

Solution

Well, as it turns out, we need exactly 3 weighing. The method is kind of confusing to describe, so I drew a flowchart (PDF) for the same (click on the image for the full sized image):

 12coins_small

Background

Campus recruitments were about to commence so I was in hunt for good puzzles to hone my problem solving skills. A friend of mine sent me this gem. I was used to tackling coin puzzles, but this was unique as the weight of the counterfeit coin was not given. I tried it and getting the 4 weighing solution was quite easy to get.

Next I  gave this problem to my friends at IISc, Dyut, Abhiskek and Arghya. After a lot of attempts Dyut and Abhiskek could not improve upon my solution. After a few days I tried it again. Particularly the case where the first two groups were unequal. After a couple of attempts with a fresh mind, I cracked it. Later I found out that my friends had also figured out the solution from some other friend, who solved it at the very first go. Well there are no dearth of brilliant guys IISc !

Thursday, September 09, 2010

Modulus Operator on negative numbers in C

I had been introduced to the C language in the very first day of my B.Sc. course back in 2003. Since then I have been using it for doing quite some varied kinds of programming jobs. But even after so many years, its every now and then that I find out something I did not know before. Here is one such thing that I encountered few days back.

I was taught by both my C teachers in B.Sc. as well as in B.Tech. that the modulus operator in C (denoted by the “%” sign) behaves exactly similar to the mod function that is defined in Mathematics. However here is something weird that I saw recently. Better to show it by code:

   1: #include <stdio.h>
   2:  
   3: #define PRINT_int(x) printf(#x " = %d\n",x)
   4:  
   5: int main() {
   6:  
   7:     PRINT_int( ( 1)%( 6) );    
   8:     PRINT_int( (-1)%( 6) );
   9:     PRINT_int( ( 1)%(-6) );
  10:     PRINT_int( (-1)%(-6) );
  11:  
  12:     return 0;
  13: }

The output given is:


( 1)%( 6) = 1
(-1)%( 6) = -1
( 1)%(-6) = 1
(-1)%(-6) = -1

This does not match at all with the definition of the modulus operation that we have learnt in Mathematics classes. Specifically, modulus can never be negative. So something must be wrong. As it turns out C’s modulo operator behaves differently from the mathematically defined ones when we apply it for negative numbers.

The C90 standard does not define the result of modulus applied on negative numbers, so the result is compiler dependant. But C99 clearly says that the sign of the result is the same is that of the dividend, so in essence for something like:

c = a%b;

The actual operation done is:

c = sign(a) * ( abs(a) % abs(b) );

Where:

  • sign(a)=1 for a>=0
  • sign(a)=-1 for a<0

I figured the rule by myself and later clarified it from the Wikipedia page on Modulo Operation and also from the comp.lang.c group’s "Division and Modulus of Negative Integers” topic.

Wednesday, September 08, 2010

How to use Skydrive folders in Windows Explorer

I am a big fan of free online storage for my backups. So far Microsoft Skydrive seems to be the best one in terms of space. But the one thing which I hate about Skydrive is its incompatibility with any application. Ideally I would have liked to use the online folders as easily as my local folders. For example had the folder been openable in Explorer, then we could have used the “copy-paste” and “save in” features available for any local directory. Surely the latency would be higher, but at least there would be no need to do thing separately.

Anyways, here is a hack (not yet perfected but works so far) devised from various sources which allows anybody to mount his/her Skydrive folders in a local directory. This is formally called network mounting. The trick is simple enough for novice users too. Just follow the simple steps:

  1. Log-in to your sky-drive account from http://skydrive.live.com/
  2. Look into the address bar, you should see something like “https://cid-xxxxxxxxxxxxxxxx.skydrive.live.com/”, where the ‘x’s would be replaced by your unique customer-id. Copy the 16 characters of customer-id.
  3. Now open Notepad and do the following very carefully:
    1. and paste this 16 characters
    2. Note down the name of the folder that you would like to mount, say “MyOwn”
    3. In notepad create this URL (without quotes): “\\docs.live.net@SSL\xxxxxxxxxxxxxxxx\MyOwn”, replace the ‘x’s by your unique 16 character customer-id and replace “MyOwn” by the folder name (as it appears in Skydrive) that you want to mount.
    4. If you are trying to mount the default folders “Public” or “Documents”, then you have to use “^2Public” and “^2 Documents” in place of “MyOwn”.
    5. Now copy the final URL that you made.
  4. Open Explorer
  5. On the left side-bar, right click on “Network”, and select “Map network drive”
  6. Paste the URL you copied from Notepad.
  7. Select a drive letter, preferably something at the end of the English alphabet like “Z”, and hit the “Finish” button.
  8. You would be asked for your Windows Live-ID and password, which you must provide.
  9. Voila, you can now see the contents of that drive inside explorer by going to the drive you selected.
  10. Now you can use this folder just like any other local hard-drive folders. Open files from this drive by double clicking, save files, cut-copy-paste files to and from this directory.

Try it out, I’m sure you will stop using the online version after using this trick.

Now, a word of caution. This is NOT an official method, so Microsoft does not give you any guarantees of any kind for this method to work. So one fine morning this method might just give a lot of errors and rendered ineffective. But till then (and I believe chances of that happening is quite slim), utilize this feature.

Lastly the file size restriction still applies (50Mb per file). So unless you are felling adventurous, do not try this out with files lager than 50Mb. Sadly this thing does not work for non-Microsoft OS (Linux, to be specific). If I get something working on Linux, I will post it here.

If you have any questions/recommendations please post it here. I usually reply within a day.

Saturday, June 05, 2010

Why India is still a Developing Country ... a short story

An Old Story:

The Ant works hard in the withering heat all summer building its house and laying up supplies for the winter. The Grasshopper thinks the Ant is a fool and laughs and dances and plays the summer away.

Come winter, the Ant is warm and well fed. The Grasshopper has no food or shelter so he dies out in the cold.

Indian Version:

The Ant works hard in the withering heat all summer building its house and laying up supplies for the winter. The Grasshopper thinks the Ant's a fool and laughs and dances and plays the summer away.

Come winter, the shivering Grasshopper calls a press conference and demands to know why the Ant should be allowed to be warm and well fed while others are cold and starving. NDTV, BBC, CNN show up to provide pictures of the shivering Grasshopper next to a video of the Ant in his comfortable home with a table filled with food.

The World is stunned by the sharp contrast. How can this be that this poor Grasshopper is allowed to suffer so?

Arundhati Roy stages a demonstration in front of the Ant's house.

Medha Patkar goes on a fast along with other Grasshoppers demanding that Grasshoppers be relocated to warmer climates during winter .

Mayawati states this as 'injustice' done on Minorities.

Amnesty International and Koffi Annan criticize the Indian Government for not upholding the fundamental rights of the Grasshopper.

The Internet is flooded with online petitions seeking support to the Grasshopper (many promising Heaven and Everlasting Peace for prompt support as against the wrath of God for non-compliance) .

Opposition MPs stage a walkout. Left parties call for ' Bengal Bandh' in West Bengal and Kerala demanding a Judicial Enquiry.

CPM in Kerala immediately passes a law preventing Ants from working hard in the heat so as to bring about equality of poverty among Ants and Grasshoppers.

Mamta Bannerji allocates one free coach to Grasshoppers on all Indian Railway Trains, aptly named as the 'Grasshopper Rath'.

Finally, the Judicial Committee drafts the ' Prevention of Terrorism Against Grasshoppers Act' [POTAGA], with effect from the beginning of the winter.

Kapil Sibbal makes 'Special Reservation ' for Grasshoppers in Educational Institutions & in Government Services.

The Ant is fined for failing to comply with POTAGA and having nothing left to pay his retroactive taxes, it’s home is confiscated by the Government and handed over to the Grasshopper in a ceremony covered by NDTV.

Arundhati Roy calls it ' A Triumph of Justice'.

Mamta calls it 'Socialistic Justice '.

CPM calls it the ' Revolutionary Resurgence of the Downtrodden '

Koffi Annan invites the Grasshopper to address the UN General Assembly.

Many years later ...

The Ant has since migrated to the US and set up a multi-billion dollar company in Silicon Valle. 100s of Grasshoppers still die of starvation despite reservation somewhere in India.

AND

As a result of loosing lot of hard working Ants and feeding the grasshoppers, India is still a developing country !

Last Words

Usually I stay away from publishing other people's contents on this blog. However, this post actually breaks the rule. The above is an email forward sent to me by my my uncle Dr. Tamal Deb. I do not know the original author, but the story made a lot of sense to me.


Friday, May 28, 2010

How to ssh to Mac

Ever since I got my Mac Book Pro, I have been trying to ssh into it. Unlike Fedora, Ubuntu and RHEL, Macs do not have this ssh switched on by default. Here is the step-by-step procedure for doing so (note that this is for the machine to which you need to connect, not the one from which you would connect) :

  1. Go to "System Preferences"
  2. Select "Sharing"
  3. Unlock the lock symbol at the bottom-left corner
  4. Check "Remote Login"
  5. Now close this window and try out ssh-ing to your machine. In case you do not know the IP of your machine, type "ifconfig" in the terminal to get it.
One could have also modified the ssh configuration file located at /etc/sshd_config for the same. Initially I had also done the same. However the method that I described above is completely GUI based, so even non-geeks can try it out. Besides this interface also allows one to tweak a lot of other things as well.

Disclaimer: I am a Mac newbie, its only since last one week that I have been using it. The above procedure is what I figured out after some attempts in my Mac Book Pro running OS X. I do not really know if it would be the same for other Macs as well.
 

Friday, May 07, 2010

IEEE formatting in LaTeX

I had to write one of my recent reports in IEEE format. Although IEEE does provide all the necessary files and guideline, I had to spend quite sometime to get the things working with LaTeX. So here is a step by step procedure on how to use the IEEE template in LaTeX in Ubuntu and Fedora.
  1. Download the template from the IEEE Manuscript Template page. Presently the file-name for Unix is "IEEEtran2.tar.gz".
  2. Extract this file in a folder IEEEtran.
  3. Within that create a subdirectory "bibtex"
  4. Download the bibtex file "IEEEtranBST1.tar.gz" from the same IEEE Manuscript Template site to this directory and extract.
  5. For Ubuntu users:
    • Move IEEEtran directory to /usr/share/texmf-texlive/tex/latex/
  6. For Fedora users:
    • Move IEEEtran directory to /usr/share/texmf/tex/latex
  7. Run "texhash", (this would require root privileges) or use sudo if its available.
That is it. Now you are ready to directly use this template file for your LaTeX reports. A couple of more things for LyX users:
  • After following these steps, you have to restart LyX.
  • Go to Lyx > Tools > Reconfigure
  • Restart LyX
  • To use this template just select IEEEtran from the Document Settings.
If you have been benefited by this short tutorial, please drop by a comment.

Friday, April 16, 2010

How to print from an iPad?

Here's a simple way to print things from Apple iPad:


Thursday, April 15, 2010

শুভ নববর্ষ ১৪১৭ (২-টি কবিতা)

Today is the starting of the Bengali New Year 1417. This is according to the Bengali Calendar which is totally separate from the Gregorian Calendar that is being used by most people around the world.


I got a few poems/couplets on sms/email today wishing me "শুভ নববর্ষ ১৪১৭", which in Bengali is "happy new year 1417". Usually these poems have a very short life-span. They stay in the phone/mailbox and are very soon forgotten. So I decide to share two of them with everybody, in an attempt to increase their life-span a bit.

Both the poems are naturally in Bengali, although I got them in the English font. I decided to put them up in their original fonts.

First poem (sent to me by my friend Arijit):

ভুলে যাও পুরোনো গ্লানি,
সম্পর্কের টানাটানি,
নতুন আশা, নতুন গান,
নতুন করে মনের টান,
আমার সুভেচ্ছা সাথে রেখো,
নতুন বছর ভালো থেকো
শুভ নববর্ষ ১৪১৭

Second poem (from my uncle Dr. Tamal Deb) :

রোদ-বৃষ্টি মাখামাখি
পুরোনোকে দিয়ে ফাকি,
নতুন ভোরের আলোর সাথে
নতুন সাজে উঠবে মেতে.
শুভ নববর্ষ ১৪১৭

I do not know the original sources of these lines. It would be interesting if anybody can find out something about it.

Sunday, April 04, 2010

Google's April Fool Tricks 2010

From the year 2000 onwards Google has been upto some tricks or the other in April 1st. It started with Mentalplex in 2000 and since then Google has come up with a series of hoaxes for April 1st. Personally I came to know of this in 2002 when they put up their Pigeon Rank technology.

So this year also Googlers have gone out of their way to put up some April Fool jokes. Being a fan of Google, I tried to collect the set for 2010. Initially it was in the form of a April Fool buzz, with only the links. Then I thought of putting up this article.

Chrome with 3D

We all know about Chrome, a browser from Google that claims to renders "web pages and applications with lightning speed". This year Google put up a page for a 3D version of Chrome, dubbed as Crome 3D, there was a official post in the Chrome blog about this release . Users had to run the application on their normal screens and they would need a special set of glasses to enjoy the 3D effect.
Chrome 3D
The next day they have put up another post to indicate that it was just another hoax. In this post the engineer who coded Chrome 3D explained the kind of trouble that Googlers go through to put up these.
Googlers testing out Chrome 3D

Vowel Outage

The official GMail Blog reported a vowel outage at 0649 hrs on April 1st. The post says:
... during routine maintenance at one of our datacenters, the frontend web servers in that particular datacenter started failing to render the letter 'a' for a subset of users.

... we're experiencing Gmail’s first temporary vowel outage.
This was very funny. Some of my friends upon receiving this link from me me even replied that they kind of felt something wrong with the interface ! Two of them replied whether this was technically feasible !

Google changes its name to Topeka

This was not as elaborate in execution as the Chrome 3D joke which involved someone actually coding and testing the whole thing and then putting it up. This was limited to just a simple blog post titled "A different kind of company name" in the official Google blog. Apparently Google was changing its name to "Topeka", for some weird reason.
New Company Name

They even published a guide to the proper usage of the word Topeka.
Proper usage of the new name Topeka

Capability to Store Physical Objects in Google

Google is offering to store any physical items with them for a charge of $0.10 per kg. This was put up in the main Google site as a coming soon stuff. The page also includes a few user testimonials. This is one of those things that would be great if it happened in real life. This hoax was also put up in Google Docs blog on March 31st.

Translate Animal Speech


Google UK put up this awesome joke as a web page for a futuristic application that could Translate Animal Speech. This was complete with tours and video demos of the application.

Conclusion

This year Google seems to have gone out of their ways to create so many of these jokes for April Fool's day. I am sure there were a few more which I might just have missed. Personally the Chrome 3D was the most gullible one. I managed to convince one of my friends to install Chrome 3D and take a print out of the glasses.

If you come across some of the other things that I might have missed, do drop me a line.

Saturday, March 13, 2010

Equations of words

I came across this blog recently. The author has managed to generate equations of words:
http://www.xamuel.com/inverse-graphing-calculator.php

Basically it generates equations which when plotted will generate the word that someone has typed. Unfortunately there is no way to verify it. The equation is by default in image format. On checking the "Raw Text" check-box, one can get the actual equation in text format that can be copy-pasted.  Unfortunately I could not copy-paste it to some plotter to plot it directly. Maybe I will try it out in Matlab someday and post the results here.

Here are some other articles that caught my attention in that blog:
Look up the website. The author is a Math teacher. His ideas seem to be quite interesting. Some of them matched with me quite a lot and created some sort of a resonance and made me like this person. Some other ideas got me thinking. The self-teacher piece is something that I find similarity with a lot. The swapping of signs was an interesting idea, it kind of reflects the consequence of standardization and protocols.

The computer simulation article was like straight out of Matrix trilogy. I have thought about this a lot, and its kind of weird. The mind says its impossible, but logically this could be a possibility. In 2001 Prof. Nick Bostrom published a paper with same title. You could read the paper and look into the website that the Prof has created.


Wednesday, March 03, 2010

SI Prefixes

Here is a list of SI Prefixes that I jotted down from the web today:
10^x Prefix
1 deca
2 hecto
3 kilo
6 mega
9 giga
12 tera
15 peta
18 exa
21 zetta
24 yotta
I was looking for the name of 10^15 and stumbled upon this list.