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:
# troll your friends and enemies | |
class Fixnum | |
alias_method :add, :+ | |
def +(other); rand(10) == 0 ? self * other : self.add(other); end | |
end |
def readable secs | |
return "0 minute" if secs < 60 | |
secs /= 60 | |
[[60, :minute], [24, :hour], [Float::INFINITY, :day]].map{ |count, name| | |
if secs > 0 | |
secs, n = secs.divmod(count) | |
pluralize(n.to_i, name.to_s) if n > 0 | |
end | |
}.compact.reverse.join(' ') | |
end |
module Utilities | |
# A helper for JSON interaction. Treat the hashes recursively | |
module CamelSnakeHash | |
# camelize and stringify keys | |
def camelize_keys(value) | |
case value | |
when Array | |
value.map { |v| camelize_keys(v) } | |
when Hash | |
Hash[value.map { |k, v| [k.to_s.camelize(:upper), camelize_keys(v)] }] |
def to_bool(str) | |
str == true || str =~ (/^(true|1)$/) ? true : false | |
end |
module WorkerHelper | |
REDIS_EXPIRY_TIME = 20.minutes | |
def logger | |
unless @logger | |
@logger = Logger.new(STDOUT) | |
@logger.formatter = proc do |severity, datetime, _progname, msg| | |
"[#{severity}] #{datetime}: #{msg}\n" | |
end | |
end |
# Example for replace spec files modules: | |
module MyFirstModule | |
module MySecondModule | |
describe Something do | |
# code | |
end | |
end | |
end |
# 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 |
(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) | |
(-> |
I hereby claim:
To claim this, I am signing this object:
# 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 |