Skip to content

Instantly share code, notes, and snippets.

View jazzytomato's full-sized avatar
🎶
🎷 🍅

Tom Haratyk jazzytomato

🎶
🎷 🍅
View GitHub Profile
@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.
# 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 / 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",
# 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 / 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

Keybase proof

I hereby claim:

  • I am jazzytomato on github.
  • I am jazzytomato (https://keybase.io/jazzytomato) on keybase.
  • I have a public key ASAmqKM9EXyy5yLsm9tLpJEObivFIzwlxe1tq18KEFvLywo

To claim this, I am signing this object:

@jazzytomato
jazzytomato / spec_middleware.clj
Last active April 21, 2017 17:27
Ring middleware for parsing query params with clojure.spec
(defn wrap-query-params-spec [h]
"Try to parse query params with clojure spec. Look for a spec named like 'query-params/[uri]'
If found and the spec does not conform, return the explained message"
(fn [req]
(try
(let [query-spec-k (keyword (str "query-params" (:uri req)))
query-params (keywordize-keys (:query-params req))
conformed-query-params (s/conform query-spec-k query-params)]
(if (= :clojure.spec/invalid conformed-query-params)
(->
# Enumerable extensions
module Enumerable
# this will be able to handle a pool of workers (actors)
# can be useful to have a pool to limit the amount of concurrent work
class ParallelWorker
POOL_SIZE = ENV.fetch('CELLULOID_POOL_SIZE', [Celluloid.cores, 2].max).to_i
include Celluloid
def yielder(element, block)
block.call(element)
end
# Example for replace spec files modules:
module MyFirstModule
module MySecondModule
describe Something do
# code
end
end
end
@jazzytomato
jazzytomato / dettes.md
Created December 11, 2015 23:31
exo ruby

un systeme de calcul de dettes dans le terminal

les données sont persistées dans un ou des fichiers (json ou yaml).

exemple d'utilisation :

ruby dettes.rb
Login