Friday, October 12, 2012

Pulling data from launchpad repository even if SSH is not available

    All the curses that English language has to offer will not be enough to calm me when I think of my college's network administrators. You can see in their faces that whatever you request them to do, their answer is going to be NO. No matter how much I requested them, they did not allow me SSH access to outside world :(
    Here's what my problem is: I contribute to open source projects which have code on launchpad and I use bzr to manage my code. Now since SSH is blocked I am unable to pull/push (get/send) code to the launchpad server.
    At first I thought of tunneling SSH over HTTP but then I realized that it would require configuration over both Launchpad and my side. Now obviously Launchpad would not make changes to it's server just because some network administrator is harassing students. So I went over the #bzr IRC channel on freenode (for solving a doubt, first comes Google and then comes IRC). As expected I got a solution for my problem. Though the solution was a partial one as it only solved my problem of pulling data and not pushing data. Anyways, here is the solution that they suggested.
   remove 'launchpad_username' from bazaar.conf and deleting the launchpad.net section of authentication.conf This will make bzr use HTTP link. Ignore bzr telling you that you are not logged into launchpad.
   It will behoove you to keep the old versions bazaar.conf and authentication.conf as you will need the details when you push the code. Now it will be irritating to move back and forth between the 2 configuration files but hey! at least you are getting up to date code! You can of course write a shell script to do this task for you :)

  

Monday, September 3, 2012

Possible problems with your django installation

In case you have installed Django using a package manager, then there are chances that you will face the following issues and the django installation pitfalls page might not help you. I faced the same and here are the solutions that worked for me.

django-admin.py not found:
The reason for this error to occur is, the directory of the file does not belong to your system path. You can either add the directory to your path or simply link your file.
How will you find the directory location?
Here's how: in your python shell enter the following commands
>>import django
>>django.__file__
Then type this in your terminal to add a link to django-admin.py:

sudo ln -s {location}/django-admin.py /usr/local/bin/django-admin.py

Another error would be with the installation of database backend:
For example, you would not be able to add mysqldb database. Probable cause for this problem is that you do not have the package 'python-mysqldb' installed.
Installing the package should solve your problem.

In case you are going to use openid or any such service, it is better to check whether the required python packages are installed.

  

Friday, July 27, 2012

cenv: create your own environments

     Everytime I start coding for GTG, I have to start terminal, nautilus and a browser(in case of bugs ;) ). For a lazy person like me, this is a very boring task. Hence i just came up with an easy solution : environment creator which takes a set of your tasks and turns them into a linux command.
     With all the tasks done in just one go, I can consider it to be a productivity enhancing tool (though it's primary purpose was to help lazy bums like me :P ). All sorts of work environments can be created with this tool. You can have one called "work" which like mine, starts terminal with vim/gedit, nautilus and browser. You can keep one for home which could maybe contain nautilus with your songs folder opened up, a music player, a todo list manager if you have one etc.
     Another added advantage for this tool, is that you can create macros for yourself. Say you have a habit of backing up your files to your external device regularly, you can just create an environment called "backup" with all the copy commands. Heck, you can even add one environment inside another environment because these all are actually turned into linux commands only!
     Right now I have features like "new", "remove" , "rename", "edit" etc. but further more features will come up in a week of 2. The very basic version is ready and I plan to launch the version 0.1 by next Saturday.
     Here is the link to the homepage of the launchpad project: https://launchpad.net/cenv
     I'll let others contribute to the code after the launch of version 0.1
  

Wednesday, July 11, 2012

How random can people think?

    Since, I have been doing some research work at college these past 2 months. I have been getting several weird ideas of surveys and testing stuff
    I first tested my laptop's performance with 100% power usage. Will share the results in the next post. Now I want to know how random can people think.
   We may think that we are selecting some random number but always there is a certain number which comes to our minds first. For example, when giving math problems to my mom's students I often selected the numbers 23 and 32. Don't know why. Also, there will be a number which is a common favorite of the mass and is bound to come often in the survey. Lets see the result.
   Here is the link to the form. You just have to enter 5 randomly chosen numbers. Don't take too long to think the random number. Just type the first 5 that come to your mind!
   https://docs.google.com/spreadsheet/viewform?formkey=dEp0U2dfTV9VaHQxeDJQU0Zad3hqc1E6MQ

   Will share the results next week

  

Wednesday, June 20, 2012

In place swapping of n digits? Okay done!

    Yesterday in order to solve a coding question I had to swap 4 digits in place! Now I knew the formula to swap 2 digits in place, so I thought, the math cannot be that hard for n number of digits can it?
    Turns out I was right! I tried creating some formulas and then, ahha! I found it! Really simple one! Here it is:
   Say you have variables a,b,c,d and you want to assign values in this fashion:
   a->b b->c c->d d->a. This is how you'll do it:
   a = a+b+c+d
   b = a-b-c-d
   c = a-b-c-d
   d = a-b-c-d
   a = a-b-c-d
   This can simply be extended for n number of digits. Easy naa!

  

Sunday, May 20, 2012

Busy days going on

    Well believe it or not I have been busy! Hence was not able to post anything since long. Though, the good thing is, I have been busy working on things that I love and hence I am not getting bored! Here are 2 things that I am working on right now.

1. Getting Things GNOME!
         Getting things GNOME! is an organizer for Gnome Desktop environment. Needless to say that it is an open source project. It has a really cool team of contributors. I have solved bugs related to event handling and UI so far. Some updates are waiting approval. All in all, this is my first experience of working in a software team and the conversations on IRC and mailing lists has taught me a lot!

2. A project on Wireless Sensor Networks
         I am doing a summer internship under my college professor where I will be working on a secure data aggregation and intrusion detection system for Wireless sensor networks. It is not sure as to which part of the project will I be working on right now. Currently I am learning programming for TinyOS using Nesc. It is a really interesting project. I get to read several research papers and will be learning a lot about encryption and cryptography. It will be real fun!
 
   I have further projects in the pipeline but I have no clue when I will be able to work on them. But for the next 2 months these will be my primary focus.

  

Friday, March 30, 2012

Directi internship questions

    Hello world! Sorry didn't publish anything since long, I am lazy and you know it.
        Anyways, due to our performance at ICPC Asia regionals at Amritapuri, I got an internship offer from Directi (big deal :) ). As a part of the interview procedure I had to give a phone interview totally based on Algos. I was asked following 2 questions:
    1. Given a number, find the smallest number larger than the given number and consists of the same
        digits as the given number.
        i.e if input = 123 then the answer would be 132
       
        Soln - Start from the last digit, move till u find a digit smaller than the last digit and then place the last      
                  digit in front of the found digit and then sort the digits present on it's right hand side.

     2. Given an array ,for all members x find a number y such that:
             y<x and pos(y) < pos(x) and pos(y) is closest to pos(x) [pos(x)=position of x in the array]
         i.e given 1,2,5,3,4 answer will be 2:1, 5:2, 3:2, 4:3

         Soln: Stack comes in handy over here.
                   Place the first number in stack.
                   Now for every member check the top of the stack. If it is smaller, then the number is your    
                   answer, or else, pop the top and again check.
                   Once, you find your answer, push the current number also in the stack.

  

