Skip to content

Instantly share code, notes, and snippets.

View Circuit8's full-sized avatar

Joshua Harris Circuit8

View GitHub Profile
@jpowers
jpowers / gist:5731878
Last active August 1, 2017 20:29
Ruby Hash with range key
class RangedHash
def initialize(hash)
@ranges = hash
end
def [](key)
@ranges.each do |range, value|
return value if range.include?(key)
end
end
@kinopyo
kinopyo / custom_logger.rb
Created October 11, 2011 15:40
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere