Web Development Course: HTTP

Been awhile!! Work has been crazy as we’re trying to launch a product by an unrealistic deadline that continues to get pushed back by 2 wks so been super busy. I took a little break from learning React and Data Structures and started watching this CS lecture video series by Harvard on web development. It covers topics like HTTP, PHP, SQL, JS, Ajax, Security, etc. Not sure if I’ll get to finish it anytime soon but I watched a bit of the first lecture on HTTP. The video is 2 hours and 40 minutes long and my ADD kicks in every so often to sit through the whole thing so figured I’d break it up in little chunks.
I used to think to myself that I have to have good/solid content that’s worth posting but what the heck, half the battle is being consistent and I’ll post SOMETHING since the point is to make it a habit to motivate myself.

Here is my summary from last night:

From a user’s perspective
What happens when a user types in a URL in the web browser such as google.com? The address gets “translated” into an unique IP address in the format of w.x.y.z consisting of numbers from 0~255. The address you type in has something like http in front of it (if omitted, the browser’s been made user friendly to type it in for you), a protocol by which a message/request is viewed by the browser. A “virtual envelope” is created with your request (such as an image you’re trying to view), your computer’s IP address as the sender and the web site’s IP address to which you’re sending your request.

How does your computer know where to send these requests to? How are IP addresses mapped to specific servers? Your ISP, internet service provider such as Comcast, has DNS, Domain Name System, that looks up its hierarchical chain to see where the IP resides. Hierarchical meaning that if it doesn’t know exactly where something should go, it knows someone else who knows someone else that knows, etc.  — it can go through up to 30 different routers all over the world. Then once say, the Google server receives your request, it looks for a particular path such as “/ (root path)” indicated in your address, retrieves the requested data, puts it in a virtual envelope, flips the IP addresses, and sends it your way. You then can view Google.com’s search page.

From a website owner’s perspective

You create a website and want show it off to the world. How do you accomplish this? Like above, your site gets visited by users on its IP address. Can you use the IP address of your laptop at home aka as a server to host your site? Technically yes, but probably no. The IP addresses you have on your computer is first of all private and probably not unique. Even if you can find a way around this, once you get a lot of traffic to your router, your ISP will most likely shut you down entirely.

That is why we use hosting services like GoDaddy and my personal favorite, Namecheap. You also need to purchase a domain name like grace.com which has to be known to DNS of your server host (can be the same place you purchase your domain name) which will do the rest of the work of routing things for you.

So how does these requests and messages physically or electronically travel to one computer to another? Simply put, we use what’s called TCP/IP for data transmission, a language spoken by the computers. The IP is the part from which IP addresses are derived; it assigns numbers, addresses, to computers. More on this later, I’m sure.

The server can receive many types of requests such as email, not just a request to view a certain web page. Email can live on the same server as other services, therefore, specific “port numbers” are needed to direct these requests appropriately (e.g. 80 for websites and 25 for email).

That is it for tonight! My apologies if I misunderstood some of the concepts but overall it’s meant to be for basic intro. Will be studying more when time permits.



Linked Lists

A friend of mine gifted me the book, Cracking the Coding Interview by Gayle Laakmann, awhile back for my birthday. It’s probably one of the most famous books for studying for interviews. However, if you don’t have CS background like me, the problems can be a bit challenging as the book is not meant to be for studying the fundamentals (well.. granted it’s meant to be challenging for anyone studying). So I turned to Udemy and started on Learning Data Structures by Eric Traub. I really like the way he explains things and his pace so far. It covers a few important data structures, linked lists, binary search trees, and hash tables. Here is a summary of this morning’s learning on the first topic, linked lists. Detailed code summary can be found here: https://repl.it/IZ09/16

A linked list is a data structure that contains data elements, “nodes,” in a linear fashion. These nodes (objects) can be singly linked or doubly linked. Singly linked nodes have reference to the nodes next to them (can only go one way) and doubly linked nodes have access to nodes next to them as well as previous nodes (can go both ways). Linked lists also have two “pointers,” one that points at the very first node in the list, namely the “head node” and the other pointing at the last node, the “tail node.” We only have direct access to these pointers and data can only be added/removed from these nodes. This means that any nodes that reside somewhere in between the pointers have to be searched through, one by one, starting from either the head or the tail (no random access or adding a node next to, say the third node without going from the head or tail ). Our goal is then to create two constructor functions that 1) creates a linked list and 2) creates a new node. We also need a few methods to be added to the prototype of the linked list constructor function that do the following: add/remove from the head/tail & search the list for the value of interest.

1) LinkedList Constructor Function

Write a constructor function for creating a new linked list. Set “this.head” & “this.tail” to null since we are starting with an empty list with no nodes in them.

2) Node Constructor Function

Write a constructor function for creating a new node. This takes in three parameters, value, next (reference to next node), and prev (reference to previous node).

3) addToHead method

This method is added to the prototype of the linked list constructor function and takes in a value parameter. It creates a new instance of the Node constructor that takes in the value passed in as its “value”, the current head of the list (if any), this.head, as the “next” node, and null as the “prev” node (since the new node is the new head, no node comes before it).
If current “this.head” exists, meaning that the list is not empty, set its prev node to the new node, making it the new head.
Else, if the list is empty, set the new node as this.tail since it will be the first and only node in the list.
Finally, set the new node as the new “this.head” regardless the list is empty or not (purpose of this method).

Additionally, removeFromHead, addToTail/removefromTail (same as head methods but in reverse), and search method can be written. The search function takes in the value to be searched as its parameter and a loop is used to search for the matching value in the list (start from head or tail, your choice, and conditional loop). To start, save the head or tail node in a variable, say “currentNode,” and update it to the next/prev node as you move along the list.

The course gives a challenge problem at the end to find the index/position of the search value.

Hackerrank has good practice problems under Data Structures > Linked Lists. Linked lists seem pretty straightforward and simple to use. When are linked lists useful in real life over the other data structures? I’m assuming it has to do with memory and space, Big O, covered next in the course.

Happy learning!