Its been a long time since wrote something substantial in a human language. In that time, I have had numerous opportunities to introspect on many things like human relations, how likely is it that I create new ones .etc. All the while, I was aware that I was breaking my promise of one tech post per week.

The hiatus was not intentional, but it did provide a lot of data and many questions have been answered. My last post on Apache web server was agreeably long and I realized that I was trying to pack in too much info into one post. Why would people read anything that long? I’m not an authority on webservers so people don’t have a motive to read it. Even as a writer, its taxing to write a long article as you need to keep a lot of things in mind and proof-reading is a real pain.

I have read some posts, really really long posts by extremely knowledgible people and I have thoroughly enjoyed reading each one of them. Some of the more memorable ones are

There are quite a few, I’m just too lazy to dig through my bookmarks collection

I know that I’m far from being called knowledgible, hopefully one day I’ll be called that :)

In the mean time, I have decided to stick to writing small posts, easy for people to read and understand. [Rule of Thumb: If you can split it into several distinct sections, you can split it into several posts]

No promises this time, I’ll write as much as I can, for my satisfaction. If people like it, awesome. If not, I’ll just have suck it up.

I’m back from a slumber, no more long posts, awesome techy and life stuff to come
(Woah, that was easy)

Farewell Dehradun!

What do you do when you have 28 hours to do almost anything?
Sleep? Read a book?
Probably, if you were comfortable enough

So what is the best option?

Relive the memories, the wonderful experience that was Dehradun!


Never did the fact that PS 1 was over hit me until I got off the train at Delhi. Hot, crowded and bustling with activity, this concrete jungle was a huge contrast from the sights of the day before.


So here’s my two cents trying to capture the two months in as much detail as my memory serves me.

Most people say that you don’t learn anything in PS 1, I disagree.
Granted I didn’t learn as much as I wanted but you can’t expect to learn much in two months, can you?

Just a question, does mastering the puppy and dog bark count as learning?

I did know to swim, but I didn’t know I was this good a swimmer.
Hand-stands,back-flips,bunny hops, quadruple sommersaults  just a list of tricks I discovered I can do underwater.
Even giving a four hour crash course in swimming, I’m impressed with myself.

From a kid who gets nauseated after an earthquake to a guy developing a crowd sourced disaster reporting infrastructure,I did grow a lot ( metaphorically ofc ;-) )
IIRS was my fourth preference after BARC, IGCAR and TIFR. But now I think getting IIRS was the best “misfortune” I had in a long time.

I made a lot of friends, both human and otherwise.


Mickey and Roney

Fireflies!, how could I forget them? Dehradun was the first time I saw fireflies in real life. They seem to have an unearthly glow and I took to sitting outside most nights looking at them.

Just like any human settlement, Dehradun and neighbouring areas too had its own share of weirdness


You need to filthy rich or a special type of stupid to buy this


Wasn’t smoking in public places prohibited?




Freemasons’ lodge just after getting down at mussoorie



Even monks can’t resist the temptation of Cheese bites!


Shiv-ji taking a selfie


not too amused, eh?



I’ll pass the 300ml cock, thank you very much..

And finally, Wherever you go, the Birla family follows


sneaky one, this


clock tower fetish

The weekends were quite fun, the trips unforgettable


Mussoorie and dhanaulti, my first long trek.


The city of Dehradun as seen from Mussoorie


The first time I saw a snow-clad mountain, WOW!


well said!


haridwar, rishikesh the usual tourist spots


You shall not pass (the test cases) !





What startled me about Haridwar was religion’s ability to unite people, yet sadly it is used to do the exact opposite.


shastradhara, lacchiwala, robbers’ cave,  swimming spots






santala devi temple, trek 2km up, climb up a ledge, jump down, run the 2km stretch downhill, done..





kurukul-gaon, isolated yet beautiful




Dehradun was no less beautiful



That’s whats called a room with a view

My pics are not the best, but there’s only so much you can capture with 3 million pixels.
I guess the best things in life can never be captured.


If there are some pics, they are probably from sid’s camera or other people’s phones



Here are few people who made the PS experience unforgettable,

First off, my team mates. Kunal and Harsh, you guys were awesome.

Without you two, i-DRAS would have never seen the light of day.





Thanks girish for being a weird yet fun roomie :-p


Good luck with Waves, Mr. Mohta the wavy baby.

That's how he woos sponsors

That’s how he woos sponsors


Thanks sid for all the trekking trips, without them the weekends would have been a drag.


foo does love bar ;)

So here’s how a usual trip is planned. Nothing happens till 11 30 pm friday, between 11 30 to 12 30, I get a call from siddhant filling me on the plan, finally “Ok, so you have to come to XYZ place by 6 30 am”  ,”Ok”. Minutes later I call vivek and he tells me the route. So at max I have five hours of sleep, wake up and reach there. Almost certainly I miss both breakfast and lunch.

Was it worth? Hell yeah! That’s the price you pay for living on the bleeding edge :-D


Not to mention, thank you, Raghav the explorer and Vivek, may your Mighty Himalayas never be destroyed.







Thanks kunjesh for reminding me what being passionate about something was all about.


Ok, not this..

Thanks to everyone else. for…. well, just being your awesome selves.

Of course, when there are ups, there are bound to be downs….

0. Couldn’t go bungee jumping in Rishikesh, should’ve started a fund-raiser before going there XD

1. Didn’t visit FRI, tapkeshwar, Buddha temple, Tehri Dam or Rajaji National Park


FRI hallway, courtesy KK

2. Didn’t have Veg. Butter Chicken, can’t believe I missed that!


Not even rogan josh, sigh..

3. Twice failed attempts at a train-selfie. Just don’t ask….



4. Didn’t meet Ruskin Bond. Biggest let down of them all. I was outside his frigging home when he was away.

There were others waiting for his arrival

There were others waiting for his arrival



There are just way too many things that I would like to thank people for, but I can’t put it down in words.

That’s what happens when you try to compress two months worth of memories in a single blog post. I guess I will have to end it here.


Here’s to the most swaggity swag, swagalicious super sexy swaggers of all swagpurs in swagaland.


You guys rock!!

Server Side Stories #1 : LAMP

In this post, we shall set up and configure a LAMP ( Linux, Apache, MySQL, PHP ) web server. This is the industry standard for web applications and  although other alternatives such as WAMP and XAMPP exist, the LAMP stack is popular because it has proven to be more flexible, user-friendly and secure than all other options

O. This tutorial will be quite easy if you have previous experience in working with Linux systems (Like Ubuntu, Fedora .etc) and if you are comfortable with using the command line. If not, don’t worry. Go through this tutorial and everything should work fine. Just have a willingness to learn on the fly.
1. This tutorial is for Ubuntu and other Debian derived OSs (like elementary OS, Linux Mint) which use the aptitude package manager, If you are using some other OS, the instructions would be similar. Instead of apt-get, you would have to change the command to “yum” or “pacman” depending on your package manager
for ex. if you see a command sudo apt-get update change it to sudo yum update or sudo pacman update depending on your case.
2. Normal human instructions look like this. Code to be typed in looks this.
3. If you are stuck anywhere or have any doubts, feel free to drop a comment and I will get back to you soon. However a google search should give you most, if not all answers. Just type in the correct set of key-words :)


Since we have already installed Linux, our task now is to install the other three components, Apache server, MySQL and PHP.
The Apache server “serves” your web-pages to people who request it.
The MySQL database is a popular open-source RDBMS used for storing structured user-data.
We will be installing phpMyAdmin which gives a user-friendly graphical interface to help work with MySQL even if you don’t have much idea about SQL query syntax.
PHP is a programming language which is used to create dynamic web pages which change based on user-input.



The LAMP stack is such a popular setup that debian and debian-derived systems have a single command to install all of them together.
However I strongly suggest installing the components one by one because you can learn a lot in the process.
However, if you are in a hurry, this should help you.
Just type in

sudo tasksel install lamp-server

in your terminal and it should take care of the rest, prompting whenever a user input is required
If, for reasons, known and unknown, the above command doesn’t work, just follow along installing one by one.

Apache Web server

Open up a terminal and type in sudo apt-get install apache2 . Say yes to all installation questions.

To check if the installation is successful, open up a web browser and type in “localhost” and press enter.

You should be able to see this if everything went right.


Again type in sudo apt-get install mysql-server-5.5  into the terminal.

During installation, it will ask you to set a password for the “root” user of MySQL, provide a secure,easy-to-remember password

Once you are done, to log into MySQL as root, type in mysql -u root -p

Enter your password when prompted, once inside run the following query to remove anonymous users.
delete from mysql.user where user='';
Once done, type in exit to exit MySQL


Open up a terminal and type in sudo apt-get install php5 php5-cgi libapache2-mod-php5 php5-common php-pear

Once the installation is complete, type in

sudo vi /etc/apache2/mods-enabled/mime.conf

 near line 220 type in
