Tuesday, December 27, 2005

Spamking of the Year

What do you hate more? Cleaning the toilet or cleaning up the spam in your mailbox? I was checking the fun facts on spam on yahoomail and it notes that more people prefer cleaning their own toilet! So do I!

The next time you see an ad screaming - "Free ipod nano is yours" - just close the browser window and take it as your hint to clean the toilet!

Thursday, December 22, 2005

All Queued Up..

Don't you hate standing in queues? Just standing there waiting for your name to be called? What can you possibly do when you are standing there? You try to look around, but nah ... too self-conscious. You begin to wonder why that lady is staring at you. She's about 40 and couldn't possibly be interested in you. In all probability you are dressed up like Superman - know what I mean?! There's a very pretty lady at the other end of the room. Wonder what she is doing buried into her laptop. Oh no, she's caught you staring at her. There's no place to hide!

Coming to the next important question - where do you place your hands? If its in your pockets, its way too casual. Keeping it folded would mean you are closed to conversation. Well, behind your back would be a good idea, but that would hurt if the line stops moving! And what is that guy behind you laughing for? Have you worn your shirt backwards? Oh, not again!

Oh well, I just hate standing in a queue!

Wednesday, September 28, 2005

Week of the year calculation in Oracle and Java

I was kinda surprised when I discovered that Oracle and Java calculated weeks of year differently - Java taking into account the day of week it is, whereas Oracle concerned only with the date.

For example, if the first day of the year is a Friday, Java will fetch Jan 1 to be week 1, Jan 2 too as weekday 1 and Jan 3 as weekday 2 (yeah it could also depend on what day you set as the start of a week). Oracle does not seem to care what day the first day of the year was. It just picks the first 7 days of the year as the first week of the year, next 7 days as the second week, and so on..

Now I know why they need a bridge to connect!

Tuesday, September 13, 2005

The New ipod Nano...

I ordered my nano the day it was announced by Apple. I got it 4 days later despite there being a weekend in between. That was quick!

Feature-wise, there's nothing to talk about if you already own any ipod. But the appearance, feel and size makes it extra-ordinarily impressive. Further, being a flash-memory based device makes it a little "different" from the earlier ipods. I said "different" and not better. You can make you own decision here http://www.storagesearch.com/semico-art1.html

If you already own an ipod, I don't see any other reason why you would want to go for a nano once the excitement dies down, other than to present it as a gift or to use it while running or in the gym. Its small size makes it extremely efficient as a portable storage device - its as small in length and width as a business card cut into half, and probably few millimeters thicker. Appearance-wise its unbeatable; cost and feature-wise its almost the same as an ipod, without the benefit of large storage. The black nano, although the better looking, will show visible marks of your fingerprints when you hold it in your hands for a few minutes. Make sure you get the nano-tubes as well, although it would no longer render your nano black anymore!

Tuesday, July 12, 2005

Writing to nothing in UNIX

Ever used this before -
$ grep hello hi 2>/dev/null

Probably you have - or something similar to the one above. We are writing errors to what constitues in Unix to "nothing" or "null". What are we doing that for?!

Before we answer the above question, lets assume you have a file hello.txt, which contains a few lines of text. Run this command at the command line -
$ grep "test" hello.*

The output would be something like -
This is a good day and I love testing my code.

How do I find out which filename this is in? With grep, if the filename pattern matches only one file. it never writes the filename to the output. So then, how do we get the filename?
Simple! Try running this at the command line -
$ grep "test" hello.* /dev/null

Howzatt?! You provide a filename here where you are sure nothing can be found, because anything cannot be found in nothing!

So, coming back to the earlier question, what use is it to redirect output to a null file? Sometimes, you need a program to just execute without bugging you with its results. There are other instances where you might not need any errors to be logged (as in the first command). /dev/null could also be used to prevent some logs from being written, when you do not have any access to the source code which is writing the logs. Just create a symbolic link to this file and make it point to /dev/nul -
$ ln -s /dev/null mylog

