Skip to content

Instantly share code, notes, and snippets.

View jazzytomato's full-sized avatar
🎶
🎷 🍅

Tom Haratyk jazzytomato

🎶
🎷 🍅
View GitHub Profile
@jazzytomato
jazzytomato / mock_env.rb
Last active April 3, 2024 00:49
Simple method to mock environment variable in ruby with minitest or other testing framework
# in test_helper.rb (for example)
def mock_env(partial_env_hash)
old = ENV.to_hash
ENV.update partial_env_hash
begin
yield
ensure
ENV.replace old
end
end
# Local tunnel to connect to remote DB via bastion ec2 instance
ssh -N -L 5433:DBHOSTNAME.eu-west-1.rds.amazonaws.com:5432 tom@ecX-XX-XXX-XXX-XXX.eu-west-1.compute.amazonaws.com
# then connects to db locally with localhost:5433
@jazzytomato
jazzytomato / sublime prefs.json
Created April 4, 2018 10:00
sublime config save
{
"color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
"font_face": "Fira Code",
"font_size": 15,
"ignored_packages":
[
"Vintage"
],
"rubocop_path": "~/.rbenv/shims/rubocop --config ~/.rubocop.yml",
"ruby_path": "~/.rbenv/shims/ruby",
# set a badge with a hostname
# Also sets a bg color when in prod
function warnssh() {
printf "\e]1337;SetBadgeFormat=%s\a" $(echo -n $1 | base64)
if [[ $1 =~ "^prod-.*" ]] ; then
echo -e "\033]1337;SetColors=bg=612c62\a"
fi
ssh $*
printf "\e]1337;SetBadgeFormat=%s\a" ""
echo -e "\033]1337;SetColors=bg=000\a"
@jazzytomato
jazzytomato / coin_change.rb
Created January 14, 2020 20:24
Making change in Ruby
# Instructions: run with rspec coin_change.rb
#
#
# Making Change
# Given a number "x" and a sorted array of coins "coinset", write a function
# that returns the amounts for each coin in the coinset that sums up to X or
# indicate an error if there is no way to make change for that x with the given
# coinset. For example, with x=7 and a coinset of [1,5,10,25], a valid answer
# would be {1: 7} or {1: 2, 5: 1}. With x = 3 and a coinset of [2,4] it should
# indicate an error. Bonus points for optimality.