AddHandler php5-script .php
Finally,restart apache server.Instructions on how to restart the server is given later on in this post.

To check if you have installed PHP correctly and to check your PHP configuration,

go to /var/www and create a file with a .php extension (say foo.php),type in




Save and close

Open up a browser and type in localhost/foo.php.


If you have installed PHP correctly, you should be able to see something like this



Fire up a terminal and type in sudo apt-get install phpmyadmin

During the installation, you will be asked to select the web server, select “apache2″ since we installed the apache web server.

You will also be asked whether you want to configure a database, select “no” as we have already installed and configured a MySQL database.

Once installation is complete, type in the following commands.

sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf

sudo vi /etc/apache2/conf.d/phpmyadmin.conf

Go to line 8 and enter the following

Order Deny,Allow
Deny from all
Allow from

These are to make sure that the phpMyAdmin portal can be accessed only at the server ( and nowhere else.

Save and close the file and restart the apache server.

To check if phpMyAdmin is installed correctly, open up a browser and type in “localhost/phpmyadmin”.
You will be greeted by this page, type in the username and password you provided during the MySQL installation and log in.

Ok, now that you have setup the stack and made sure that everything is working fine.
We’ll now talk about the locations of important files that you may need to edit or look up for configuring and debugging purposes.

Important files


The server logs are stored in /var/log/apache2 folder

Here you can see two type of files, access.log and error.log, what these contain is explained later.
If you have been running the apache server long enough, you can see access.log.<<some_number>>.gz files too.
These are archived logs and can be viewed using zcat. The most recent entries will be always in the access.log file,
the next recent are in access.log.1 and the older ones are archived in access.log.2.gz, access.log.3.gz and so on.

To see the latest “N” requests,
run tail -n N access.log

Logs record the IP, time and page requested by various users. Depending upon your configurations, it may have more or less information.
If you are running a website which has a large amount of traffic, the log files can be extremely large.
For example, websites like google, facebook, wikipedia have logs which are potentially TBs in size.

This is the big in big data.

The error.log contains error messages as well as information on when the server was shutdown, restarted .etc. Hopefully, this log should be small

Similarly, the MySQL logs are stored in /var/log/mysql folder. The data they store is similar to what the apache logs store.

The PHP error logs too are stored in /var/log/apache2 folder.

Configuration files

Configuration files are what you use to tweak the behaviour of applications to your needs. This mostly involves opening up the config file and editing the values of  various options, what the option does and how you can change the behaviour are well documented in the respective configuration files and I will not be going into the details.

Apache Server

The main config file is /etc/apache2/apache2.conf

There are several other config files in the sub-directories for configuring the active modules, setting up multiple websites to be hosted on the same server, which ports to listen to .etc. These details are given in the beginning of the apache2.conf file so you can read it whenever you want.


The config file is at /etc/mysql/my.cnf

This file holds the global configurations which applies for all users.You can copy this file to your home directory and rename it to .my.cnf to set user-specific configurations


The PHP config file for apache is at /etc/php5/apache2/php.ini

This config file defines the behaviour of php in the apache server. In simpler terms, how php scripts will be executed in the browser.
If you have installed php command line interface (which is useful if you are running php scripts in a cron job, for example), its config file would be in /etc/php5/cli/php.ini


No prizes for guessing, the config file’s at /etc/phpmyadmin/apache.conf

If you are using the lighttpd server(which is not our case!), the config file would be /etc/phpmyadmin/lighttpd.conf
Apart from these two config files, there are several php scripts which are used to access the MySQL database and to modify the look of phpMyAdmin.
In most cases, you would never have to edit any of these files,not even the conf files of phpMyAdmin

O. You need to  be root whenever you are editing any of the config files (edit with the sudo prefix. for ex, sudo vi /etc/phpmyadmin/apache.conf).
1. Once you have done editing the files, you need to restart the service for the changes to be effected.
for example, if you have edited the /etc/apache2/apache2.conf file, you need to run sudo service apache2 restart to restart apache2.
Similarly, run sudo service mysql restart to restart MySQL.
2. The above case is an example where there would be a new entry in error.log file of apache,go take a look.

Web pages

These are what your users will see when they connect to your server. By default, the index.html file is the first page presented to the user. You can change this file or even create your index.html file to replace it.

The files which can be viewed as webpages are to be stored in /var/www/ directory.

You can create subdirectories here to organize your pages.
This is the default behaviour and you can change it by editing the config file ;)

