http://code.tutsplus.com/tutorials/ruby-for-newbies-testing-with-rspec--net-21297
tutsplus rspec tutorial.
require('dotenv').load(); | |
var AWS = require('aws-sdk'), | |
AWS_ACCESS_KEY_ID = process.env.S3_ACCESS_KEY, | |
AWS_SECRET_ACCESS_KEY = process.env.S3_SECRET; | |
AWS.config.update({accessKeyId: AWS_ACCESS_KEY_ID, secretAccessKey: AWS_SECRET_ACCESS_KEY}); | |
AWS.config.region = 'us-west-2'; | |
var s3 = new AWS.S3(); |
var lighthouse = function(num) { | |
var arr= []; | |
for(var i = 1; i <= num; i++) { | |
arr.push(i); | |
} | |
return arr; | |
}; | |
console.log(lighthouse(5)); |
Gist Generic |
http://code.tutsplus.com/tutorials/ruby-for-newbies-testing-with-rspec--net-21297
tutsplus rspec tutorial.
# 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 | |
require 'byebug' | |
def has_sin?(string) | |
!!string.match(/\b\d{3}\W?\d{3}\W?\d{3}\b/) | |
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 |
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. :) |
@caps = 0 | |
@empties = 0 | |
@cash = 0 | |
def user_prompt_cash | |
puts "How many dollars would you like to spend on soda pop today?" | |
@cash = gets.chomp.to_i | |
end | |
def calculate_full_bottles | |
(@cash + user_prompt_cash.to_i)/2 + @caps/4 + @empties/2 |
def describe_state(state_code) | |
first_part = "#{state_code} is for #{@states[state_code.to_sym]}.\ | |
It has #{@cities[state_code.to_sym].length} major cities:" | |
@cities[state_code.to_sym].each { |city| first_part << " #{city},"} | |
first_part.chomp(',') | |
end | |
def calculate_tax(state_code, amount) | |
if @taxes.keys.includes?(state_code.to_sym) | |
'%.2f' % (amount * (1 + @taxes[state_code.to_sym] / 100)).round(2) |
@numbers = { | |
M: 1000, | |
D: 500, | |
C: 100, | |
L: 50, | |
X: 10, | |
V: 5, | |
I: 1 | |
} |
def count(string) | |
let_counts = {} | |
string.split(//).each { |let| let_counts[let] ? let_counts[let] += 1 : let_counts[let] = 1 } | |
let_counts | |
end | |
puts count("lea asdjflasdfl asidufoaubvoahboaeurfaw") | |
puts count ("maybe a better count zzzzzzz ooo") |