Skip to content

Instantly share code, notes, and snippets.

View ahimmelstoss's full-sized avatar

Amanda Himmelstoss ahimmelstoss

View GitHub Profile
@ahimmelstoss
ahimmelstoss / tweet-shortener.rb
Last active December 24, 2015 01:29
shortening tweets by turning them into arrays and iterating over them with a hash of substitutions.
require 'awesome_print'
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?"
tweet3 = "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."
tweet4 = "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!"
tweet5 = "to two too four for be you at and"
$substitutions_hash = { #global variable to work in method
"to" => "2", "two" => "2", "too" => "2", "for" => "4", "four" => "4", "be" => "b",
@ahimmelstoss
ahimmelstoss / conference-lab.rb
Created September 27, 2013 03:19
Conference Lab
$conference_speakers = ["Edsger", "Ada", "Charles", "Alan", "Grace", "Linus", "Matz"]
def badge_printer(speaker_array)
speaker_array.each do |name|
puts "Hello, my name is #{name}!"
end
end
def room_assignments(speaker_array)
speaker_array.each_index do |index|
$songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The Phoenix - Consolation Prizes"
]
holiday_supplies = {
:winter => {
:christmas => ["Lights", "Wreath"],
:new_years => ["Party Hats"]
},
:summer => {
:forth_of_july => ["Fireworks", "BBQ"]
},
:fall => {
:thanksgiving => ["Turkey"]
def reverse_each_word(sentence)
sentence_array = sentence.split(" ")
sentence_array.collect {|word| word.reverse}.join(" ")
end
puts reverse_each_word("Hello there, and how are you?")
#=> "olleH ,ereht dna woh era ?uoy"
movie_collection = {
:rom_com => ["Bridesmaids", "Bridge Jone's Diary", "Love Actually",
"The Notebook", "He's Just Not that into You", "Friends with Benefits"],
:sci_fi => ["Avatar", "Battlestar Gallatica", "World War Z"],
:drama => ["Blue Jasmine", "Beasts of the Southern Wild"],
:foreign => ["Sin Nombre", "Y Tu Mama Tambien", "Los Amantes Pasajeros", "La Piel que Habito"]
}
recipes_hash = {
:chili => ["turkey", "beans", "chili", "spices", "tomatoes", "cheese"],
fruit_array = ["apple", "pear", "orange", "banana", "apple", "peach", "Apple"]
def apple_picker(array)
array.select { |fruit| fruit.downcase == "apple" }
end
apple_picker(fruit_array)
#Implement it with collect and then implement it with select.
#Write a sentence about how select differs from collect.
amandas_deli = []
def take_a_number(amandas_deli, customer)
amandas_deli << customer
puts "#{customer}, you are number #{amandas_deli.count} in line."
#counts number of elements in array
end
def line(amandas_deli)
puts "The line is currently:"
@ahimmelstoss
ahimmelstoss / hanoi.rb
Created October 2, 2013 03:16
Towers of Hanoi
a = [1,2,3,4]
b = []
c = []
def move_disk(number_of_disks,from,to,via)
orig_from = Array.new(from)
orig_to = Array.new(to)
orig_via = Array.new(via)
if number_of_disks == 1
to.unshift(from.shift)
puts "Moved #{number_of_disks} disks from #{orig_from} to #{orig_to} via #{orig_via}; from is now #{from}; to is now #{to}."
class Array
def version_sort
return self.sort {|a,b| my_comparison(a, b) }
end
#split each string by - or . and then sort by those parts
def my_comparison(left, right) #returns -1 or 0 or 1
left_array = left.split(/[-\.]/) #left array
right_array = right.split(/[-\.]/) #right array
left_array.pop
right_array.pop