Skip to content

Instantly share code, notes, and snippets.

View ashleygwilliams's full-sized avatar
>o_o<

ashley williams ashleygwilliams

>o_o<
View GitHub Profile
@ashleygwilliams
ashleygwilliams / flow.rb
Last active December 18, 2015 11:29
control flow wat -> control flow WUT
def step1(x)
if x==1
puts "it was all a dream"
end
return 2
end
def step2(x)
if x==2
@ashleygwilliams
ashleygwilliams / gist:5778813
Created June 14, 2013 01:37
HOMEWORK: ALEX + JULIAN 13 JUNE 2013
JULIAN:
finish scraper for two types of site
read http://www.w3schools.com/sql/ << teach you how to build sql tables
port the scraper lib from the sinatra app to the rails app
pay attention to what your models are!!
tables = > columns :: models => attributes
what data am i scraping || what attributes does my model have || what columns should my table have
SCRAPER || RAILS || SQL
@ashleygwilliams
ashleygwilliams / enumerable.rb
Created June 19, 2013 00:02
practice using nested data structures with each
# create a new hash that has this structure
# {
# "A" => "a"
# "B" => "b"
# ...
# "Z" => "z"
#}
#using a single each loop
#know that you can do (A..Z) and (a..z)
@ashleygwilliams
ashleygwilliams / nutrition.rb
Last active December 18, 2015 16:19
homework for alex
#fill out this meal array with items and details hashes. make sure you have at least 5 items
ITEMS = [ "ITEM" => {:calories=> ??, :fat => ??, :carbs => ??, :protein=>},
"ITEM" => {:calories=> ??, :fat => ??, :carbs => ??, :protein=>}
]
#here is a method that randomly makes you eat x portions of the food
def generatePortions
portions = []
rand(20).times do
@ashleygwilliams
ashleygwilliams / hellorack.rb
Last active December 18, 2015 17:19
a simple exercise to explore the code required to run a simple local helloworld rack app
require 'rack'
class MyApp #change this name
def call(env)
#some code goes here!
end
end
Rack::Handler::WEBrick.run(MyApp.new, {:Port => 3000}) #you'll need to update this...
@ashleygwilliams
ashleygwilliams / middleware.md
Last active December 18, 2015 18:29
rack lab

Rack runs an instance of a class that implements the #call method, but it can also use several other "stand-alone" Rack apps before returning the response to your web-browser by passing the status, headers, and body to each new app, we can stack middleware between the server and the browser to manipulate the details of the request/response cycle. Think of it like a stack.

  1. Create a directory called rack_middleware

  2. cd into that directory and create the file app.rb

  3. We're going to define our base Rack app in app.rb. We just need a class that implements a call method. Add a MyApp class that says hello, but doesn't set any headers. We'll add those later.

# app.rb
@ashleygwilliams
ashleygwilliams / sinatra.md
Last active December 18, 2015 21:49
sinatra part 0

Student Sinata App: Part Zero

Objective

Get comfortable writing routes and creating ERB views in a very simple Sinatra App.

Tutorial

Part 1: Bootstrap the app

@ashleygwilliams
ashleygwilliams / sinatra_objectives.md
Created June 24, 2013 15:53
sinatra learning objectives

Sinatra

Learning Objectives

Level 0

  • scaffold a basic sinatra app
    • app.rb
    • config.ru
    • Gemfile
  • gemfiles, what are they
  • rubygems.org
@ashleygwilliams
ashleygwilliams / sinatra_1.md
Last active December 18, 2015 22:08
part 1

Sinatra: Part 1

Objective

Re-create the student website as a dynamic web application using Sinatra and the Student Class you created in the Student Class DB lab.

Student ORM files Note1: If you use this ORM, it has a dependency on the Persistable module, you must grab and require this file. Note2: You MUST USE THE GEMFILE. All gems go in the gemfile, and no longer do we do "require 'sqlite3'" in our actual program. Files you wrote (like student.rb) are required as normal. Part 1: Rendering a list of students.

@ashleygwilliams
ashleygwilliams / sinatra_2.md
Last active December 18, 2015 22:09
part 2

#Sinatra: Part 2

Objectives

Continue re-creating the student website as a dynamic web application using Sinatra and the Student Class you created in the Student Class DB lab.

  • Add the static assets (stylesheets, javascripts, and images) from the student static website.

  • Style the students index page

Add your static assets