Friday, November 30, 2007

Difference between StringBuffer and StringBuilder

There is a subtle yet important difference between the StringBuffer and StringBuilder. StringBuffer is synchronized when it has to access/modify its contents, where as StringBuilder is not. A StringBuilder object is not safe to be shared across multiple threads.

It is much efficient to make use of StringBuilder when the StringBuilder object is not shared between multiple threads.

StringBuilder was introduced in JDK 1.5.

Thursday, November 29, 2007

Starting X sessions in Cygwin

Question: "I want to have my Linux desktop in my Windows machine. I have installed Cygwin. How to do this?"

Follow these steps:
  • Start your Cygwin command shell.
  • Give "xinit -- -clipboard" in the command line. You will see a bare X window show with a command prompt in it. You will also see something like "Cygwin/X - 0:0" on the left-top of the window. This tells you the display in which the X server is listening for incoming connections.
  • Give "xhost +" in the command prompt. This is to let the server accept all the incoming connections. Remember: if you are concerned about the security, refer to the man page of xhost on how to give a list of hosts instead of wild card "+".
  • Start an ssh connection to your Linux box.
  • Once logged in, set the display variable. As per this example it would be "export DISPLAY=x.x.x.x:0.0" where x.x.x.x is the IP address of your Windows box.
  • Start your Gnome session by giving "gnome-session". Voila! You will see your desktop in your X window.
A couple of trouble shooting tips. If you have a firewall blocking connections from your Linux box to your Windows box, you will encounter an error. Just use telnet to make sure that your connection works. Try "telnet x.x.x.x 6000" to confirm this. It might be the case that you didn't do the "xhost +" step above, in which case your X server will reject the incoming connections. Make sure you have done this right.

A note on the "-clipboard" option above: if you don't give this option, X server doesn't share the windows clipboard with the applications running in it, hence you will not be able to copy/paste between your Windows and Linux applications.

Update on 1/28/2008: I found that giving the "-keyhook" option lets you switch between the frames inside Cygwin/X using Alt-TAB. You should give it like:
xinit -- -clipboard -keyhook

Glossary from Altova

I was searching for one good place where I can get a decent list of acronyms that I come across often, without a need to search for them every time in the net. The Altova glossary page looks like a good place (despite their nepotism toward their brainchild XML Spy!).

Monday, November 19, 2007

Finding DLL dependencies in Windows

For quite sometime now I was searching for a tool that will help me in finding out the dependent DLLs for a given EXE/DLL (like ldd in Solaris/Linux). I came across an amazing utility today called Dependency Walker. Its really neat and cool in finding out the broken dependencies.

Friday, November 09, 2007

Nuke those Google ads that come in your way

Google ads are good, at times. But I don't remember when was the last time I clicked on one and visited the target page. If I need something, I mostly use Google search, not the ads. Most of the time I feel that those ads come in my way when I am reading something really serious. Its waste of bandwidth and time to load these ads when I am not in a mood to clicking on them.

Here is a cool solution for the Firefox. All that you have to do is to download the Adblock plug-in and install it. Then restart your Firefox. Go to Tools -> Adblock -> Preferences. Enter the Google syndication URL ( Save and you are done. Have a Google ads free surfing :-)

Thursday, November 01, 2007

Puzzle of repeating numbers

My friend Siva asked me this puzzle.
There is a set of N numbers. All numbers in this set repeat even number of times, except two numbers that repeat odd number of times. Develop an algorithm that will find these two numbers in O(N) space & time complexity.

I couldn't find the solution, but the solution Siva gave and another variant of that solution that his friend gave were simply amazing. Not to spoil the fun, I am not giving any of those solutions here :-)