Skip to content

Instantly share code, notes, and snippets.

View TrevMcKendrick's full-sized avatar

Trevor McKendrick TrevMcKendrick

View GitHub Profile
class Student
attr_accessor :name, :twitter, :linkedin, :facebook, :website
attr_reader :id
@@students = []
def initialize
@@students << self
@id = @@students.count
end
class Jukebox
attr_accessor :songs, :desire, :current_song #:song_hash
def initialize(songs)
@songs = songs
#@song_hash = {}
help
end
"Which SQL command selects all the columns from the sable?"
SELECT *
SELECT all
SELECT rows
SELECT every_one_of_them
"Which SQL command is used to sort the result-set?"
SORT
ARRANGE
SORT_BY
########################
# NYC PIGEON ORGANIZER #
########################
# Start with the following collected data on NYC pigeons.
pigeon_data = {
:color => {
:purple => ["Theo", "Peter Jr.", "Lucky"],
:grey => ["Theo", "Peter Jr.", "Ms .K"],
@TrevMcKendrick
TrevMcKendrick / hashketball.rb
Created October 1, 2013 13:06
Hashketball Homework
game = {
:the_lakers => {
:name => "The Lakers",
:colors => ["purple","gold"],
:players => {
:daniel_mckendrick => {
:stats => {
:points => 25,
:rebounds => 5,
:assists => 3,
@TrevMcKendrick
TrevMcKendrick / gist:6728872
Created September 27, 2013 13:49
todo parse phone #'s
def normalize_phone_number(str)
parsed_str = str.gsub(/[^0-9]/, "")
return str if parsed_str.length != 10
parsed_str.insert(0, "(")
parsed_str.insert(4, ") ")
parsed_str.insert(9, "-")
return parsed_str
# You're hosting a conference and need to print badges for the speakers. Each
# badge should say: "Hello, my name is _____."
# **Write a method that will create and return this message, given a person's
# **name.**
def badge(name)
"Hello my name is #{name}"
end
#badge("Trevor")
# Let's go back to the exercise where we determined what is and isn't a vowel.
# With ruby, there's always more than one way to do something and get the same
# result.
# Assuming vowels `a,e,i,o,u`:
# 1. Write a method that returns whether a given letter is a vowel, using `if`
# and `elsif`
def is_vowel_one?(letter)
def my_each(array)
i = 0
while i < array.length do
yield(array[i])
i += 1
end
end
my_each(["boy",7,true,"awesome_sauce","YES"]) { |x| puts x}
#From [rubeque](http://rubeque.com/problems/temperature-robot)
#Temperature bot is comfortable when it's room temperature (18-21C). Help him out by completing the method below:
#Temperature bot is American but takes Celsius temperatures.
def temperature_bot(temp)
if temp >= 18 && temp <= 21
puts "I like this temperature"