Skip to content

Instantly share code, notes, and snippets.

@amysimmons
Last active December 26, 2017 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amysimmons/9ec8832a9e1f7574096c to your computer and use it in GitHub Desktop.
Save amysimmons/9ec8832a9e1f7574096c to your computer and use it in GitHub Desktop.
WDI Week 2 Notes

#WDI Week 2 Notes

##Monday

###Warm-up

Robot name:

https://gist.github.com/wofockham/8d343ee24988f751601e

class Robot
 
 	#i want the ability to read the instruction count
	attr_reader :instruction_count

	#initialize only gets called when you call .new 
	#thats the only time initialize runs
	#this is why the new robot has the same name each time you puts robot1.name
	def initialize
		@instruction_count = 0

		@creation_time = @boot_time = Time.now

		@name = letters + numbers
		@mac = (0...4).map { rand(1000..9999).to_s}.join(':')
	end	

	def name
		@instruction_count += 1
		@name
	end

	def reset
		@instruction_count += 1
		@name = letters + numbers
		@boot_time = Time.now
	end

	def timers
		"#{(Time.now - @boot_time).round} seconds since last boot " +
		"#{(Time.now - @creation_time).round} seconds since creation"
	end

	private
	def letters
		('A'..'Z').to_a.sample(2).join
	end

	def numbers
		rand(800...1000).to_s
	end

end

require 'pry'
binding.pry

puts "Robot 1: "
robot1 = Robot.new
puts robot1.name
puts robot1.name
puts robot1.name

puts "Robot 2: "
robot2 = Robot.new
puts robot2.name
puts robot2.name
puts robot2.name

puts "Robot 3: "
robot3 = Robot.new
puts robot3.name
puts robot3.name
puts "Resetting to factory settings."
robot3.reset
puts robot3.name
puts robot3.name

###The web

Local host just means the machine that this code is currently running on.

###Sinatra

http://www.sinatrarb.com/

http://localhost:4567/calc?first=6&operator=%2B&second=6

http:// - protocol

localhost - domain

4567 - port

calc - path

first=6&operator=%2B&second=6 - query string

###APIs

###LAB: Stock Lookup

###Homework: Pair Programming Bot

My attempt: https://github.com/amysimmons/wdi8_homework/tree/master/amy/pair_programming_bot

##Tuesday

##Wednesday

###HTML5 Forms

<form action="/process">

    <p>
        <label for="query">Thing to search for:</label>
        <input type="search" name="query" id="query" placeholder="Search">
    </p>

    <p>
        <label for="age">Name:</label>
        <input name="name" id="name" placeholder="Abraham" autofocus>
    </p>

   <p>
        <label for="age">Age:</label>
        <input type="number" id="age" name="age" placeholder="99">
   </p>

   <p>
       <label for="booking_date">Booking date:</label>
       <input type="date" name="booking_date" id="booking_date">
   </p>

   <p>
       <label for="myspace_page">Myspace page:</label>
       <input type="url" name="myspace_page" id="myspace_page" required>
   </p>
  
    <p>
        <label for="address">Address</label>
        <input type="email" id="address" name="address">
    </p>

    <p>
        <label for="avatar">Avatar</label>
        <input type="file" name="avatar" id="avatar">
    </p>

    <p>
        <label for="letter_home">Letter to home:</label>
        <textarea name="letter_home" id="letter_home" placeholder="Dead mum and dad"></textarea>
    </p>
    
    <p>
        <label for="bros">Favourite Marx Brother:</label>
        <select name="bros" id="bros">
            <option value="groucho">Groucho Marx</option>
            <option value="harpo" selected>Harpo Marx</option>
            <option value="chico">Chico Marx</option>
            <option value="zeppo" disabled>Zeppo Marx</option>
        </select>
    </p>

    <p>
        Select your vices:
        <label for="wine">Wine</label>
        <input id="wine" name="vices[]" type="checkbox" value="wine">

        <label for="cigars">Cigars</label>
        <input id="cigars" name="vices[]" type="checkbox" value="cigars">

        <label for="heroin">Heroin</label>
        <input id="heroin" name="vices[]" type="checkbox" value="heroin">
    </p>

    <!-- the square brackets after the name allows you to select multiple choices and it will store them in an array -->

     <p>
        Select your favourite vice:
        <label for="wine">Wine</label>
        <input id="wine" name="fave_vice" type="radio" value="wine">

        <label for="cigars">Cigars</label>
        <input id="cigars" name="fave_vice" type="radio" value="cigars">

        <label for="heroin">Heroin</label>
        <input id="heroin" name="fave_vice" type="radio" value="heroin">
    </p>

    <button>Submit</button>

</form>

Lab: Movie posters

https://github.com/amysimmons/wdi8_homework/tree/master/amy/movie_poster

###Homework: SydJS

##Thursday

###Lab: Movie posters v.2

https://github.com/amysimmons/wdi8_homework/tree/master/amy/movie_poster2

###Homework: Games

The task:

https://gist.github.com/wofockham/56f8d794c405a8d7cae6

My attempt:

https://github.com/amysimmons/wdi8_homework/tree/master/amy/Games

##Friday

####The difference between GET and POST in forms

<form action="/" method="post">

    <label for="client">Client: </label>
    <input type="text" id="client" name="client">

    <label for="service">Service: </label>
    <input type="text" id="service" name="service">

    <label for="cost">Cost</label>
    <input type="number" id="cost" name="cost">

    <input type="submit" value="Create recepit">

</form>

method get is what's implicitly in the form, it puts the info in the url

get request: is just saying give me som einformation

eg get me the movie poster for Jaws a thousand times

method post means send the data to the server, but when you post it you won't see it in the url, it sends it to the server behind the scenes in another way

post request: is something you want to receive only once

eg when you are creating something on the server, not fetching something, actually pushing something into the server

the basic difference between get and post is whether it is changing something on the server or not

####Including a view within another view in Sinatra

<%= erb :form, :layout => false %>

this is saying go and get my form but don't bother including the layout

this only matters if you're including a view within another view

if you do want to do that just say layout false

####Keeping the user's data out of the URL

with get method, the user's data is stored in the url

but every time the user hits refresh, it will reenter that data in the csv File

it's also not secure to have passwords and credit card details in the url

POST will make it so the information never appears in the url

####What if my CSS isn't showing on one page in Sinatra?

href="/css/receipts.css">

putting a fwd slash at the start of your css href will say ignore where you think I am, go back to the very start of the site and find it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment