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
begin_time = Time.now
yield
end_time = Time.now
elapse = end_time - begin_time
end
# Be careful, pasting this into IRB will take a long time to print.
# It's a loooong string. :)
long_string = "apple"*100000000
@shinobcrc
shinobcrc / roman.rb
Created June 22, 2016 22:25 — forked from kanet77/roman.rb
Convert from Decimal to Roman Numerals in Ruby
class RomanNumerals
RN = {
1000 => 'M',
500 => 'D',
100 => 'C',
50 => 'L',
10 => 'X',
5 => 'V',
1 => 'I'
}
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:TX] = "Texas"
@states[:GA] = "Georgia"
@shinobcrc
shinobcrc / count_letters.rb
Created June 22, 2016 14:32
Character count and Index locater
def count_letters(list)
letters = Hash.new(0)
list.each do |word|
word.split('').each { |letter| letters[letter] += 1 }
end
letters
end
my_array = ['lighthouse', 'in', 'the', 'house']
list = {
'yvr' => 'Vancouver',
'yba' => 'Banff',
'yyz' => 'Toronto',
'yxx' => 'Abbotsford',
'ybw' => 'Calgary'
}
# Why is it returning nil instead of first element of the list above
@shinobcrc
shinobcrc / fizzbuzz_messy.rb
Last active June 22, 2016 03:35 — forked from kvirani/fizzbuzz_messy.rb
W1D2 Homework Exercise - Ruby - Messy Fizzbuzz
def fizzbuzz(s, f)
s.upto(f) { |x| puts e(x) }
end
def e(number)
if div_3?(number) && div_5?(number)
"FizzBuzz"
elsif div_5?(number)
"Buzz"
elsif div_3?(number)
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby shakil_the_dog.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your dog (named Shakil).
# You'll probably want to write other methods, but this
# encapsulates the core dog logic
def shakil_the_dog
@shinobcrc
shinobcrc / fizzbuzz.rb
Last active June 22, 2016 02:59
fizzbuzz
def fizzbuzz(max)
(1..max).each do |i|
if i % 15 == 0
puts "FizzBuzz"
elsif i % 5 == 0
puts "Buzz"
elsif i % 3 == 0
puts "Fizz"
else
puts i