Skip to content

Instantly share code, notes, and snippets.

@TylerRockwell
TylerRockwell / scale_app
Last active August 29, 2015 14:25
Scale App
#Compares weight of 2 items
def weigh(item1, item2)
$totalWeighings += 1
if item1 > item2
return 0
elsif item2 > item1
return 1
else
return 2
end
@TylerRockwell
TylerRockwell / gist:39d8f5d68a7f2a2a51e0
Last active August 31, 2015 22:38
Week 1 Exercise 1 - User Input Statistics
#WARNING! This code is functional but has some redundancy
#LEVEL: NIGHTMARE
def is_a_number(input)
true if Float(input) rescue false
end
def get_input()
puts "Please give me your input:"
gets.chomp
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which returns:
#
# * "Fizz" if the number is divisible by 3
# * "Buzz" if the number is divisible by 5
# * "FizzBuzz" if the number is divisible by 3 and 5
# * Otherwise, return the number itself
#
@TylerRockwell
TylerRockwell / Time Entry SQL Practice
Created September 16, 2015 11:55
Time Entry SQL Practice
Find all time entries.
SELECT *
FROM time_entries;
# Results Returned: 500
Find the developer who joined the company most recently.
SELECT *
FROM developers
ORDER BY joined_on DESC
require 'minitest/autorun'
require 'minitest/pride'
# Write two methods:
#
# * `first_name`: given a name in string, return the first name.
# * `last_name`: given a name in string, return the last name.
# WRITE YOUR CODE HERE.
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts an array and returns a hash. Each item in the
# array will be a string, and the returned hash should have last names as keys
# and first names as values.
# WRITE YOUR CODE HERE. Name your method `names`.
def first_name(name)
array = name.to_s.split
@TylerRockwell
TylerRockwell / gist:59d718267073ac9fe91d
Last active September 17, 2015 17:20
Palindrome Challenge 9-17-15
require 'minitest/autorun'
require 'minitest/pride'
# Write a method which accepts one parameter. The method should return true if
# the string passed to it is a palindrome. It should return false if the string
# is not a palindrome
def palindrome?(string)
string.downcase!
string = string.gsub(/\W/, '')
@TylerRockwell
TylerRockwell / gist:a38d489c4ccc4dc6cf44
Created September 21, 2015 13:16
In Class Challenge 09-21-15
require 'minitest/autorun'
require 'minitest/pride'
# Write two classes which inherit from the Vehicle class below. You will also
# need to add a method to the Vehicle class during this challenge.
class Vehicle
def initialize(make, model)
@make = make
@model = model
require 'minitest/autorun'
require 'minitest/pride'
#I somehow overlooked this challenge. Submitting now on 9-21
class Goat
attr_reader :name
def initialize(name)
@TylerRockwell
TylerRockwell / gist:6d5e13bc29abc3935900
Created September 22, 2015 13:59
Composition Challenge 9-22-15
require 'minitest/autorun'
require 'minitest/pride'
# Write a class which wraps around an array, but only allows odd numbers
# to be stored in the array.
class OddArray
def initialize(numbers)
@array = numbers.select{|num| num % 2 == 1}
end