This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@values = [ | |
[1000, 'M'], | |
[500, 'D'], | |
[100, 'C'], | |
[50, 'L'], | |
[10, 'X'], | |
[5, 'V'], | |
[1, 'I'] | |
] | |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
class Question | |
def initialize | |
@num1 = rand(1...20) | |
@num2 = rand(1...20) | |
end | |
def to_string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Flight | |
puts "I'm a bird!, I can fly!" | |
end | |
class Animal | |
attr_reader :num_legs, :prey, :habitat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Barracks | |
attr_reader :food, :gold | |
def initialize | |
@gold = 1000 | |
@food = 80 | |
end | |
def can_train_footman? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |