Skip to content

Instantly share code, notes, and snippets.

View blake41's full-sized avatar

Blake Johnson blake41

  • http://blakejohnson.brandyourself.com/
View GitHub Profile
@blake41
blake41 / forms
Last active September 10, 2015 13:31
forms are HTML and follow HTTP conventions
forms are the combination of a get and a post
in sinatra we mainly build forms manually (in HTML)
in rails we mainly use "form helpers" to dynamically create forms
it's only the HTML you write that matters
the most important things about a form are the name attributes of the inputs and the action of the form.
the action of the form tells you where the form will post.
How does Sinatra/Rails parse query parameters (hint: it's really Rack doing it)?
http://spin.atomicobject.com/2012/07/11/get-and-post-parameter-parsing-in-rails-2/
require 'pry'
require 'pry-nav'
class Person
def initialize(att)
self.class.class_eval do
att.each do |method, value|
define_method(method) do
instance_variable_get("@#{method}")
end
# All bicycles are road bikes
# A Mechanic is going to need to know what spare parts to take
# for a bike on a trip in case it breaks down
# tape color is the only dynamic component of spares
############## Page 107 ##############
class Bicycle
attr_reader :size, :tape_color
def initialize(args)
@size = args[:size]
@blake41
blake41 / tickets
Last active August 29, 2015 14:27
a person should be able to purchase a ticket to a show
they should be able to attend multiple shows
we should keep track of how many unused tickets a person has
we should keep track of how many used tickets a person has
we should be able to use a ticket (go to a show)
Alexander Burton
Andrew Persad
Brian Mesa
Bruna Netto
Carson Crane
Christopher Dabalsa
Damian Lajara
Djavan Joseph
Dylan O'Keefe
Esther Mohadeb
require 'pry'
def second_supply_for_fourth_of_july(holiday_hash)
# given that holiday_hash looks like this:
# {
# :winter => {
# :christmas => ["Lights", "Wreath"],
# :new_years => ["Party Hats"]
# },
# :summer => {
def reformat_languages(languages)
result = {}
languages.each_pair do |style, values|
# style like :oo
# values like {
# :javascript => {
# :type => "interpreted"
# }
values.each_pair do |language, attributes|
# language is like :javascript
def reformat_languages(languages)
result = {}
languages.each_pair do |style, values|
# style like :oo
# values like {
# :javascript => {
# :type => "interpreted"
# }
values.each_pair do |language, attributes|
# language is like :javascript
require 'pry'
require 'pry-nav'
require 'ap'
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms. K"],
:white => ["Queenie", "Andrew", "Ms. K", "Alex"],
:brown => ["Queenie", "Alex"]
# Count words in a sentence
require 'pry-nav'
require "pry"
require 'ap'
paragraph = <<-something
Steven likes the movies. Blake likes to ride his bike but hates movies.
Blake is taller than steven. Steven is a great teacher.
something