Skip to content

Instantly share code, notes, and snippets.

@Leejojo
Leejojo / benchmark_with_block
Created June 24, 2016 23:19
Benchmark with Blocks
def benchmark
# Your benchmarking code goes here.
start_time = Time.now
yield
end_time = Time.now
puts @duration = end_time - start_time
end
@Leejojo
Leejojo / regular_expression.rb
Created June 25, 2016 03:06
Regular Expressions
# 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)
match = string.match(/\b\d{3}\-\d{3}\-\d{3}\b/)
!!match
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
@Leejojo
Leejojo / candidates.rb
Created June 26, 2016 17:56
Candidates
require 'active_support/all'
require 'pp'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
@Leejojo
Leejojo / car.rb
Created June 27, 2016 15:14
Week 2, Day 1 Notes : CLASSES
class Car
def initialize(model, colour)
@model = model
@colour = colour
end
end
@Leejojo
Leejojo / io exercise
Created June 27, 2016 17:08
I/O Excerises
require 'rubygems'
require 'rest-client'
fname = "sample.txt"
somefile = File.open(fname, "w")
somefile.puts "Hello file!"
somefile.close
@Leejojo
Leejojo / contact.rb
Created June 28, 2016 15:29
Contact List App
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
# Creates a new contact object
@Leejojo
Leejojo / barracks.rb
Created June 29, 2016 00:07
Warcraft 3
class Barracks
attr_reader :gold, :food
def initialize
@gold = 1000
@food = 80
end
def train_footman
@Leejojo
Leejojo / 1_hello_world.rb
Created June 29, 2016 22:47
Debugging with Rspec
### SETUP
require 'rspec'
### LOGIC (fix me)
def who (word)
word
end
def hello(who)
"hello #{who}!"
@Leejojo
Leejojo / Gemfile
Created June 29, 2016 23:45
Stubbing Review
gem 'rspec'
gem 'pry'
gem 'byebug'
@Leejojo
Leejojo / bookstore.sql
Created July 5, 2016 00:50
Bookstore SQL Assignment
#1
SELECT editions.isbn
FROM editions
INNER JOIN publishers
ON (editions.publisher_id = publishers.id)
WHERE (publishers.name = 'Random House');
#2
SELECT editions.isbn, books.title
FROM editions
INNER JOIN publishers