- You enter a URL into a web browser
- The browser looks up the IP address for the domain name via DNS
- The browser sends a HTTP request to the server
- The server sends back a HTTP response
- The browser begins rendering the HTML
- The browser sends requests for additional objects embedded in HTML (images, css, JavaScript) and repeats steps 3-5.
- Once the page is loaded, the browser sends further async requests as needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd a, b | |
return a if b == 0 | |
return gcd(b, a % b) | |
end | |
def gcd_in_list list | |
list = list.sort | |
grt = 0 | |
list.each do |i| | |
grt = gcd(i, grt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sudoku is a puzzle where you're given a partially-filled 9 by 9 grid with digits. The objective is to fill the grid with the constraint that every row, column, and box (3 by 3 subgrid) must contain all of the digits from 1 to 9. | |
# A Backtracking program in Pyhton to solve Sudoku problem | |
def line(): | |
return '*' * 13 | |
# A Utility Function to print the Grid | |
def print_grid(arr): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Queue | |
def initialize | |
@s1,@s2 = [],[] | |
end | |
def enqueue e | |
while not @s1.empty? | |
@s2 << @s1.last() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def max_sum(array) | |
max_so_far = 0 | |
max_ending_here = 0 | |
array.each do |i| | |
max_ending_here += i | |
max_so_far = max_ending_here if max_so_far < max_ending_here | |
max_ending_here = 0 if max_ending_here < 0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maximum_profit stock | |
max = 0 | |
stock.each_with_index do |buy, i| | |
(i+1...stock.size).each do |sell| | |
profit = stock[sell] - buy | |
max = profit if profit > max | |
end | |
end | |
return max | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def deck | |
ranks = ['A',*(2..10),'J','Q','K'] | |
suits = ['♠','♦','♣','♥'] | |
deck = [] | |
suits.product(ranks).map { |rank, suit| deck << "#{rank}#{suit}" } | |
deck | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Node | |
attr_accessor :val, :left, :right | |
def initialize val, left=nil, right=nil | |
@val = val | |
@left = left | |
@right = right | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
class Node: | |
def __init__(self, data): | |
self.data = data | |
self.left = None | |
self.right = None | |
def __str__(self, level=0): | |
ret = "\t"*level+repr(self.data)+"\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def all_palindromes(word) | |
q = "@#" | |
q += word.chars.join("#") | |
q += "\#$" | |
puts q | |
pld = [0] * q.size() | |
c,r = 0,0 | |
search = (1...q.size()) | |
search.each do |i| | |
mirror = c - (i - c) |