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!

“>https://www.youtube.com/watch?v=Sa9gOAIHU1U[/embed]

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.

IMG1695

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.

IMG1458

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

IMG907

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

IMG1602

Wasn’t smoking in public places prohibited?

IMG1604

sexist!!!

IMG922

Freemasons’ lodge just after getting down at mussoorie

 

10365809_10203407791829807_9070906675642337902_n

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

IMG1312

Shiv-ji taking a selfie

IMG1313

not too amused, eh?

IMG1345

IMG1226

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

And finally, Wherever you go, the Birla family follows

1544973_10203407793269843_172103752407019942_n

sneaky one, this

IMG1239

clock tower fetish

The weekends were quite fun, the trips unforgettable

 

Mussoorie and dhanaulti, my first long trek.

IMG921

The city of Dehradun as seen from Mussoorie

IMG_6762

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

IMG956

well said!

 

haridwar, rishikesh the usual tourist spots

IMG_20140601_144821

You shall not pass (the test cases) !

20140601_093118

Rishikesh

IMG1204

Haridwar

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

IMG_0423

lacchiwalla

IMG_20140614_104033

sahastradhara

 

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

IMG1553

IMG_1593

IMG_1575

 

kurukul-gaon, isolated yet beautiful

IMG1635

IMG1668

IMG1663

Dehradun was no less beautiful

IMG_1148

IMG1687

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.

<NOTE>

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

</NOTE>

 

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.

IMG1710

IMG_20140601_144818

 

 

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

IMG_1642

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.

IMG_0411

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.

IMG_6952

Vivek

 

Raghav

Raghav

 

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

IMG_0972

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

IMG_1094

FRI hallway, courtesy KK

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

IMG905

Not even rogan josh, sigh..

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

Almost....

Almost….

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.

IMG_20140603_182953

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

<NOTE>
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 :)
</NOTE>

Introduction

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.

Installation

Shortcut

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.
snapshot1

MySQL

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

PHP

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

<?php

phpinfo();

?>

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

phpinfo

phpMyAdmin

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 127.0.0.1 10.0.0.0/24

These are to make sure that the phpMyAdmin portal can be accessed only at the server (127.0.0.1) 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.
snapshot2

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

Logs

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.

MySQL

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

PHP

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

phpMyAdmin

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

<NOTE>
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.
</NOTE>

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.

403error

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:

ex1

 

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:
exx

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 http://google.com and press enter
4. If the google’s page opens up, congrats

Geeks
1. Open up a terminal
2. type in ping 8.8.8.8

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

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

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

NOTE: 8.8.8.8 is Google’s DNS Server

 

 

A Small Apology

When I started O(lol n), I meant it to be a tech blog, a platform using which

I could share whatever little knowledge I gained with the rest of the world in hopes that

someone, somewhere may find it useful

And well to help out people like below
Image

But I admit, till now the blog has been nothing but that. Its been more of a place for my ranting. Not that I think they shouldn’t be a part but that I’ve lost the purpose for which this blog was made.

Anyway, here’s a small apology.

I do have some ideas on what I plan to write but its better to see them in action than talking about them ;)

For starters, I plan to write ATLEAST one technical article a week
If more than one, great!!. But that does not give me leeway to slack off the next week :)

So that’s all, lets see how the plan turns out.
Thanks

Who Am I?

Who am I?
I’m a statistical Anomaly

An improbable aggregation of atoms formed in the fiery furnace of stars billions of years old
and possibly trillions of light years away,
All formed from a single point at the beginning of time.
spewed at a such high speeds that an aggregatiion like me is improbable,
yet here I am.

Atoms coming together billions of years later into the form that’s me.
On a pale blue dot called Earth right in the goldilocks zone around a mid-sized star on a spiral arm of a galaxy called milky way

After millions of years of evolution, after countless catastrophies, after a cold age,
after being hunted by animals and then taming the very same animals,
after living in caves, after walking thousands of miles from Africa,after epidemics, after wars, after economic crises.
Yet here I am.

In India, one of the 197 odd countries, divisions created by man to “better manage” himself
In one of the 29 states, in one of the 33 districtss in that state, through years of oppression, through floods and droughts
Yet here I am.

With my unique set of friends, “friends”, parents, relatives,
with people who love me and hate me.
A single man in the 7 billion strong ocean of humanity.
A result of a result of a relationship between two of those 7 billion humans.
This is me.

The lone survivor out of the millions of sperms that made it,
A collection of millions of molecules of nucleic acid, in one of the very few optimal configurations out of a googol of combinations,
bound so tight that is not yet achievable by humans.
A blob of biological matter,capable doing things that even it can’t explain,
walking, running, cycling and so on….

Feeling things like love, hate,misery,jealousy,gluttony,pride,pain,agony,joy,happiness,ecstasy.
Everything rolled into one, not making sense more often than not.
That’s me

Capable of imagining things that don’t exist
and having the skills to bring into reality
Or what we believe is reality.
Capable of measuring the heights of the towering mountains,
the mass of planets far away, the volume of water in all of the vast oceans,
distances ranging from microns to millions of light years.
Capable of doing wonderous things with just 1’s and 0’s
Creating theories of how I came about, and where I’m going
and being able to test them
All that and more is who I am

I don’t call myself an existentialist,factist would fit.
I just state the facts, sans the emotional icing that so very often facts come covered in.
guess, I can call myself lucky,
Lucky to be here, right now,when I could I have been anywhere, spanning the entire Universe.

And I have absolutely nothing to feel bad about,for that matter, no one does.
because I’ve always had the odds stacked against me,and yet I seemed to win every time
because the mere fact that I exist is wonderous
And in the eye-blink in the larger scheme of thing that I will be.
I must do everything to make sure,
that I won for a reason……..