Skip to content

Instantly share code, notes, and snippets.

@adeng21
adeng21 / gist:11194889
Created April 22, 2014 21:24
Seed file
category_attributes = [{name: 'Wrecks/Artifacts', image: Rails.root.join('/assets/images/categories/Wrecks.jpg')},
{name: 'Caves', image: Rails.root.join('/app/assets/images/categories/Caves.jpg')},
{name: 'Drift', image: Rails.root.join('/app/assets/images/categories/Drift.jpg')},
{name: 'Walls', image: Rails.root.join('/app/assets/images/categories/Walls.jpg')},
{name: 'Whales & Sharks', image: Rails.root.join('/app/assets/images/categories/Sharks.jpg')},
{name: 'Macro/Corals', image: Rails.root.join('/app/assets/images/categories/Corals.jpg')},
{name: 'Manta Rays', image:Rails.root.join('/app/assets/images/categories/Manta.jpg')},
{name: 'Night', image: Rails.root.join('/app/assets/images/categories/Night.jpg')},
{name: 'Turtles', image: Rails.root.join('/app/assets/images/categories/Turtles.jpg')},
{name: 'Schools of Fish', image: Rails.root.join('/app/assets/images/categories/Fish.jpg')}]
@adeng21
adeng21 / recursion
Created April 22, 2014 13:10
Factorial Recursion
def recursion(number)
if number == 1
number
else
number * recursion(number - 1)
end
end
@adeng21
adeng21 / Bank Accounts
Created March 8, 2014 20:15
Bank Balance Challenge
class BankAccount
attr_reader :account_type, :starting_balance, :transactions_array
def initialize(account_type, starting_balance, transactions_array = [])
@account_type = account_type
@starting_balance = starting_balance
@transactions_array = transactions_array
end
@adeng21
adeng21 / Classes and TDD - Lib file
Created March 8, 2014 18:06
Week 3 Systems Check
class Square
attr_reader :side
def initialize(side)
@side = side
end
def area
side * side
@adeng21
adeng21 / Erase Method
Created March 3, 2014 19:33
Whiteboard & DryEraseMarker Instance Method Examples
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase(contents)
@contents.delete(contents.length)
end
@adeng21
adeng21 / Card Getter
Created March 3, 2014 17:44
Card Getter Example
class Card
def initialize(rank, suit)
@suit = suit
@rank = rank
end
def rank
@rank
end
@adeng21
adeng21 / Car Getter
Created March 3, 2014 17:43
Getter Method Example
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color
@color
end
@adeng21
adeng21 / TV constructors
Created March 3, 2014 16:48
Class Constructors
class Television
def initialize(brand, model)
@brand = brand
@model = model
end
end
class TelevisionChannel
def initialize(name, channel_number)
@name = name
@adeng21
adeng21 / Random Card Constructor
Created March 3, 2014 16:44
Card Constructor Example
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
@rank = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'].sample
else
scores = [75, 100, 85, 65, 84, 87, 95]
def average(array)
total = 0
array.each {|i| total += i}
total/array.length
end