Skip to content

Instantly share code, notes, and snippets.

source 'https://rubygems.org'
# Frameworks
gem 'rails', '4.0.2'
# Server
gem 'unicorn'
# Database
gem 'pg'
@irmiller22
irmiller22 / greed_score_method
Created December 6, 2013 19:16
Greed Score Logic
# GREED GAME
def score(dice)
return 0 if dice == nil
score = 0
counts = [0,0,0,0,0,0]
dice.each { |roll| counts[roll-1] += 1 if (1..6) === roll }
@irmiller22
irmiller22 / gist:7418546
Created November 11, 2013 19:06
Database Checklist
does it change the database?
where am I going to store that data?
what data needs to be stored?
name
the songs on the mixtape
- write my migration
how does that effect my models?
@irmiller22
irmiller22 / config.ru
Created October 21, 2013 14:22
hello_rack
# require 'Rack'
# class YourAppClass
# def call(env)
# [200, {'Content-Type' => 'text/html'}, ['Hello Rack!']]
# end
# end
# run YourAppClass.new
@irmiller22
irmiller22 / factorial.rb
Created October 16, 2013 03:45
factorial
def factorial(num)
if num <= 1
1
else
num * factorial(num-1)
end
end
@irmiller22
irmiller22 / serialize.rb
Last active December 25, 2015 15:49
serialize.rb
class Song
attr_accessor :title, :artist
def serialize
file_name = self.title.gsub(" ", "_").downcase
File.open("#{file_name}.txt", "w+") do |f|
f << "#{self.artist.name} - #{self.title}"
end
end
@irmiller22
irmiller22 / tap.rb
Created October 15, 2013 14:15
tap_method
class Dog
attr_accessor :name, :food, :breed
def bark
"Woof!"
end
def self.bark
"Awoo!"
end
@irmiller22
irmiller22 / version_sort.rb
Created October 13, 2013 19:46
version_sort_filenames
class Array
def version_sort
self.sort_by do |file|
file.scan(/\d+|[a-z]*/).map {|e1| e1.to_i}
end
end
end
filenames = [
"foo-1.10.2.ext",
"foo-1.11.ext",
@irmiller22
irmiller22 / iterators.rb
Created October 13, 2013 18:17
Iterators
def my_each(array)
i = 0
while i < array.length
yield(array[i])
i+=1
end
array
end
@irmiller22
irmiller22 / school_domain.rb
Created October 13, 2013 18:09
school_domain_model
require 'pry'
class School
attr_accessor :roster, :school
@@schools = []
def initialize(school)
@school = school
@roster = {}