Skip to content

Instantly share code, notes, and snippets.

@irmiller22
irmiller22 / katz_deli.rb
Created October 11, 2013 16:07
katz_deli
katz_deli = []
def take_a_number(queue, name)
count = (queue.count + 1)
queue << "#{count}. #{name} "
puts "The line is currently: "
line(queue)
end
@irmiller22
irmiller22 / pidgeons.rb
Created October 11, 2013 16:15
pidgeons.rb
########################
# 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"],
@irmiller22
irmiller22 / reddit_scrape.rb
Created October 12, 2013 21:12
reddit_scrape
require 'json'
require 'rest-client'
require 'pry'
@html_reddit = " "
@irmiller22
irmiller22 / tweet_short.rb
Created October 12, 2013 21:39
tweet_substitute
require 'pry'
tweet1 = "Hey guys, can anyone teach me how to be cool? I really want to be the best at everything, you know what I mean? Tweeting is super fun you guys!!!!"
tweet2 = "OMG you guys, you won't believe how sweet my kitten is. My kitten is like super cuddly and too cute to be believed right?", "I'm running out of example tweets for you guys, which is weird, because I'm a writer and this is just writing and I tweet all day. For real, you guys. For real."
tweet3 = "GUISEEEEE this is so fun! I'm tweeting for you guys and this tweet is SOOOO long it's gonna be way more than you would think twitter can handle, so shorten it up you know what I mean? I just can never tell how long to keep typing!"
@substitute = {"to" => "2","too" => "2","two" => "2","for" => "4","four" => "4","be" => "b","you" => "u","at" => "@","and" => "&"}
@irmiller22
irmiller22 / normalize.rb
Created October 12, 2013 22:18
phone_normalize
# Download this file:
# https://gist.github.com/scottcreynolds/ac1b5c8d96de0c91bf7c/download
# Run it from your terminal with:
# ruby ruby_phone_format.rb
# (Just make sure you are in the right directory)
# ======================================
# Ignore All This Code
# ======================================
@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 = {}
@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 / 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 / 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 / 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