Sunday, December 31, 2006

Kurukshetra was a flop show



The Kurukshetra online programming contest (FLOP SHOW) was supposed to start at 2PM today, but due to mysterious circumstances was rescheduled to begin at 2:30 PM. At 2:30 they again postponed it to start at 3PM. And guess what the site goes down at 3PM. Somehow I managed to get the questions and also solved one, but then since the site is down I was not able to submit it and that really put me off.

Guys!!! was this supposed to be a joke. Maybe someone just thought of playing a practical joke on us geeks. Well they better not be playing a prank because if they are, then as Russel Peter's father says "Somebody is gonna get a hurt real bad!!"...

Bottomline. If you cannot take the load, dont host the contest. No point preparing the questions if your site goes down during the contest..

Saturday, December 30, 2006

My good deed for the year 2006

On 30th December at 10:50 PM as I am sitting in my room in front of the TV and reading "Introduction to Algorithms", I hear a LOUD crashing sound in front of my house and rush downstairs to check out what happened. I see a stranger was lying down on the ground holding his left leg and besides him in the drain standing upright was a motorcyle. I went up to the man and asked him if he is ok. On enquiring he told me that his name was "Sarvanan", he is a "Tile worker" (the ones who lay tiles) and that he was riding under the influence of alcohol. He lost control and ended up crashing in the drain.

At this moment enters my neighbor "Seshadri" (who just returned from USA after completing his MS and was going back in a couple of days to start his PhD). I hadn't met him in over 2 years, so we meet look at each other say "Hi" and get to work taking the bike out of the ditch. The right side of the bike was completely totalled and after looking around we realized that the right side of the bike crashed into an electric pole before the bike ended up in the drain.

We asked him if he had a mobile phone (aka cell phone) so that he could call some relatives or friends. He said that he had given his mobile phone to his friend (What a bad time to give your mobile phone to your friend). He finally gave us a diary which had a couple of numbers. We dialled those numbers but no one at 11PM was lifting their phone. Finally someone lifted the phone and they did not know who Sarvanan was and we wasted like 5 minutes asking him if he knew who this guy was and if he could come over to take this guy home.

In the mean while another neighbor of ours kept asking the injured person whether he was driving fast and why was he driving fast, and I kept thinking "Hello... Can we do the root cause analysis later. We have an injured person here."
(With crimes on rise in cities and news channels showing us all the gory images of crime and deception we didnt know if we could trust this guy, but he looked hurt so we decided to help him)

For a moment we thought of calling the cops but then we didnt want the poor person to get into any more trouble than he already is in. He said that his friends lived in a one room shelter nearby, so we decided to drop him there and that they would take care of him. So I took out my car and we drove him to the place. The place was in a side road where the car could not enter to we carried him on our shoulders (like the injured soccer player who has too much pride to be stretchered of is carried). We started walking towards the room and he was telling me that he is married and if his boss finds out that he was drunk he might fire him or he would not be paid for some days. Definitely a sad story and for sure he was worried what would happpen to his family. So I just looked back at him and said, shouldn't you have thought about this when you were drunk and were riding a bike. But I guess he was too psyched out to understand what I said to him. But later he would realize it.

Finally we reached his room and started banging on the door. After 5 minutes of banging the door, his friends woke up and opened the door. Seshadri explained the situation to them in Tamil. We asked one of them to come with us to see where the bike is and also take its keys.

Finally at 12AM on 31st December 2006 the ordeal was over. Hope Sarvanan recovers soon and that next time he thinks a million times before he drinks and rides.

I am feeling good about helping out a person who needed help. It is a nice feeling, but I dont want you guys to fall in a ditch for me to have this nice feeling. Drive safe!!


PS: I almost forgot Harishh JP (my partner in crime for SQL injection attack on trendio and my partner in Kurukshetra) also met with an bike accident day before yesterday. He bruised his hands and legs. Wishing him too a speedy recovery!!


Yet another PS: Sadam was hanged today. Why was he hanged in such a hurry? My comments on it, COMING SOON!!!

Kurukshetra

Kurukshetra is an online programming contest. Got to hear about it yesterday on the Yahoo!'s internal mailing list.


Played around the site.
There are 3 test problems given. I already got 2 solutions accepted. Yay!
The solution for the 3rd problem ( Reconstructing Permutations ) is working but gave me time limit exceeded. Need to fix it up to make it more efficient.

It is good fun...

The main contest is tomorow. It starts at 2PM and ends at 8PM.
So there is a day of hacking/coding ahead for me. I plan to team up with Harish for the event.
There is place for one more person on the team. Anyone interested??

May be I will discuss the problems and how to solve them (Only the approach, no solutions for you folks ) in the upcoming posts.

Friday, December 29, 2006

Semi Non Chalant pose at Golconda

Ok.. For anyone who has seens Friends Season 10, remembers Joey's non chalant pose.
We got Naveen (A full time member of Ashtam) by chance giving a semi non-chalant pose at Golconda Fort in Hyderbad.

I know I know Joey's pose is much better but anyways look at the similarities.. The hands on hips, the head tilted to the left.











Joey

Naveen






Click on images to see full screen images.

PS: Naveen did not know about me planning this blog post and supplied me with Joey's non chalant pic.. Also this pose was given by chance and he had no intentions to look like Joey :)

Comments welcome...

Jaspal Bhatti

Jaspal Bhatti is one of my favourite comedians. He has acted in shows like Ulta Pulta, Flop show etc.. And during our campus visit to Punjab Enginnering College, Chandigarh in Novemeber we ran into him at the hotel's restaurant. Here is the snap to prove it :)


(Click to see full screen image)

People in the pic (Left to right): Amitava Ghosh , Prasanna, Jaspal Bhatti , Me (The blogger) , Badi Kumar (First spotted Mr. Bhatti).

Photographer: Syam (aka Uncle Sam)

Missing from frame: Vishnu (HR)

Thursday, December 28, 2006

Easiest 5 vadas I ever earned

I had been to Hyderabad for the weekend to meet a friend of mine (Girishar) working in Microsoft.
On the way back I got into a discussion with my another friend (Karthik U) about latitudes and longitudes. He asked us what is the line passing through the Earth with 0 latitude called. I said "The equator". He said "No, thats the line having 0 longitude". Then I said that "the latitudes are the lines running parallel to the equator and the lines perpendicular to the equator are called longitudes". He did not agree so we decided to bet 5 vadas at veena stores (Veena stores is a world famous in Malleswaram, Bangalore hotel which sells the most amazing vadas).

And no prizes to guess who was right :D

Information about latitudes and longitudes can be found here

Hoping to get my vadas soon.... :)


Latitude:




Longitude:




Vada:

Sunday, December 24, 2006

Dog Food

Microsoft calls the process of releasing a beta and getting feedback on it as "Dog fooding".The beta is called dog food. So what does that make the people who consume the beta? ........ You bad bad people.. What were you thinking, they are called beta customers :)

Well then what do they call the bugs found in Dog food?

Friday, December 22, 2006

Gizmos.com

Found this new site.. Really cool. They made animated heads and let you make avatas,gags out of them..


Really cool. Must try... www.gizmoz.com

Here is one of the videos they have on the site.

Wednesday, December 20, 2006

open Yahoo! hack day




One of the presentations at the open Yahoo! hack day held in Sunnyvale

Very funny prank on telemarketers


Saturday, December 16, 2006

www.trendio.com

I really like playing this game www.trendio.com
It was good fun till the site got redesigned and I lost all the virtual money I made on the site. They also ajaxified the site and added lots of other things making it real heavy.

Yesterday myself and a friend Harish JP were talking about ow much we missed playing the site and decided to check out if the vulnerabilities were actually an issue with the site.

Pretty soon we hit this loophole..

You can try it out yourself:
1) Log in to the site
2) Check out the link
http://www.trendio.com/word.php?language=en&wordid=1246 or id = 1279
3) It shows you a word which costs 0.01$. Then go ahead and buy as many shares as you want of that word, on the page.
4) Come back to your portfolio and check that the word magically turns into the "Earthquake" word, which has a value of 63$

So the bottom line is for every dollar you put in buying the word you get 6300 dollars.

I tried it out, made a billion (virtual) dollars and here is the rank list from today morning.



PS: I am informing Jensen the creator of this site about this issue so it might not be around too long. I hope he sends me the geek T-Shirt :)

If you are not a technical guy I would suggest not to read what is written below coz you might want to pull your hair out..

Now here is why this happens and how to fix it:
The site uses PHP and MYSQL as the backend.

He receives the data from the form as a GET request which is visible to the user in the address bar of his browser.
(NOTE: This is a mistake. You should always use POST method. Dont let the user know more than he needs to know)

The GET request looks like http://trendio.com/word.php?language=en&wordid=1 in the browser for the Earthquake word.

Now that I know the request he sends and what variables need to be set, I play around with it.

I change it to
http://trendio.com/word.php?language=en&wordid=1'
NOTE: There is a single quote at the end of the wordid

The MYSQL database expects the data in wordid to be a number but it recieves a string so it throws out the error.

"Error: Unable to perform query: SELECT method, word, lastquot, variation, categoryID FROM words_en where id=1' :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1 "

This query gives me the structure of the database and I know what query is being generated.
(NOTE: The error generated by the mysql_ php functions should not be displayed to the user. Use a @ in front of the mysql_ functions to supress the error messages from being displayed and handle the error elegantly in the code)

Also the wordid should have been checked using the isint() function in PHP.
Eg:
if(isint(_GET['word_id']))
{
$result=@mysql_query("select blah from blah where blah limit blah");
// Do something
}
else
{
print an error message
}

This check would have solved most of the issues.

So just few small checks can make sure that the SQL injection attacks are avoided.

Also when you take inputs from users parse it to remove HTML tags..
If I put in a comment like
<script src="http://blah/blah.js" />
and it is not parsed would not be shown but executed on the other users browsers who open the page to read the comments. Use the strip_tags function in PHP to strip out the unwanted HTML code from being submitted.

Hope you find this blog post useful.

Jensen,
hopefully you would fix trendio (PS: Kindly restore my 46 million $ I had with the old trendio. While you are it, can we get back to the old interface also.) (PS: Can I get a Geek T shirt for pointing out the bugs with trendio ??? )


Final PS: I am willing to help you fix the bugs provided you give me access to the code.

Friday, December 15, 2006

SQL injection >:)

Why is the wen so broken. www.guruji.com a few days ago and now another site (to be revealed in the next blog post)..

This site had a SQL injection vulnerability along with XSS.

People please make sure that your site is not vulnerable to SQL injection attacks and XSS. Here is a list of don't for your website:
1) Dont use GET method to post forms.
2) Dont stick in the input provided by users into the sql. Check for SQL injection attacks.
3) Dont throw up the SQL in the browser if MYSQL query fails. Use @ before the mysql_ function to supress the query.
4) Dont store and reflect the data passed by user as it is.. Parse it and remove or escape special characters.

More information later...

Working at Yahoo


Working in a chillaxed (Chilled + Relaxed) mode at office...

Thursday, December 14, 2006

Dig through the earth

Made this dig through the Earth hack in the last 5 minutes just to show how cool the Yahoo! maps look.

This is what the page does. Click on any point on the Earth and the app tells you where you would land up if you were to dig through the Earth from that point right through the core of the Earth. You can try it here.

Hack day

Hacking can be so tough.. After being sleepless for around 40 hours and hacking on an online implementation of a variant of the RISK game I got to sleep yesterday night.
Being sleepless is one thing, getting your brains rattled by technology when you are sleepless is a totally different ball game.

Here I narrate some horrors we faced while programming the game. All started well as I started coding and testing the backend for our application on my pretty looking FreeBSD 6 box (shown in the previous post). Harish JP (Another sleepless dude) was doing the frontend using Yahoo! maps and JS on his machine..

Soon we started hitting issues,
1) The internal package that we were using to validate the user was not giving us the name of the users. After breaking our heads for half an our we realized that the package depends on the version of PHP. So it was like on PHP 4 use the variable name ".user" and on PHP5 use the variable name "_USER". If that was bad enoughm, we had worse things coming our way.

2) Somewhere in the middle we decided to move our code to Yahoo's apache server. All of a sudden SAJAX started cribing. A quick look at the logs indicated that SAJAX was not getting $_SERVER['REQUEST_URI'] variable in PHP. After a little digging around and looking at the output of phpinfo() we realized that the variable was not just called $REQUEST_URI .

3) SAJAX was not handling complex objects like arrays of arrays too well. It was opening up the arrays and concatenating all the values into a single array. Not what we wanted so Harish hacked into SAJAX and fixed it to handle such objects. He also put in JSON encoding from another package into JSON.

3) It is a pain debugging JavaScript. SAJAX was working fine but for one case where it just never worked. After painful debugging of an hour we figured out that for this particular object SAJAX needed a set of paranthesis around the JSON encoding and eval( '(' + json + ')') ; did the trick for us...

4) Another issue we faced was swithcing between languages. The way you define functions in Javascript and PHP is very similar but the way you define and use variables is not. So often we got confused between what file we are changing and wrote PHP code like ($nattack > $ndefend) instead of (nattack > ndefend) and vice versa.

5) We also found many limitations in Yahoo! maps. Yahoo! maps are great, believe me but they would have been slightly better with a richer set of API. But I guess there is always a tradeoff, because if someone uses a website with the Yahoo! maps JS included in it. The entire JS would be downloaded on the users machine, which is an overhead and that is what limits the number of functions in Yahoo! maps. (Atleast thats what I think)

After a zillion more issues .. (Note.. hardly any with the logic of the game or the game itself) we were able to complete the game and present it for 2 minutes to fellow Yahoos..

Well 36 hours of hacking... Was it worth it even though we did not win any price. Yeah!!!! We learnt so much about JavaScript, Yahoo! maps, PHP and MYSQL.

And I have new found respect for people working with JavaScript. It can be quite intimidating at times but the language rocks.