18 Jul

My notes on HTTP headers

HTTP stands for Hyper Text Transfer Protocol. It is the core protocol for world wide web. HTTP headers are the main part of the HTTP request/response and they carry information about the client browser, requested page, server and more.

HTTP Request Structure

The first line of the HTTP request is called the request line which contains 3 things:

  2. Path – path of url after the host
  3. Protocal – HTTP and version 1.1

The remainder of the request contains HTTP headers with “name:value” pairs on each line.

HTTP request methods:

  1. GET : retrieve a document
  2. POST : send data to server. Even though you can send data to the server using GET and the query string, in many cases POST will be preferable. Sending large amounts of data using GET is not practical and has limitations.
  3. HEAD : Retrieve header info. With this method, the browser checks if the doc is modified (for caching purposes) or whether the doc exists or not
  4. PUT :  store the entity body at a specified url location (present in the request)
  5. DELETE : delete the file at a specified url location.

HTTP request headers:

  • Host : Domain-name that the browser is currently looking at
  • User-agent : Browser name and version; OS name and version
  • Accept-language : Default language setting for the user
  • Accept-encoding : Most browsers supports compression encoding techniques like gzip.
  • If-modified-since : Browser sends this header so that if the doc is not modified the server returns 304 (Not modified) and it gets the doc from the cache
  • Cookie : Sends cookies stored in your browser for that particular domain. Cookies are client-side whereas Sessions are server-side. I will detail it out in another post
  • Referrer : the url which referred this url (for e.g. if u come from google, referrer is google.com)

 HTTP Response Structure

The first line contains two things:

  1. Protocol and the version
  2. Status code

Status code

  • 200 – Successful request
  • 300 – Redirection
  • 400 – if there is problem with the request
  • 500 – if there is problem with the server

For complete list of status code, please refer to the wikipedia article

HTTP response headers

  • cache-control : specify directives which should be obeyed by all caching mechanisms.

    public means it can be cached by anyone but for 3600 seconds only.
  • Content-type : mime-type of the document
  • Content-disposition : Instructions for browser as to how to handle the content
  • Content-length : size of the document. Helps the browser figure out the progress of the download
  • Etag : Used for caching purposes. Whenever a doc is fetched, Etag header specifies a unique value. This value can be based on last modified, checksum or file size. Now whenever the browser want to refetch it, it can do so using etag and if etag is present then it will be shown 304 (content not modified)
  • Location : Used for redirections.
  • Set-cookie : When the website wants to set/update cookies for the browser.
  • WWW-authenticate : A website may send the user this header in-order to authenticate him over HTTP. When browser sees this, it opens a login window.
  • Content-encoding : To specify that the document is encoded

For more information

09 Jul

Python – Notes on Python Lists

This post serves as a placeholder for all important Python Lists related info I found online and discovered by playing around Python during the last 4 years of my life.

Python Lists are like array and this is how you create a Python List:

If this is how you create an array or One Dimensional array, how do we create a Two Dimensional list in python

So why should not we do the last thing? It is because of the same reason why we should not copy list by doing  List1  = List2

Looping over Lists:

Lists as stacks:

Lists as queue but it is not recommended as delete shifts the entire list. Use collections.deque instead:

Sorting list

From python 2.4 both list.sort() and sorted() added a key parameter to specify a function to be called on each list element prior to making comparisons

For further reading and helpful notes:

04 Jul

CSS – understanding box model

Any HTML element can be considered a box and therefore, box model applies to all HTML elements.

and the corresponding Box model for the above div:


Mnemonic to learn the box model – MBPE (Margin, Border, Padding, Element) -> My Baby Pee Everywhere!

Width, InnerWidth, OuterWidth

For further reading

02 Jul

Javascript – Hashtable and objects

Hashtable is sort of an associative array (with name-> value pairs). In JS, all objects are associative arrays. So, when you define

you are basically defining a hashtable of the name “dict”. But there are couple of things that you need to keep in mind.

  1. Length of associative arrays in not tracked unlike regular arrays. So when you do dict.length, the result will be undefined.
  2. keys can conflict with built in members (or of the object’s prototype). So whenever you are iterating a hashtable (or JS object), you need to filter out keys from the object prototype

For further reading as to how to implement Hashtable class in Javascript, refer to Mojavelinux article

30 Jun

Javascript – understanding this keyword

In Javascript, “this” keyword normally refers to the object on which the method is invoked. But there are times when figuring out “this” is not so easy.

However there are 4 rules using which you will be able to figure out the object that “this” refers to.

  1. By default, “this” refers to the global object.
  2. When a function is called as the property of a parent object, “this” refers to the parent object inside that function
  3. When a function is called with a “new” operator, then “this” refers to the newly created object inside that function
  4. When a function is called using call/apply, “this” refers to the first argument passed to call/apply. If the first argument is null or not an object, “this” refers to global object.

“this” pretty much sums it up!

For further reading:

09 Jan

Cornell Startup Fair

Got this in the Cornell mail

Dear Engineering Graduate Students, below is a message from Engineering Career Services:

We are very excited to announce Cornell University’s first ever Start-Up Career Fair!  In this inaugural year we are focusing on NYC, Boston and Upstate NY start-ups.  The recruiting focus is on all Engineering and Technical students.

When: Feb. 1 from 3-7pm

Where:  Duffield Atrium

Who: 40 Start-Ups from stealth mode to burgeoning on IPO

Just to name a few: Makerbot, Primet, Twitter, Tumblr, ZocDoc, MongoDB, Wayfair, FB, Moat

For more info: www.engineering.cornell.edu/startupfair

Not very sure whether students from other universities or working professionals interested in startups can attend the fair but you can shoot a mail to Ami Stuart (eng-recruiting@cornell.edu) to find it out.

20 Jul

What to read for your next interview

This guide is intended for students who want to enter CS/IT field. The topics that i have mentioned are the ones which i was grilled on during my placement season. I had given interviews in Yahoo, Agilent Technologies, Oracle, PitneyBowes and Flipkart.

My cousin sister is in 4th year of her Undergrad CS program. It is placement season at her college. She wanted some tips regarding placements. What to do? What not to do? Which topics should she study? Which topics she should avoid? Etc Etc Etc. During my placements, i did not have any mentor. Also, i did not realize the power of the internet. So, i decided to write all the things that came to my mind for her. I am sharing this post to all students who are/will be going through placement season in the near future.

A) Programming Languages
You should learn 2 programming languages
Java/C++ and C
Java/C++ because of their OO nature
C because that is the primary language that we all have used during our undergrad


  1. Java Book : Think like a Computer Scientist in Java (free pdf)
  2. C++ Book : Think like a Computer Scientist in C++ (free pdf)
  3. C Book : Kernighan and RitchieAmazon link
  4. CS-Library@Stanford.edu : Essential C
  • Optional but preferred : Do not use any fancy code-editors. Try to code everything in Notepad++ or GEdit (win). For Mac/Linux, use vim (nothing is better than this). I am asking you not to use Visual IDEs because at this stage we are better off without cheats/hints that are provided in IDEs.

B) Data Structures and Algorithms

  1. Algorithmic Complexity : You need to know Big-O. It is the first chapter of any Algo/DS book. A must
  2. Sorting : Details of O(n) of each sorting algorithm. Advantages/Disadvantages. Also, u need to know how they are implemented in C/Java/C++
  3. Queues, Stacks and Linked List : Basic Stuff. A must. Do all possible questions possible on these topics. Refer CS-Library@Stanford.edu for all possible questions on LinkedList.
  4. Trees : Again. A must. Do all possible questions possible on these topics. Refer CS-Library@Stanford.edu for all possible questions on Trees. Also, one should know about tree-traversal methods and operations, both recursively and non-recursively. Optional – Balanced trees and tries.
  5. Hashtables : Knowledge of Hashtables are required while solving real-life problems discussed during the interview. Candidate should know the working and implementation of Hashtables in any language he/she chooses.
  6. Graphs : Rarely companies ask to implement graph-problems. However, u need to know the functioning of graph algorithms, Djikstra, BFS, DFS. 
  7. Other problems : 8queen problem, Knapsack problem, Travelling-Salesman are some of the problems that are normally asked in the interviews


C) Operating Systems
You should know about Processes, Threads, Concurrency, Deadlocks and Memory Management. There are specific chapters allotted to these topics. Read and understand them from the dinosaur book (Galvin). You can also get Powerpoint ppts from the author’s site. I preferred reading from them.


  1. Operating System Concepts – Galvin (Amazon link) or, Ppt slides by Galvin.
  2. Modern Operating Systems – Tanenbaum (Amazon link)

D) Databases

Basic Database concepts, Normalization and joins. Candidate should also have good hands-on in MySQL. You should also know basic SQL queries and transactions. Implementation of triggers should also be known [My personal opinion as I was rejected in the final round of Yahoo because of triggers :) ]


  1. Sams’ Publishing MySQL tutorial (Amazon link) is my go-to book. Read till Chapter 8.
  2. Google University [ For the ones, who finished till Chapter 8 of the above book ]
  3. For Triggers : Refer Korth/Gehrke (Amazon link of Korth/Amazon link of Gehrke) whichever book is used in your college. I prefer Gehrke (not because he is my professor at Cornell, but it is a fabulous book)

E) Networking
I never gave Cisco’s interview so, I hardly have knowledge about networking questions. TCP/IP and Internet are two hot topics for all companies. Read about them in detail.


  1. Forouzan (Amazon link)/Tanenbaum (Amazon link): Whatever is used in your college
  2. or, Head First Networking (Amazon link) : Awesome book. It’s a Head-First. Need i say more :)

F) Puzzles
Almost every company (apart from Yahoo) asked me puzzles. Infact my entire flipkart’s first interview was based on puzzles. They were not programming puzzles, but were mathematical puzzles.
Book : Book of Puzzles by George Summers (Amazon link)

G) Optional

Intricacies of Unix. A must for people who want to become system engineers.

For this, delete Windows and install Ubuntu [ Do not dual-boot, it will not serve any purpose as you will not learn/admire Linux until it’s ur go-to OS ]
Start learning by following Ubuntu/Unix/Linux blogs. The more you will use it, the more you will know about it.

Book : Unix Concepts by Sumitabha Das (Amazon link)

One book i want all interviewers to check out is Cracking the coding interview by Gayle Laakmann (Amazon link). It is the best book i came across. MUST i should say. I bought the pdf version of this book on careercup.com. Buy it even if it’s a lil expensive for books in India. Great value for money.

Note: All the links in this post are affliate links. I got a Disqus post citing “Affliate links, Con-Alert”. I did not understand why I m labelled as a con just because I have affliate links in the post. Hell, I m not even using a url-shortener (Had I been using one, then maybe u can label me as a con). Anyways, they are all affliate links. Kill me for that :P