This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'open-uri' | |
require 'prawn' #makes a pdf! | |
html_tag = | |
'<html> | |
<head> | |
</head> | |
<body> | |
<ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
holiday_supplies = { | |
:winter => { | |
:christmas => ["Lights", "Wreath"], | |
:new_years => ["Party Hats"] | |
}, | |
:summer => { | |
:forth_of_july => ["Fireworks", "BBQ"] | |
}, | |
:fall => { | |
:thanksgiving => ["Turkey"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" | |
] |