Skip to content

Instantly share code, notes, and snippets.

View TrevMcKendrick's full-sized avatar

Trevor McKendrick TrevMcKendrick

View GitHub Profile
# Create Some Hashes
## Create Hashes for the following use-cases.
# - A movie collection that organizes by genres
# - Recipes with ingredients
# - User profiles where each user has a list of favorite colors along with 3 personal essays, essay_1, essay_2, essay_3
first_line = ["Trevor","Breanna","Annelise","Daniel","Curtis","Robert"]
def take_a_number(line,new_customer)
line << new_customer
first_line = line.length
end
def now_serving(line)
puts "Currently serving " + line.pop
end
game = {
:the_lakers => {
:name => "The Lakers",
:colors => ["purple","gold"],
:players => {
:daniel_mckendrick => {
:stats => {
:points => 25,
:rebounds => 5,
:assists => 3,
def prime?(possible_prime)
test_range = possible_prime / 2
true
puts !(2..test_range).any? { |number| possible_prime % number == 0 }
end
puts prime?(52)
puts 51/
# tower_of_hanoi.rb
a = [1,2]
b = []
c = []
# Move the disks from one peg to another following the rules of Hanoi.
#
# number_of_disks - the total number of disks
# from - the starting peg
# create a method called create_groups that, given an array of student names,
# a group size, and a number of groups, will return an array of groups of
# of students with no student in adjacent groups
def create_groups(students,group_size,group_count)
new_student_array = []
i = 0
j = 0
require 'json'
require 'rest_client'
reddit_url = "http://www.reddit.com/"
reddit_hash = JSON.parse(RestClient.get('http://www.reddit.com/.json'))
#puts reddit_hash["data"]["children"][1]
#reddit_hash["data"].each {|k,v| puts k}
########################
# NYC PIGEON ORGANIZER #
########################
# Start with the following collected data on NYC pigeons.
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
HOMEWORK
1. SELECT title, sum(amount)
FROM projects
JOIN pledges
ON projects.id = pledges.project_id
GROUP BY title;
2. SELECT name,age,amount
FROM users JOIN pledges
ON pledges.user_id = users.id;
require_relative './song_library.rb'
def jukebox(command)
if command.downcase == "list"
list_library
else
parse_command(command)
end
end