Skip to content

Instantly share code, notes, and snippets.

# Write a program that tells you the following:
#
# Hours in a year. How many hours are in a year?
# Minutes in a decade. How many minutes are in a decade?
# Your age in seconds. How many seconds old are you?
#
# Define at least the following methods to accomplish these tasks:
#
# seconds_in_minutes(1)
# minutes_in_hours(1)
@irmiller22
irmiller22 / collect&select.rb
Created October 1, 2013 13:54
Week 2, Day 1 Exercises & HW
def apple_picker(array)
array.select do |x|
x == "apple"
end
end
def apple_picker(array)
test = []
array.collect do |x|
@irmiller22
irmiller22 / gist:6809411
Created October 3, 2013 12:58
Pigeon_Sort
########################
# NYC PIGEON ORGANIZER #
########################
require 'pry'
# Start with the following collected data on NYC pigeons.
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
require_relative './song_library.rb'
def jukebox(command)
if command.downcase == "list"
list_library
else
parse_command(command)
end
end
@irmiller22
irmiller22 / gist:6830131
Created October 4, 2013 18:09
Scraping Example
# Scraping Most Voted Hackernews
require 'nokogiri'
require 'open-uri'
# Get all the Posts on Hackernews
doc = Nokogiri::HTML(open('http://ycombinator.com/'))
# Figure out their vote count
stories = hacker_news.css("span.comhead")
# stories.first.class

##RSpec Code Coverage Lab

How do we know we have enough tests, and that our tests cover all of our code?

Enter simplecov! simplecov is a tool that will measure your test run against the code paths in your code files and see if you're exercising them all. "Code Paths" includes method calls, conditional statements, loops, and anything that branches program flow.

This is important because you want to be able to know that every decision your program makes is being tested, no matter what.

Assignment

@irmiller22
irmiller22 / jukebox.rb
Created October 9, 2013 04:18
rspec_code_coverage
# A Jukebox filled with songs
# that responds to help, list, play, and exit
require_relative 'song'
class Jukebox
attr_accessor :songs
APPROVED_COMMANDS = [:list, :help, :exit]
def initialize(songs)
@songs = songs
@irmiller22
irmiller22 / person.rb
Created October 10, 2013 14:17
Mass-Assign at Initialization
class Person
attr_accessor :name, :birthday, :hair_color, :eye_color, :height,:weight,:handed,:complexion,:t_shirt_size,:wrist_size,:glove_size, :pant_length,:pant_width
def initialize(attributes)
attributes.each do |key, value|
self.send("#{key}=", value)
end
@irmiller22
irmiller22 / reverse_word.rb
Created October 11, 2013 16:04
reverse_word.rb
def reverse_each_word(sentence)
temp_array = []
array = sentence.split(//)
array.length.times do
temp_array.push(array.pop)
end
array = temp_array.join
array
end
@irmiller22
irmiller22 / apple_picker.rb
Created October 11, 2013 16:06
apple_picker.rb
def apple_picker(array)
array.select do |x|
x == "apple"
end
end
def apple_picker(array)
test = []
array.collect do |x|