The 403 issue

In some cases, you can get a “403: Forbidden” error when you try to open a web page in browser.


Like this

This is usually caused due to a file permissions issue. Since you are editing as root, the other users do not have permission to read it.
The solution is to change the file permissions by running the chmod command. Commonly used file permission is 755 (rwx-r_x-r_x), which means that the owner of the file can read, write and execute whereas others, whether the same group or not, can only read or execute the file. This is exactly what we need. (If you are interested to learn more about file permissions in Unix, let me know in the comments, I might write a post on it)
Suppose a file, foo.html is giving you the 403 error.

Just run sudo chmod 755 foo.html and then refresh the page.This will fix the issue.

That’s it!
Congratulations, you have now successfully setup and configured a LAMP stack !!

You can now play around with the config files to see what combination suits you best.

P.S. This is my first lengthy blog post. If there are any typos, please let me know.

Grouping geodata – Problems and Solutions

In many location based applications such as google maps, user data would most certainly contain their location represented by latitude and longitude. To enable quality services and accurate analytics, we need to gather this information as precisely as possible.

For example, the LocationManager class in the android platform provides latitude and longitude accurate upto six decimal places.This level of accuracy is sufficient for almost all location-enabled services. If we are storing this in a database, it makes sense to store all the six decimal places.

However, a problem arises when we try to try to group data for visualization. If the database is big enough, its almost impossible to achieve any meaningful grouping by using the co-ordinate data as-is.

Here’s an example that occurs in the project I am working on. The Google Map has a marker for every report received by the server and groups it if there are any reports with the same latitude and longitude (all six decimal places of both the latitude and longitude have to be SAME )

The  SQL query was
SELECT count(*), Latitude, Longitude FROM `geodata` WHERE 1 GROUP BY Latitude, Longitude

The result:



On further zooming in….

ex3Oh look there are actually two reports!

let’s zoom in further..

ex2Surprise!! There are actually three reports

There were only five records in this example but as you can see, the grouping was ineffective due to the high amount of precision

So how do we fix this

Well, there are several solutions with their advantages and disadvantages. You can decide on which solution to implement depending on your needs

Solution 1: Reduce precision in the input data

This is probably the simplest and dirtiest way around this problem. Just take the first three decimal points and ignore all trailing data.This can be used when your application does not depend heavily on the user location

Advantage: Quick, no computation or disk storage cost

Disadvantage: Loss in data, which can have serious consequences

Solution 2: Create two extra columns which will have the reduced precision co-ordinates

This is a straight-forward way to have a meaningful grouping, have a column say lat_red_prec which will have the reduced precision latitude and similarly for longitude and group using these rather than using the actual ones.

Advantage: Simple, straight-forward and if you’re running analytics which require only lesser precison this will come handy in that

Disadvantage: Two extra columns, if you’re having a huge number of records, the extra storage required may cause latencies while running the query

Solution 3: Group by using the ROUND function

The ROUND() function takes a double value and rounds it off to the nearest integer or rounds it off to the required number of decimal places.
Your modified query would be

SELECT count(*), Latitude, Longitude FROM `geodata` WHERE 1 GROUP BY ROUND(Latitude,3),ROUND(Longitude,3)

This rounds off the data to three decimal places, which is exactly what we want.We can now either save the results of this query to a XML file which can be accessed by the map to plot the markers or execute it whenever a user requests the page.

Advantage: No data loss or redundant data

Disadvantage: If we are saving into a XML file, then we would have to have a cron job to run the query periodically. Hence, the map will not be always up to date. If we are running the query for every request, they will a overhead due to rounding off and hence may reduce the service quality
Irrespective of the solution used, final result should be:

As you can see, we have data loss and hence the marker has changed its position but only by a small amount. Depending upon whether this deviation is tolerable, you can set the parameters to the ROUND( ) function.

Happy coding :)



How to check if you’re connected to the Internet

Keeping up with my promise, I thought I could start with something simple, almost funny even, yet a very important question

How to check if you’re connected to the internet, the biggest knowledge base known to mankind.


Normal People
1. Open up your browser, in my case it’s firefox
2. Click on the long tab on top
3. Type and press enter
4. If the google’s page opens up, congrats

1. Open up a terminal
2. type in ping

3. If you get a reply, you’re connected to the net

Normal People
1. Typing in works too!
2. You can directly search for something instead of going to google first

1. Try out traceroute (You need to have traceroute installed first)
2. Try out sudo ping -f

NOTE: is Google’s DNS Server