Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
ivanbrennan / config.ru
Created October 21, 2013 13:52
hello rack
#run lambda { |env| [200, {'Content-Type'=>'text/plain'}, ["Hello World"]] }
class ThisApp
def call(env)
p env
response = env["REQUEST_PATH"] == "/" ? "Hello Rack!" : "Hi again Rack!"
[200, {"content-type" => "text/html"}, [response]]
end
end
@ivanbrennan
ivanbrennan / serialize.rb
Created October 15, 2013 14:08
Serialize
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :progress # :progress, :html, :textmate
end
@ivanbrennan
ivanbrennan / roman-numerals.rb
Created October 12, 2013 23:11
Roman Numerals
# # Roman Numerals
# The Romans were a clever bunch. They conquered most of Europe and ruled it for hundreds of years. They invented concrete and straight roads and even bikinis. One thing they never discovered though was the number zero. This made writing and dating extensive histories of their exploits slightly more challenging, but the system of numbers they came up with is still in use today. For example the BBC uses Roman numerals to date their programmes.
# The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice these letters have lots of straight lines and are hence easy to hack into stone tablets).
# Write a function to convert from normal numbers to Roman Numerals: e.g.
# ```
# 1 => I
@ivanbrennan
ivanbrennan / binary.handshakes.rb
Created October 12, 2013 17:31
Binary handshakes
# # Binary Secret Handshake
# > There are 10 types of people in the world: Those who understand binary, and those who don't.
# You and your fellow flatirons are of those in the "know" when it comes to binary decide to come up with a secret "handshake".
# ```
# 1 = wink
# 10 = double blink
# 100 = close your eyes
@ivanbrennan
ivanbrennan / vowels.rb
Created October 11, 2013 15:31
vowels
# Download this file:
# https://gist.github.com/aviflombaum/28534c5d69edd2439a7d/download
# Run it from your terminal with:
# ruby ruby.basics.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
@ivanbrennan
ivanbrennan / .irbrc
Created October 11, 2013 15:19
irbrc
require 'rubygems'
require 'yaml'
require 'irb/completion'
require 'awesome_print'
alias q exit
class Object
def local_methods
(methods - Object.instance_methods).sort
@ivanbrennan
ivanbrennan / person.rb
Created October 10, 2013 14:04
person.rb
class Person
def initialize(attr_hash)
attr_hash.each do |property, value|
Person.send(:define_method, property) do
@property = value
end
end
end
end
@ivanbrennan
ivanbrennan / triangle.rb
Last active December 25, 2015 02:19
triangle.rb
class TriangleError < Exception
end
class Triangle
attr_reader :sides
def initialize(side1, side2, side3)
@sides = [side1, side2, side3].sort
self.validate
end
@ivanbrennan
ivanbrennan / school.domain.rb
Last active December 25, 2015 01:19
School.domain.rb
class School
attr_reader :roster
def initialize(school_name)
@roster = {}
@name = school_name
end
def add_student(stu_name, grade)
(self.roster[grade] && (self.roster[grade] << stu_name)) ||
@ivanbrennan
ivanbrennan / juke-scraps.rb
Created October 8, 2013 15:09
juke-scraps
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The Phoenix - Consolation Prizes"
]