Tuesday, January 24, 2012

Facebook Hacker Cup

    The Facebook Hacker Cup qualification round results came out yesterday night. I had attempted 2 out of 3 questions and both of them came out correct. Yay! I am actually lucky to have solved 2 questions as I was procrastinating about solving another question after I submitted the first one. You need to submit only one correct solution to get qualified further. This procrastination cost me in terms of time penalty but we can ignore that.
    Here is the list of questions: https://www.facebook.com/hackercup/problems.php?pid=215823855164332&round=146094915502528
   As only 22 people all over the world solved 3 questions, I am cool with my result :)
   Now the round one starts at 10 am PT on 28th Jan which means it will start at 11:30pm India time :'( I can never work at night :(


Wednesday, January 11, 2012

Installing Linux (Ubuntu 11.10) on Virtual Box

   Hey all! Here's a post on how to install Linux on a virtual box. I will be giving the demo on a Window 7 machine, using Virtual Box version 4.0.10 and will be installing Ubuntu 11.10 on it. So, let's start!

First step: Getting Virtual Box
You can download it from here: https://www.virtualbox.org/wiki/Downloads It is a  simple exe, just run it and you have your virtual box ready!

Next: Get Ubuntu

The direct download link is this: http://www.ubuntu.com/download/ubuntu/download .  Make sure you select 32bit version for your 32 bit computer and 64bit version for you 64 bit computer.

Start your virtual box and click on  new Machine icon.

It will open up a "Create new Virtual Machine" Wizard.
Click next and then it will ask you to give name to the machine. I entered Ubuntu and it automatically set the Operating System to Linux and version to Ubuntu. You can set them manually as well.

Click on next and it will ask you to give base memory. I gave 1GB but it is upto you. For Linux 512MB to 1GB is good enough. Click Next.
Now you are at "create a boot hard disk". As this is your first installation, you do not need to make any changes and just click on next.

Now it will open up a "Create New Virtual Disk" wizard. Click next.
Here you have an option to create dynamically expanding storage or Fixed size storage. It is best to use dynamically increasing storage. Moving on,
It will ask a location to store your new virtual disk. Select the location of your choice. Then in the size part, select the disk size of your choice. The default 8 GB will be enough if you do not want to install much of applications on your Ubuntu otherwise, select 4 or so GB extra.Click Next
Click on Finish and it will give you a summary of your new machine. Click on Finish or go back to make necessary changes.
Now the installation part is half complete.

Next: Configuration
Just a little time over here.
Select the new machine you created, go to settings. Now go to Storage and click on IDE controller. Now in the attributes section, click on the small disk icon. Select the copy of Ubuntu that you downloaded and click on OK. That is all the configuration you will need.

Now click on the start Machine Icon.
At the first run, Virtual Machine may ask a few configuration questions. Just read them and take necessary steps. It is very easy to do so!
Once Ubuntu is booted, it will ask whether you want to install or just try Ubuntu. It is your choice what to do. Though, if you do not install Ubuntu, all the work you do on the machine, will be lost, the next time you boot it. Hence, it is better to install it.

Again, installation will ask you some questions, and again, they are very simple It will ask you whether to install updates with installation or after it and so on. Installation will take some time. After that, you are all set to play with your Virtual Machine!

Monday, January 9, 2012

Infinite Redirect and effects on browser

   Its always great to do something that messes your computer! How about doing something that makes your browser take up 50% of your CPU!
  Javascript has window.location object, generally used for redirecting your page.
 e.g. window.location = "http://www.google.com" redirects you to Google homepage.
 What would happen if you redirected the page to itself! An infinite Reload! Just to see how the browsers behave when this happens, I created an html page with a javascript code redirecting it to itself. As expected the result was an infinte reload happened and the browsers gulped 50% of my processor! I was hoping the usage would go up but it didn't :(
  I was wondering if there was any way, that the browsers could stop this from happening.I found 2 solutions:

1.The browsers can keep a count of number of reloads of a page and on reaching a certain number, the browser can simply kill the page or stop it from refreshing. But then, sites keeping live scores tend to keep on refreshing and you wouldn't like it when the site stops loading at a crucial moment in the game! The solution to this problem could be browsers keeping a count of average time between 2 reloads. If the time is smaller than some smaller certain amount, the page can be stopped from reloading.

2. Web browsers get the javascript code right? So, they can simply ignore the line where the page redirects to itself, if the code line is not within some function. Maybe the