So, what is the /dev/zero file?

Thursday, June 30, 2005

Java - Memory Leaks

Now that we are talking Java, why not continue the discussion a little further, and since we ended on pointers in Java, the next question would be - what are memory leaks in Java, and why does it occur if Java performs its own garbage collection?

This is how the garbage collector in java works - starting at the root class and parsing through all nodes being referenced, at the same time keeping track of which objects are actively being referenced. Any classes no longer being referenced are then eligible to be garbage collected. What is to be noted is that an object is only counted as being unused when it is no longer being actively referenced. One other thing to keep in mind is that, unlike other languages such as C++, allocated memory is returned to the operating system when the application is closed.

Some common causes of memory leaks -
* Register a class as a listener, without unregistering it when it is no longer needed
Until the application receives event notification, the JVM will not garbage collect the storage.
* Declare a huge collection to be static
Collections hold other reference objects, and making them static keeps them in memory throughout the lifetime of the application.
* Not closing database or network connections
It is very important that the database or network collection is released once the information exchange is completed.
* Including native code in a Java program
The storage for references created in native C or C++ coding environments is not handled or garbage collected by the JVM. Hence the JNI memory must be directly dereferenced by the native language it was written in.

Now I know why I keep forgetting things nowadays. Lots of static HashMaps and Vectors pervading my brain!

Java - Unchecked Exceptions

There are two types of Exceptions in Java - The Checked and the Unchecked. Ever wondered why we have this classification? Any exception that can be thrown by a method is part of the method’s API and forms an integral part of that method’s declaration as are its parameters and return value. Just imagine the complexity of a method declaration if it would make all exceptions necessary to be declared! And worse, some of these exceptions would never occur in a program if the program was written carefully and diligently.

Unchecked exceptions, on the other hand, represent problems resulting from a programming problem, from which the application cannot recover or which cannot be handled in any way - for eg ArrayIndexOutOfBounds or NullPointerException.

Moral of the story - If the code can reasonably be expected to recover from an exception, make it a checked exception. If the code cannot do anything to recover from the exception, make it an unchecked exception.

Oh yes, on a related note - Are there pointers in Java? If your answer is NO, could you please explain why there are NullPointerExceptions everytime I run my code?!

Saturday, June 04, 2005

More inspiration quotes..

We make a living by what we get, we make a life by what we give.
- Winston Churchill

Live as if your were to die tomorrow. Learn as if you were to live forever.
- Gandhi

Just as a candle cannot burn without fire, men cannot live without a spiritual life.
- The Buddha

Life is like riding a bicycle. You don't fall off unless you plan to stop peddling.
- Claude Pepper

It is not length of life, but depth of life.
- Ralph Waldo Emerson

Expecting life to treat you well because you are a good person is like expecting an angry bull not to charge because you are a vegetarian.
- Shari R. Barr

And in the end, it's not the years in your life that count. It's the life in your years.
- Abraham Lincoln

There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.
- Albert Einstein

Attack life, it's going to kill you anyway.
- Steven Coallier

Friday, June 03, 2005

Cute little San Diego...

The memorial weekend was a welcome relief from the enormous work I was loaded with. So, my friends and I planned a quick trip to San Diego, situated in south of California. Had a look at Sea world and the zoo. There were a few scenic spots in the San Diego old town area. I also picked up a little stuff in the shops there.
The San Diego downtown is a great place to go to try out various types of cuisines - Chinese, Indian, Mexican, Thai, American, French ... the list if endless.
Missed out going to the Animal park and the Harbor there. Next time probably!






Monday, May 16, 2005

Inspirational!

"To learn to succeed, you must first learn to fail."-Michael Jordan

If you love somebody, they shouldn't make you cry, they should be worth crying over.

Learn from the mistakes of others, because you can't live long enough to make them all yourself.

When everything is coming your way, you're in the wrong lane.