Skip to content

Instantly share code, notes, and snippets.

View rosiehoyem's full-sized avatar

Rosie Hoyem rosiehoyem

View GitHub Profile
@rosiehoyem
rosiehoyem / insert.sql
Created October 13, 2013 17:53
SQL Build Kickstarter, Day 9
INSERT INTO users(id, name, age)
VALUES
(1, "Casey", 24),
(2, "Angie", 20),
(3, "Samantha", 17),
(4, "Greg", 40),
(5, "Andrew", 43),
(6, "John", 64),
(7, "Camille", 20),
(8, "Cynthia", 50),
@rosiehoyem
rosiehoyem / prime.rb
Created October 13, 2013 18:01
Prime number example from day 7
number = 10007
# def prime?(number)
# tries = 0
# while i < number
# prime = false if number % high == 0
# tries += 1
# end
# end
@rosiehoyem
rosiehoyem / version_sort.rb
Created October 13, 2013 18:37
Version sort TODO, Day 7
class Array
def version_sort
array = []
array << filenames.split(.)
array.each |x|
x.drop("foo")
end
array.each |pieces|
end
@rosiehoyem
rosiehoyem / tower_of_hanoi.rb
Last active December 25, 2015 10:59
Tower of Hanoi, Day 7
#Tower of Hanoi
# Recursive solution:
# http://www.sparknotes.com/cs/recursion/examples/section6.rhtml
def toh(n, source = 'A', temp = 'B', dest = 'C')
toh(n - 1, source, dest, temp) if n > 1 # move all n - 1 disks to temp pole
puts "Move top disc #{n}: #{source} => #{dest}." # move bottom disk to destination pole
toh(n - 1, temp, source, dest) if n > 1 # move all n - 1 disks to destination pole
end
@rosiehoyem
rosiehoyem / person_class.rb
Created October 13, 2013 19:04
Mass-assignment of attributes at initialization, day 14.
attributes = {
:name => "Avi",
:birthday => "01/29/1984",
:hair_color => "brown",
:eye_color => "brown",
:height => "tall",
:weight => "good",
:handed => "lefty",
:complexion => "decent",
:t_shirt_size => "medium",
@rosiehoyem
rosiehoyem / ruby.basics.rb
Created October 13, 2013 20:56
Ruby basics TODO, day 3
# 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
# ======================================
@rosiehoyem
rosiehoyem / pigeon_organizer.rb
Created October 14, 2013 15:28
Pigeon Organizer
########################
# NYC PIGEON ORGANIZER #
########################
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
:white => ["Queenie", "Andrew", "Ms .K", "Alex"],
:brown => ["Queenie", "Alex"]
@rosiehoyem
rosiehoyem / normalize_phone_numbers.rb
Created October 14, 2013 15:30
Normalize phone numbers TODO, day 5
def normalize_phone_number(phone)
if phone[/a-zA-Z/] == nil
phone.each_char do |x|
if !(x.match(/[\d]/))
phone.delete! x
end
end
phone.insert(0, "(")
phone.insert(4, ") ")
phone.insert(9, "-")
@rosiehoyem
rosiehoyem / serialize.rb
Created October 15, 2013 16:36
Serialize To Do
class Song
attr_accessor :title, :artist
def initialize
@artist = artist
end
def serialize
filename = self.title.downcase.gsub(' ','_')
text_to_write = "#{self.artist.name} - #{self.title}"
File.open("#{filename}.txt", 'w') { |file| file.write(text_to_write) }
@rosiehoyem
rosiehoyem / recycling.rb
Last active December 25, 2015 18:09
Refactoring Case Statements and Recycling
class Recycle
def initialize
@plastic_bin = []
@glass_bin = []
@paper_bin = []
@metal_bin = []
@landfill_bin = []
@plastic_types = ["num_1", "num_2", "num_3", "num_4", "num_5", "num_6", "num_7"]
@glass_types = ["clear", "color"]
@paper_types = ["paper", "cardboard"]