Skip to content

Instantly share code, notes, and snippets.

@Andsbf
Andsbf / Messing_classes.rb
Created March 9, 2015 21:13
Classical Inheritence (Mini Exercise)
require 'rspec'
RSpec.configure do |config|
config.color = true
end
#classes experiment!!!
module Flight
def fly
print("I'm #{self.class}, Sure I can fly")
end
@Andsbf
Andsbf / candidates.rb
Created March 9, 2015 03:00
Candidates Exercise
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
@Andsbf
Andsbf / pop_bottles_promotion.rb
Last active August 29, 2015 14:16
Pop Bottle Recycler
require 'pry'
class Exchange
def initialize x_client
bottles_earned = {by_empty: 0, by_tips: 0}
bottles_earned[:by_empty] += x_client.bottles_empty/2
x_client.bottles_empty = x_client.bottles_empty%2
@Andsbf
Andsbf / regular_expression.rb
Created March 7, 2015 20:09
Regular Expressions Exercise
# 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)
!( /\b(\d){3}-(\d){3}-(\d){3}\b/ =~ string ).nil?
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
puts "has_sin? returns false if it doesn't have a SIN"
def benchmark
# Your benchmarking code goes here.
start_time = Time.now
yield
end_time = Time.now
running_time = end_time - start_time
end
@Andsbf
Andsbf / to_roman.rb
Created March 5, 2015 03:42
Roman Numerals Exercise
require 'pry'
# require 'pry-nav'
def to_roman(num)
@roman_num = ""
@num = num
roman_M(@num)
roman_D(@num)
roman_C(@num)
roman_L(@num)
@Andsbf
Andsbf / state_info.rb
Created March 5, 2015 00:51
States & Cities Exercise
# require 'pry'
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:TX] = "Texas"
@states[:OK] = "OKlahoma"
@Andsbf
Andsbf / count_letters.rb
Last active August 29, 2015 14:16
Character Counting Exercise
require 'pry'
def count_letters (string="")
counts = Hash.new(0)
string.split("").each do |element|
# binding.pry
counts[element] += 1 if element != " "
end
@Andsbf
Andsbf / debug01.rb
Created March 4, 2015 20:30
Debug Exercise
require 'pry'
list = {'yvr' => 'Vancouver', 'yba' => 'Banff', 'yyz' => 'Toronto', 'yxx' => 'Abbotsford', 'ybw' => 'Calgary'}
binding.pry
# Why is it returning nil instead of first element of the list above
p list.first
@Andsbf
Andsbf / Sign shop exercise
Created March 4, 2015 04:37
Sign shop app
def get_dimension_price
while true
puts "Input banner width in m:"
width = gets.chomp.to_f
break if (width != 0.0 && width < 150) # avoid string input and unreasonable values=a banner bigger than 150m
end
puts "Input banner height in m:"
height = gets.chomp.to_f