Skip to content

Instantly share code, notes, and snippets.

/* Protect the networkDefinitions object so that it is not mutable */
const networkDefinitions = {
gmb: {
name: 'Google My Business'
},
bbb: {
name: 'Better Business Bureau'
}
};
// Create a function to test if these sudoku puzzles are correct
// correct
[
[1,2,3,4,5,6,7,8,9],[4,5,6,7,8,9,1,2,3],[7,8,9,1,2,3,4,5,6],
[2,3,4,5,6,7,8,9,1],[5,6,7,8,9,1,2,3,4],[8,9,1,2,3,4,5,6,7],
[3,4,5,6,7,8,9,1,2],[6,7,8,9,1,2,3,4,5],[9,1,2,3,4,5,6,7,8]
],
// incorrect, 5 twice in block 5
// Three characters, Barbarian, Archer, and Wizard
// They all can attack, heal, defend (echo/print/etc.. the method name)
// Barbarian has the ability to charge
// Archer has the ability to shoot arrows
// Wizard has the ability to cast magic
// Each character starts with 100 health, 10 strength, 10 magic, 10 speed
// Barbarians will have extra strength of 20
// Archer will have extra speed of 20
// Wizard will have extra magic of 20
// Write a function that takes a string as an argument and returns the number of vowels (a, e, i, o, u) it contains.
// Example: foo('Hello World'); => 3
@iamkevinlowe
iamkevinlowe / s3_cache_control.rb
Last active June 19, 2017 18:17
Ruby script to update cache control on S3 objects
@s3 = Aws::S3::Client.new(
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
)
@bucket = ENV['S3_BUCKET_NAME']
def get_objects(continuation_token = nil, last_key = nil)
options = { bucket: @bucket, prefix: 'images/uploads/' }
options.merge!(continuation_token: continuation_token) if continuation_token
@iamkevinlowe
iamkevinlowe / crypto.rb
Created February 16, 2017 23:53
Crypto module to encrypt/decrypt with AES128 and AES256
module Crypto
module AES128
class << self
def encrypt(data)
aes = OpenSSL::Cipher.new('AES-128-CBC')
aes.encrypt
aes.key = Digest::MD5.digest(ENV['SECRET_KEY'])
crypt = aes.update(data) + aes.final
Base64.urlsafe_encode64(crypt)
end
def solve_problem
numbs = Array(1..999)
mults_of_3 = []
mults_of_5 = []
all_mults = []
the_answer = 0
numbs.each do |number|
if number % 3 == 0
mults_of_3 << number
end
# http://osherove.com/tdd-kata-1/
class StringCalculator
def add(string)
# Default delimiters to split string
delims = %w(, \n)
# If string begins with "//[delimiter]\n" include delimiter to array of delimiters
if string.match(/^\/\/.+/)
match, string = string.split('\n', 2)
# http://www.codewars.com/kata/54eb33e5bc1a25440d000891/train/ruby
def decompose(n, area = n**2, squares = "", results = [])
if area == 0
results << squares.strip.split(' ').map(&:to_i)
elsif
x = Math.sqrt(area).floor
x -= 1 while x >= n
x.downto(1) do |i|
@iamkevinlowe
iamkevinlowe / triplebyte_programming_challenge.rb
Created December 15, 2015 23:22
Triplebyte Programming Challenge
# The first 12 digits of pi are 314159265358. We can make these digits into an expression evaluating to 27182 (first 5 digits of e) as follows:
# 3141 * 5 / 9 * 26 / 5 * 3 - 5 * 8 = 27182
# or
# 3 + 1 - 415 * 92 + 65358 = 27182
# Notice that the order of the input digits is not changed. Operators (+,-,/, or *) are simply inserted to create the expression.
# Write a function to take a list of numbers and a target, and return all the ways that those numbers can be formed into expressions evaluating to the target. Do not use the eval function in Python, Ruby or JavaScript