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
Rails::Rack::Logger.class_eval do | |
def started_request_message_with_no_ip(request) | |
'Started %s "%s" at %s' % [ | |
request.request_method, | |
request.filtered_path, | |
Time.now.to_default_s] | |
end | |
alias_method_chain :started_request_message, :no_ip | |
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 API | |
module Middleware | |
class AppReloader | |
class << self | |
def mtimes | |
@mtimes ||= {} | |
end | |
def files |
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
# config/lean_application.rb | |
# | |
# Require and run only a part of your Rails app (maybe as a background process) | |
# | |
require File.expand_path('../boot', __FILE__) | |
require 'active_record/railtie' | |
require 'action_mailer/railtie' |
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
s = $document[0].createElement('script') | |
s.type = 'text/javascript' | |
s.async = true | |
s.src = "https://widget.intercom.io/widget/#{chat_settings.app_id}" | |
tags = $document[0].getElementsByTagName('script') | |
x = tags[tags.length - 1] | |
x.parentNode.insertBefore(s, x) |
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
class DummyController | |
include Logging | |
protected | |
def log_file | |
'log_file_name' | |
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
USER_AGENT_ALIASES = ['Windows Mozilla', 'Mac Safari', 'Mac FireFox', 'Mac Mozilla', 'Linux Mozilla', 'Linux Firefox'] | |
agent = Mechanize.new do |mech| | |
mech.open_timeout = 10 | |
mech.read_timeout = 10 | |
mech.follow_meta_refresh = true | |
mech.keep_alive = true | |
mech.max_history = 1 | |
mech.user_agent_alias = USER_AGENT_ALIASES.sample | |
end | |
agent.set_proxy(proxy_ip, proxy_port, AppConfig.http_proxy.username, AppConfig.http_proxy.password) |
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
class Merchant | |
include Cequel::Record | |
key :user_id, :int | |
key :source, :text | |
key :source_id, :text | |
column :name, :text | |
# @example | |
# Merchant.by_key(user_id = 1, source = 'facebook', source_id = '4213578641d') |
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 HashieMashExtensions | |
# To play nice with ActiveSupport Array#extract_options! | |
def extractable_options? | |
true | |
end | |
end | |
Hashie::Mash.send(:include, HashieMashExtensions) |
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 +(other) | |
new_data = data.merge(other.data) do |_, val, other_val| | |
case val | |
when Array, Integer | |
val + other_val | |
when Hash | |
val.merge(other_val) { |__, val1, val2| val1 + val2 } | |
else | |
nil | |
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 ObjectTracker | |
def track(*args) | |
@__tracking ||= [] | |
args.each { |arg| @__tracking << arg unless tracking?(arg) } | |
end | |
def track!(*args) | |
track(*args) | |
start_tracking! | |
end |