Skip to content

Instantly share code, notes, and snippets.

@gregeng
gregeng / my_iterators.rb
Created October 2, 2013 14:45
my_iterators: each, collect, select, none?
my_none?([1,2,3]) { |x| x == 4 }
@gregeng
gregeng / lab4-hashketball.rb
Created October 1, 2013 12:05
Lab 4: Hashketball
# Hashketball Nests
#
# Great news! You're going to an NBA game! The only catch is that you've been
# volunteered to keep stats at the game.
#
# Using Nested Hashes, define a game, with two teams, their players, and the players stats:
#
# The game has two teams.
#
# A team has:
@gregeng
gregeng / lab3-deli.rb
Created October 1, 2013 12:04
Lab 3: Deli
katz_deli = []
def take_a_number(deli, name)
deli << name
puts deli.index(name)+1
end
def now_serving(deli)
puts "Currently serving #{deli[0]}"
deli.shift
@gregeng
gregeng / lab2-applepickerholidays.rb
Created October 1, 2013 12:03
Lab 2: Apple Picker Holidays
# Apple Picker
# Skills: Collect and Select
def apple_picker_collect(fruits=["apple", "orange", "apple"])
only_apples = fruits.collect do |x|
x if x == "apple"
end
only_apples.compact!
@gregeng
gregeng / lab1-hashesandreverse.rb
Created October 1, 2013 12:02
Lab 1: Hashes Reverse Each Word
# A movie collection that organizes by genres
# Recipes with ingredients
# User profiles where each user has a list of favorite colors along with 3 personal essays, essay_1, essay_2, essay_3
## Hashes
movie_collection = {
:action => ["Man on Fire", "Fight Club"]
:adventure => ["National Treasure", "National Treasure 2"]
:comedy => ["BASEketball", "Wedding Crashers"]
@gregeng
gregeng / gist:6723514
Created September 27, 2013 02:42
Day 4: Another Homework - Tweet Shortener
# Tweet Keyword Shortener
# "to, two, too" become '2'
# "for, four" become '4'
# 'be' becomes 'b'
# 'you' becomes 'u'
# "at" becomes "@"
# "and" becomes "&"
# Possible Regexes
@gregeng
gregeng / gist:6723133
Created September 27, 2013 01:45
Day 4: The Second Program
# Given this List of Songs, Construct Arrays by Artist and Album
# Hint: Make use of the split() String Method
# http://www.ruby-doc.org/core-1.9.3/String.html#method-i-split
# Simple Example of Data Parsing
songs = [
"The Magnetic Fields - 69 Love Songs - Parades Go By",
"The Magnetic Fields - Get Lost - Smoke and Mirrors",
"Neutral Milk Hotel - In An Aeroplane Over the Sea - Holland 1945",
"The Magnetic Fields - Get Lost - You, Me, and the Moon",
@gregeng
gregeng / gist:6723087
Last active December 24, 2015 01:19
Lab: Conference Badges and Schedules // Lab: Different Ways to Discover what's true
# You're hosting a conference and need to print badges for the speakers. Each badge should say: "Hello, my name is _____."
# Write a method that will create and return this message, given a person's name.
# Now the list of speakers is finalized, and you can send the list of badges to the printer. Remember that you'll need to give this list to the printer, so it should be accessible outside of the method.
# Modify your method so it can take a list of names as an argument and return a list of badge messages.
# Your conference speakers are: Edsger, Ada, Charles, Alan, Grace, Linus and Matz. How you scored these luminaries is beyond me, but way to go!
@gregeng
gregeng / gist:6709402
Last active December 23, 2015 23:19
quiz
# 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)
@gregeng
gregeng / gist:6709385
Created September 26, 2013 03:09
fizzbuzz
# assignment.rb
# FizzBuzz - The Programmer's Stairway to Heaven
# Define the fizzbuzz method to do the following: 10pts
# Use the modulo % method (divisible by)
# 2 % 2 #=> true
# 1 % 2 #=> false
# If a number is divisible by 3, puts "Fizz".
# If a number is divisible by 5, puts "Buzz".
# If a number is divisible by 3 and 5, puts "FizzBuzz"