Skip to content

Instantly share code, notes, and snippets.

require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
#Determine whether a string contains a SIN (Social Insurance Number).
#A SIN is 9 digits and we are assuming that they must have dashes in them
def has_sin?(string)
if string.match(/\b(\d{3}-\d{3}-\d{3})\b/)
return true
else
return false
end
end
def benchmark
start_time = Time.now
yield
end_time = Time.now
run_time = end_time - start_time
return run_time
end
long_string = "apple"*100000000
def to_roman(num)
#this mess takes the number, puts each digit in an array as an int
#and then reverse the array... why, you ask? because I'm lazy.
#this way I can then deal with the smallest numbers first, thus
#removing the need to know the length of num ahead of time.
#or something. i'm sure there are better ways.
num_arr = []
while num > 0
num_arr.unshift num % 10
states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
states[:DS] = "Distress"
states[:DR] = "Disrepair"
@clark-teeple
clark-teeple / debug01.rb
Last active August 26, 2015 15:43 — forked from rafd/debug01.rb
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'}
# Why is it returning nil instead of first element of the list above
p list['yvr']
#because hash does not use index
#I had a 24 line version, but the assignment seems to request more than one method.
go = true
while go
#could be a method, but really no need to
#since it always has to happen
puts "> "
speak = gets.chomp.downcase
#had this in the main method, but this works too
def continue(speak)
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
if baller && furnished || rent < 2100
return true
else
return false
end
end
###
last = rand(1..100)
start = rand(1..last)
def fizzbuzz(start,last)
start.upto(last) do |i|
if i % 5 == 0 && i % 3 == 0
puts "FizzBuzz"
elsif i % 5 == 0
# Find the maximum
def maximum(arr)
largest = arr[0]
arr.each do |i|
if i > largest
largest = i
end
end
return largest
end