Monday, March 5, 2012

Linux Cron Jobs

  I have always envied Iron man for Jarvis and all other cool toys that he has. I used to envy all those people who had some or the other type of automation in their life.
  Even I wanted some automation through my computer. First I had thought of making a twitter bot that would tweet the news of the day from Wikipedia. I had also a php script to scrap the necessary data . But, then I got bored of the idea and hence dropped it in middle (nothing new for me).
  I come to my room everyday at 12:20 from my college. So, I thought, how about getting my media player ready by the time I reach my room? (Cool Idea huh!)
  I already knew that I had to simply create a cron-job for this. The question was "how?". Well, what is Google for? A simple Google search told me that I just had to enter the command
     crontab -e
  It will ask you for your favorite editor. Select the one of your choice. It opens a user cron file. Now, for people who don't know what cron file is, well in simple words, you enter the time and command and then your computer runs that command on that time. The format of a cron file is:


   m h dom mon dow command
   m-minute
   h-hour
  dom-date of month
  mon-month
  dow- date of week
  command - command to be run

  you can enter * at any field (except command ofcourse!) to run that command every minute,hour etc.
  you can also input range in the form [1-5]
  also, you can give an interval like */2 i.e occur every 2 minutes etc.
  Enter the proper value in each field and enter the correct command. And then save the file. Thats it! You have now a command that will run automatically!
  One thing though, the output of the command will not be shown on the screen but will be mailed to you.
   Also, an important thing: If you are starting any GUI application you need to give command in this format:
   env DISPLAY=:0 command
   e.g env DISPLAY=:0 firefox

   Now, who is going to keep his/her morning alarm using a cron-job? :)


Saturday, February 18, 2012

Scraping Data: Getting only what you need

     It has happened several times that I have visited Wikipedia home page just to look into today's history. But, then there is so much of information, that you simply get distracted, don't you? So I decided how about, getting just what I needed? I had once stumbled upon a CS 50 video on Scraping data from internet, hence I had a basic idea as to what to do.
    But I googled a bit, coz I wanted to get something which was more recent and something that made my work very easy. Thankfully I stumbled upon, simplehtmldom parser . It made scraping of data so much easier. You don't even need to worry about completeness of the code! I just had to go through the HTML of the page and identify where the information was placed. Well, here is the code that I used to get my information.


<?php
  include_once('simple_html_dom.php');
  $html = file_get_html("http://en.wikipedia.org/wiki/Main_Page");
 echo $html->find('p', 4)->innertext; // Event happening today e.g Independence day
$ret['All'] = $html->find('ul', 5)->innertext; // Event happened in the past
echo $ret['All'];
   $html->clear();
   unset($html);
?>


I have used $ret['All'] just to show you that the output can be stored in another array.
      There is one fault in this code. If there is no event happening today, then the fourth 'p' tag would contain data of some other section of the page. Hence, in order to scrape the data in this manner, you need to hope that the page's html does not change. I have used only some of the features of the simplehtmldom parser, this manual will show you more applications of the library. Happy Hacking!
      If I get a chance I will make a twitter bot, that gets this info and tweets it everyday. Will need to setup some cron jobs for that and will need to learn several other things, but that will be done later.
      


  

Tuesday, February 7, 2012

TT (newer version of timetable)

  Last year I had created a shell script which showed me my academic timetable for the day. I was a newbie in shell scripting at that time and hence the script was not so good. Hence, here is tt or I should say timetable2.0 ?
  This time I have stored my timetable in a timetable.txt file so that whenever I need to modify the timetable, I don't need to modify the script. Also, the code is much shorter this time with not so many if statements. Here is the new code:

#!/bin/bash
days=( Monday Tuesday Wednesday Thursday Friday )

if [ "$#" == 0 ]
then
  echo -e "\nToday's Timetable:"
  set `date +%u`
else
  echo -e "\n"${days[$1-1]}"'s timetable:"
fi
  sed -n $1p < timetable.txt
  echo -e "\n\n"


  Still to be added: Feature to change the timetable. But that's all for now. The new modification will come when I feel the mood of it :)

  

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.

Next:Installation
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