This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_bool(str) | |
str == true || str =~ (/^(true|1)$/) ? true : false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# troll your friends and enemies | |
class Fixnum | |
alias_method :add, :+ | |
def +(other); rand(10) == 0 ? self * other : self.add(other); end | |
end |
NewerOlder