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 PostsController < ActionController::Base | |
| def create | |
| Post.create(post_params) | |
| end | |
| def update | |
| Post.find(params[:id]).update_attributes!(post_params) | |
| end | |
| private |
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
| 3.years.ago.send([:+, :-].sample, rand(100).days) |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"></script> | |
| <style type="text/css"> | |
| body { | |
| background: #000; | |
| } |
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 Hackery < Arel::Visitors::ToSql | |
| def quack(o) | |
| "WHERE #{o.wheres.map { |x| visit x, nil }.join ' OR ' }" | |
| end | |
| end | |
| hack = Hackery.new(ActiveRecord::Base.connection) | |
| condition1 = {:social_network_type => "facebook", :social_network_id => "555555"} | |
| condition2 = {:social_network_type => "linkedin", :social_network_id => "555555"} | |
| hack.quack(SocialUser.where(condition1).where(condition2)) |
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 |
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 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
| 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
| 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 DummyController | |
| include Logging | |
| protected | |
| def log_file | |
| 'log_file_name' | |
| end | |
| end |
OlderNewer