Skip to content

Instantly share code, notes, and snippets.

@screamingmunch
Last active December 18, 2015 23:19
Show Gist options
  • Save screamingmunch/5860666 to your computer and use it in GitHub Desktop.
Save screamingmunch/5860666 to your computer and use it in GitHub Desktop.
Networks, Sinatra

Networks:

"The Cloud" - marketing wise, it implies anything that has to do with the internet these days.

but when we're talking about networks, it means the connection of computers from point A to some other computer B.

Firewall- a computer that by default accepts no connections, and accepts a few exceptions

port 80 = HTTP, port 443 = HTTPS (S=secure)

port: similar to a phone extension number - assigned to applications

when debugging, the most common ports to use are :3000 and :8080.

IP address- IP (Internet Protocol) dials you into a (specific) computer. IP address will go to a specific computer.

TCP/IP = Transmission Control Protocol/ Internet Protocaol (computer communication protocols, description of the rules computers must follow to communicate with each other).

TCP vs UDP(User Datagram Protocol). TCP- transmission-oriented, once a connection is established, data can be sent bidirectional. UDP is simpler, connectionless internet protocol. Multiple messages are sent as packets in chunks using UDP.

AP= access point, just a wire in the air.. doesn't do anything with networking but pretend that there is a wire where there isn't one

router-

NAT - network address translation - the only thing that has access to the internet with an IP address. there are only about 4 billion IP addresses available as of right now.

a router when it's set up, it was given a location with an address to access to (an IP address), which is usually assigned to the router when you're connected by your internet provider(comcast or Cox).

comcast assigns an ip address to the router

gives the users connected to that router an intranet address ip.foobar3000.com

DNS (domain name system/ resolution) - basically a global phone book for computers, a tiered system top tier- a computer called .com (about a dozen computers) translates an internet address to IP address comcast has a mirror/copy of the name of the all the .com in the world (updates every 24 hours) - copies all the addresses.

Utility: ICMP- pingpong service and lets us know how many pings it takes to get a pong ping-

in terminal: ping -c 1 www.google.com or ping -c www.yahoo.com will give you IP addresses.

dig- the swiss army knife of DNS

ifconfig (ipconfig on windows) -interface configure. interface: ethernet, bluetooth, wifi, serial *MacAirs has no Ethernet port

when you type ifconfig you'll get a list of available interfaces: the ones we're concerned with are the ones starting with:

eth - ethernet (linux) en - ethernet (mac) wLAN - wireless LAN (local area network) = wifi - not used much anymore on mac and linux lo -

eth0 is usually the wired ethernet port eth1 is usually the wifi ones

Types of IP Addresses x.y.z.a format 10.x.y.z (reserved)- intranet address, NAT address, private address 192.168.x.x (reserved)- intranet address

169.x.y.z - usually a problem with the router

127.0.0.1 - reserved for lo (local) or Home, or local host, or self.(every computer has it).

DNS - for the internet mDNS- for a local network (how airdrop works, how peer-to-peer file sharing) hostname in terminal

Babbage

to change the name of your computer (in mac): System Preferences -> sharing --> Computer Name (for linux): sudo hostname -n newname

windows doesn't automatically have mDNS, but if you have itunes installed, it would have mDNS

netcat - swiss army knife of networks (linux) config1: netcat name/ip port client- calling the other computer config2: netcat -l port netcat -l boss.local (listener or server that accepts connections)

(mac) config1: nc name/ip port config2: nc -l port nc -l 3000

web browser is a client.

Additional topics on networking: Asus RT-N16, Tomato USB, DD-WRT, Port Forwarding.

Sinatra

a miniframework `gem install sinatra sinatra-contrib` `gem list sinatra` to confirm it has been installed

http:// www.google.com/ search/ ?9= WDI protocal domain route or path search or query strings/parameters

require 'sinatra'
require 'sinatra/reloader'  #allows you to reload the page while it's running

get '/hi' do
  "Hello World" 
end

get '/name/:first' do 
  "Hello #{params[:first]}"
end

http://localhost:4567/hi will show Hello World http://localhost:4567/name/Kris will show Hello Kris http://localhost:4567/name/Anil will show Hello Anil

Sinatra and Rails both use pre-defined locations for certain files.. If you don't follow that, the program will likely not be able to find the files.

find . in command line will return all the files in that folder

recap on problems:

```bash 1. be discrete- focus on one problem at a time 2. What problem am I solving? -make sure it is a single thing 3. What do I expect? How do I know it worked? test! 4. Where am I (in terms of files and folders)? pwd 5. Which files are there? Which function/class are there? ls, use the tab key 6. Which file am I running? Which function am I calling? Which class am I instanciating? ```

Sinatra part II- IMDB clone

omdbapi IMDB API that gives you back movie data in json

super mario RPG emulator. chiptune.rainwave.cc

Homework Review - Landlord app

Programmers do not use global variables, only scripties & ignorant folks use global variables. Everything in PHP automatically becomes global variables

Week 2 - Day 1 homework

  • implement rental management app that we designed this morning - see [Class Diagram] (http://i.imgur.com/4qlsnSi.jpg)
  • Create class files buidling.rb, unit.rb and tenant.rb and implement them.
  • The code below is the main program. Save it to a file main.rb in the same folder as class files.
  • Implement menu choices below (1 to 6) as far as you get today.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment