Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / nyc-pidgeon-organizer.rb
Created October 3, 2013 02:51
NYC Pigeon Organizer
########################
# NYC PIGEON ORGANIZER #
########################
# Start with the following collected data on NYC pigeons.
require 'pry'
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
@gregeng
gregeng / scraping_students.rb
Last active December 24, 2015 16:49
scraping student pages
# Scraping Most Voted Hackernews
require 'pry'
require 'nokogiri'
require 'open-uri'
# Get all the Posts on Hackernews
# student_profile = Nokogiri::HTML(open('http://students.flatironschool.com/students/greg_eng.html'))
student_index_page = Nokogiri::HTML(open('http://students.flatironschool.com'))
@gregeng
gregeng / binary_handshake.rb
Last active December 25, 2015 00:09
binary-handshake
require 'pry'
class SecretHandshake
attr_accessor :binary
def initialize(binary)
@binary = binary
end
def commands
@gregeng
gregeng / oop-jukebox-practice.rb
Last active December 25, 2015 00:18
oop-jukebox-practice
# Build a Jukebox
require 'pry'
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
@gregeng
gregeng / student_scrape.rb
Last active December 25, 2015 00:49
oop-studentscrape
require 'pry'
require 'nokogiri'
require 'open-uri'
require_relative './student_scrape'
class Student
attr_accessor :name, :twitter, :linkedin, :facebook, :website
@@students = []
def initialize(name, twitter, linkedin, facebook, website)
@gregeng
gregeng / my_each.rb
Created October 11, 2013 15:30
my_each
class Array
def my_each
i = 0
while i < self.length
yield(self[i])
i+=1
end
self
end
@gregeng
gregeng / anagram.rb
Created October 14, 2013 15:14
anagram
require 'pry'
class Anagram
attr_reader :word
def initialize(word)
@word = word
end
def match(array=%w(hello world zombies pants))