Wednesday, May 14, 2008

Power of Java, In deleting the files that Windows cannot

Today, in one of the programs, I messed up a little piece of code that creates a folder in another, which ended up creating folders in an infinite loop. The folder name was ae, but there were so many of them ae in ae in ae .... Then I just wanted to clear the folder and start afresh with the fixed code. But guess what. Windows would not delete the folder because the name is too long. This was the exact error..

"cannot delete the file name you specified is not valid or too long"

I tried from Command prompt and tried other solutions from Google search like assigning a name on shared and trying to delete from network. And nothing worked. That's when I decided, let's take Java's help. Wrote a simple piece of code to loop through until it reaches the final folder and deletes everything. Ran the code and 2 minutes later, everything was gone. One more reason to love Java and being a programmer. Here is the code in case you are interested..



import java.io.File;
public class FileDelete
{

private void deleteFiles(File file)
{
if(file.isDirectory())
{
File child[] = file.listFiles();
for(int i = 0; i < child.length; i++)
{
deleteFiles(child[i]);
}

}
if(!file.delete())
{
System.out.println("Cannot delete file: " + file.getAbsolutePath());
}
}
public static void main(String[] args)
{
System.out.println("Attempting to delete files");
File _work = new File("");
FileDelete fd = new FileDelete();
fd.deleteFiles(_work);
}
}


Friday, May 2, 2008

Britain's got talent, hell ya with these kind of Michal Jackson + Bhangra, it sure does

Don't need to describe the video much. The audience reaction says it all :)

Tuesday, April 29, 2008

Impressed with Jawbone headset and its customer service support

A week or two ago, I purchased the Jawbone bluetooth headset which has got a lot of reviews as the best bluetooth headset in the market. I should say I am pretty impressed. The noise canceling feature is just awesome, people on the other side rarely hear any other noises other than my voice. After trying the multiple ear pieces and loops and fixed on a set. I haven't used a bluetooth headset before so I can't really compare. My long calls started turning effortless and I was pretty happy with the piece. Worth every penny, oh yeah..

And then the inevitable according to Murphy's law had happened. I broke the left standard ear loop. I was trying to remove it when it broke. I called up the Jawbone support guy. They wouldn't give their number on the website but a quick Google search revealed their support phone number 408-848-4348. The customer service guy was cool and he told me that he will send me a complimentary one in 7 business days. Now, how cool is that. I didn't know you could also buy the ear loops from their website, you pay $10 for the ear loops but then you will need to order the 4 piece set. I should say that I am pretty impressed both with the piece and the customer service. All the negative reviews on the web, I guess those guys were probably having a bad day :)

Monday, April 28, 2008

Too smart or too novice in Java: Relevance of for loops

During the course of my work, I have had to fix some code written by others and modify existing code for enhanced functionality. In one of such projects, I encountered this piece of code written by someone


for(boolean valid = false; !valid; valid = true)
{
try
{
sp = spf.newSAXParser();
parser = new ProjectParser();
sp.parse(projectFile, parser);
}
catch(Exception e)
{
e.printStackTrace();
log.throwable(e);
throw new RuntimeException((new StringBuilder("Unable to parse ")).append(projectFile.getAbsoluteFile()).toString());
}
}


Let's see how this for loop works. It initializes a boolean called valid with a value false. The condition is until valid is false. The increment is making valid true. And then inside the loop, the coder wants to accomplish something. Now what is the point of this for loop at all. Was the for loop used because the coder didn't know that loops are used for, you guessed right, looping. If he/she just wanted it to run only once, then what is the point of using a for loop at all. How different is the below code from the above code.


try
{
sp = spf.newSAXParser();
parser = new ProjectParser();
sp.parse(projectFile, parser);
}
catch(Exception e)
{
e.printStackTrace();
log.throwable(e);
throw new RuntimeException((new StringBuilder("Unable to parse ")).append(projectFile.getAbsoluteFile()).toString());
}


This would execute the code only once and that is the desired behavior that was accomplished by using the for loop for once. I think keeping your code clean and staying away from such unnecessary stuff helps you in keeping your code clean and reducing any unwanted bugs. Why turn the hand around the neck to eat something when you could directly eat it.. Is this trying to be too smart or being too much of a novice to know what loops are used for. Or is there something, that I am missing that is something great that I haven't realized in using this type of code. If someone could elaborate, I would be glad...

Friday, March 14, 2008

Pay auto/car Loan or Invest in a CD or other investment. When do you break even

