Skip to content

Instantly share code, notes, and snippets.

@values = [
[1000, 'M'],
[500, 'D'],
[100, 'C'],
[50, 'L'],
[10, 'X'],
[5, 'V'],
[1, 'I']
]
def benchmark
start_time = Time.now
yield()
end_time = Time.now
end_time - start_time
# Your benchmarking code goes here.
end
# Be careful, pasting this into IRB will take a long time to print.
# It's a loooong string. :)
# # 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)
regex = /(?<!\d)\d{3}.?\d{3}.?\d{3}(?!\d)/
truth = !!(regex =~ string)
end
puts "has_sin? returns true if it has what looks like a SIN"
puts has_sin?("please don't share this: 234-604-142") == true
# In this file we define the methods to help filter out candidates
# This way, we keep these methods separated from other potential parts of the program
def ordered_by_qualifications(arr)
sorted = arr.sort_by {|cand| [-cand[:years_of_experience], -cand[:github_points]]}
# return sorted.reverse
end
def repl
loop do
puts "Please enter command(find one, all, qualified, quit)"
answer = gets.chomp
require 'pry'
class Question
def initialize
@num1 = rand(1...20)
@num2 = rand(1...20)
end
def to_string
# fname = "sample.txt"
# somefile = File.open(fname, "w")
# somefile.puts "Hello file!"
# somefile.close
# require 'rubygems'
# require 'rest-client'
# wiki_url = "http://en.wikipedia.org"
# wiki_local_filename = "wiki-page.html"
module Flight
puts "I'm a bird!, I can fly!"
end
class Animal
attr_reader :num_legs, :prey, :habitat
# require './contacts.csv'
require 'csv'
# Represents a person in an address book.
# The ContactList class will work with Contact objects instead of interacting with the CSV file directly
class Contact
attr_accessor :name, :email
class Barracks
attr_reader :food, :gold
def initialize
@gold = 1000
@food = 80
end
def can_train_footman?
1. SELECT isbn
FROM editions
WHERE publisher_id = 59;
2. SELECT isbn, title
FROM books
JOIN editions on books.id = editions.book_id
WHERE publisher_id = 59;
3. SELECT stock, retail, title, editions.isbn