Skip to content

Instantly share code, notes, and snippets.

View ahimmelstoss's full-sized avatar

Amanda Himmelstoss ahimmelstoss

View GitHub Profile
INSERT INTO users (id, name, age, gender, education) VALUES (1, "Finnbar", 17, "male", "MD");
INSERT INTO users (id, name, age, gender, education) VALUES (2, "Smokey the Bear", 78, "male", "GED");
INSERT INTO users (id, name, age, gender, education) VALUES (3, "Rosey", 9, "female", "GED");
INSERT INTO quizzes (id, quiz_name, topic, length) VALUES (1, "Ruby Syntax Quiz", "syntax", 5);
INSERT INTO quizzes (id, quiz_name, topic, length) VALUES (2, "Git Quiz", "version control", 5);
--quiz 1--
INSERT INTO questions (id, quizzes_id, content) VALUES (1, 1, "How do you define a method?");
INSERT INTO questions (id, quizzes_id, content) VALUES (2, 1, "How do you define a class?");
require 'json'
require 'open-uri'
require 'prawn' #makes a pdf!
html_tag =
'<html>
<head>
</head>
<body>
<ul>
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
@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}."
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:"
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.
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"],
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"
holiday_supplies = {
:winter => {
:christmas => ["Lights", "Wreath"],
:new_years => ["Party Hats"]
},
:summer => {
:forth_of_july => ["Fireworks", "BBQ"]
},
:fall => {
:thanksgiving => ["Turkey"]
$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"
]