The previous post of mine on auto loan had lots of discussion and ifs and buts. I decided to make it pretty simple this time. Here is the case. You have $10000 with you today, that you can use to pay off a car loan of equivalent amount which is at a interest rate of 5.5% or you can pay the monthly installment on the car loan and invest the current $1000 you have in a CD or shares..

Analysis
--------

Current car loan = $10000
Interest rate = 5.5%
Term = 2 years or 24 months

From Bank Rate Calculator the equal monthly installment is $440.96

Let us say Best CD rate available is 5% (which is impossible at this time). So the case under study is that you have $10000 in hand today and you have $440.96 from your monthly income available to you to pay the car loan

Pay the car loan
----------------

In this case you paid off the car loan and you put the $440.96 in a Savings account like ING Direct. Let us say in an ideal scenario you are making 4% on your savings account (ING doesn't offer this interest at this time). So putting $440.96 in a Savings account for 2 years, at the end of 2 years, (from dinkytown)

Total = $11,505
Taxes = 28% of (11505-10000) = $421.4
After taxes total savings = $1083.6
After paying taxes, money you have with you = $11083.60

Put in a CD
------------

From Bankrate $10000 at 5% for two years will yield a total of $11,052.

Total = $11,052
Taxes = 28% of (11,052-10000) = $294.56
After taxes, net with you = $757.44
After paying taxes, money you have = $10,757.44

Paying the car versus CD
------------------------

Difference you lose by not paying the car loan and investing in a CD = $11083.6-$10757.44 = $326.16

Incentives for not paying the car loan is the fact that you are only liable to $441 a month, if you lose the job or if you are on bench in consulting, then you have $10000 with you and you are only liable to $441 a month. So, that makes it easier for your mental peace

If you do not put in a CD and invest in shares or something, then what percent interest rate on your $10000 investment justifies your not paying off the car loan? lets calculate that. This means that your $10000 has to become $11,505 in 2 years. Using the formula for compound interest, that would be 7.26% assuming interest compounded annually. That is a very low interest rate compared to gains on Shares. But then, you never know about Shares. You might as well lose your money.

So, that's the calculation folks. Know your facts, analyze your situation and make a good decision :)

Wednesday, March 12, 2008

Overcoming cross domain issues through php proxy server in Flex for RSS Reader samples

Today, I took a second look at my home page and decided that the blog link should not directly point to this page and should have an in-built RSS Reader for getting these posts there. And then the troubles started. People who know me already know my website and know that it was built in Flex. I had this idea of an in-built RSS Reader in my home page for long, but whenever I started working on it, I would have weird exceptions on page load, which were not straight forward and I wouldn't have time to debug them. So it remained the same, a hyperlink to this blog. Today a post on DZone caught my attention and I again tried this. I found a simple example which I implemented in my home page and thankfully everything went cool. But when I put it on the server, another problem started. The cross-domain problem..

The thing about flex is that, while being cool and xml dominated, the biggest problem is with the fact that you cannot load the rss or xml from other websites, without a cross-domain.xml file on the serving domain that lists the calling domain. Now I cannot ask blogger.com to put my domain name in their cross-domain.xml file. Can I ?? So I preferred the alternative route, which is widely written on the net, the proxy server route. And though I do not have Java hosting by my space provider, they support php and went for a simple php script..

<?php
header('Content-Type: text/xml');
$url = 'http://cognitivecache.blogspot.com/rss.xml';
$content = file_get_contents($url);
echo $content;
?>

The script looks so simple like a no-brainer right. Nope, that wouldn't still solve my problem. Because, the blogger wouldn't let the php script open a stream and I kept ending up with this error

Warning: readfile [function.readfile]: failed to open stream: No route to host..

After changing the scripts from the net thrice hoping the other one would be different, I kept coming back to the same problem. Finally I realized that it could be an issue with Blogger not allowing an incoming connection. Boom, that was it. I changed the code to point to my feed in FeedBurner and that was it. My new code looks like this

<?php
header('Content-Type: text/xml');
$url = 'http://feeds.feedburner.com/CognitiveCache';
$content = file_get_contents($url);
echo $content;
?>

Now, The RSS Reader gets its content now and it looks like a nice addition. A Happy ending to lot of time spent indeed !!

If you are still wondering about the whole process, what you need to do, is to burn a feed in FeedBurner and put the above code in a file called proxy.php. Now upload this file to your domain and use the url for xml in your flash file as "http://mydomain.com/proxy.php" and thats it..

Saturday, January 5, 2008

Taare Zameen Par - Because every kid is special...

I haven't done my homework and prepared for the exam well. I was hoping and praying that the exam would get canceled, I was praying to God again and again that something should happen, a flood or earthquake should come so that the exam gets canceled, and I don't fail. Because failing the exam is a doom, that would set a downward spiral on, which would leave me with no future. I won't have a place to live or food to eat in future. What could I do now. The thoughts of "if only" run through my mind as I promise myself, if somehow I pass this exam by God's grace, I will always prepare well for every exam in m life.


Source: Movie Home

And boom, I suddenly wake up in the middle of the night realizing it was just a dream, realizing that I have finished my Masters and am in a stable job making a decent salary and set for a decent career. But why do I still get these dreams. My parents never compelled me for anything. Still there was fear of exams, fear of failing, fear of going nowhere in life, that has captured my thought process so vehemently that even at about one-third of my lifetime, I still get such dreams. Is it a psychological disorder. Of course not, it is the psychological set up of almost every Indian student who has gone through the rigors of Indian system of education, the stress of what the society would say if you fail. Is the fault with the Indian system of education. Nope. the fault is with the societal mind set in India or at least in Andhra Pradesh, where you have to be an Engineer or a Doctor in your life. Other career options don't even exist..

The thought process above was triggered in me, after watching the movie Taare Zameen Par. A wonderful movie that takes us through the journey of a kid who suffers from Dyslexia. Trying to camouflage his inability to read and write like other kids in a cover of stubbornness and frustration, Ishaan slowly loses interest in one thing he is the best at, painting. As Aamir points out, his parents and teachers were seeing the symptoms of the problem, but none try to understand the reason for his problem. It is not that he does not want to read and write, its just that he cannot. Having suffered through the trama himself in his childhood, Aamir sets out to help the kid. With the kids' Dad not understanding the situation, he gets the help of the Principal to get the kid to normality by giving him ample time to learn things his way in his own pace. And guess what, he brings progress in the kid by projecting his positive points and building up his confidence.

A really wonderful movie with superb action from the kid who portrayed the role of Ishaan. Aamir Khan performs well enough, but the best part in the movie is his direction. His sincere attempt at a heart touching story strikes an emotional cord or two by making you fell for the boy, because you have been there! Overall cent percent to Aamir Khan for a honest attempt at a genuine subject, instead of song and dance routine.. Do yourself and your kids or your future kids a big favor. Watch Taare Zameen Par, because it teaches you how to be a real parent. Because it lets you see a child's mindset from his point of view. Perhaps your kid might really benefit from your changed outlook. Perhaps India will see light in careers other than Engineering and Medicine !!

Tuesday, December 18, 2007

Tum Chalo to Hindusta Chale - TOI Lead India "Tree" (India will be what we are..)

No words necessary to describe. The video speaks for itself!!

Monday, December 10, 2007

Genuine attempts lead to Fame, over course of time too

My previous roommate started this site called Sanskritvoice.com a little while ago. We used to discuss about websites, making money from them, or business models. It was then, I asked him, what he was doing this site for, money or fame. And he replied that it was a passion that he had for the Sanskrit language and was trying to do, what he could. He wasn't doing it for money or fame. Recently he got profiled in NDTV. This only goes out to prove that, you should concentrate on what you are passionate about, money or fame will slowly follow your passion, perhaps a little later, though I doubt if money will follow in this case. Check out the video where he got profiled..

Wednesday, October 31, 2007

What happened to the $1. Can you explain? - A simple math brain teaser that leaves you thinking..

So you think you are good at Math and at simple calculations. Here we go. Try and solve this..

Three guys came to a motel and asked for a room with 3 beds. The manager said that the room rent was $30. They said they will check the room and pay for it. So the boy took them to the room, they liked it and each paid with a $10 note and the net amount came to $30. The boy went back to the manager and gave him $30. Then the manager realized that they had discounts at that time and that the room rent was actually $25 for the day. Since he was honest, he gave $5 (5 1 dollar notes) to the boy and asked him to return that money to those guys in the room. While going to the room, the boy thought that they cannot share the amount of $5 equally and since they didn't pay him the tip last time, he thought that he will take $2 and give them back $3 so that each gets $1 back. He silently slipped $2 into his pocket and went to their room and gave each guy $1. Everyone was happy.

But here is the question about it.. Initially the three visitor guys gave $30. Each paid $10 and got $1 back. This means each paid $9 and so the total they paid is $27. $2 were stolen by the hotel boy. We have the count for $27 + $2 = $29. What happened to the remaining $1 ???