Skip to content

Instantly share code, notes, and snippets.

@goofiw
goofiw / awsGetSignedUrlExample.js
Last active February 4, 2021 08:14
aws getSignedUrl example using Node and aws-sdk
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();
@goofiw
goofiw / Lighthouse
Created June 1, 2015 18:37
Lighthouse Basic for loop
var lighthouse = function(num) {
var arr= [];
for(var i = 1; i <= num; i++) {
arr.push(i);
}
return arr;
};
console.log(lighthouse(5));
@goofiw
goofiw / Generix-Gist
Created May 8, 2015 17:43
Generic Gist
Gist Generic
@goofiw
goofiw / regular_expressions
Created April 30, 2015 22:24
Regular Expressions practice and gsub
# 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
@goofiw
goofiw / benchmark_with_block
Created April 30, 2015 18:10
Time Benchmark
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. :)
@goofiw
goofiw / Poppin_Bottles
Last active August 29, 2015 14:20
Poppin Bottles - Directions were not very clear, but I made it recursive assuming the same customer drinking all the soda
@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
@goofiw
goofiw / state_info
Created April 30, 2015 00:55
State_info - All but combining into one hash
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)
@goofiw
goofiw / romans
Last active August 29, 2015 14:20
Modern and Ancient Roman Numerals
@numbers = {
M: 1000,
D: 500,
C: 100,
L: 50,
X: 10,
V: 5,
I: 1
}
@goofiw
goofiw / Count_Letters
Created April 29, 2015 19:49
count letters and count_with_indexes
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")