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 ExceptionNotifier | |
| def call(env) | |
| @app.call(env) | |
| rescue Exception => exception | |
| options = (env['exception_notifier.options'] ||= {}) | |
| options.reverse_merge!(@options) | |
| unless Array.wrap(options[:ignore_exceptions]).include?(exception.class) or /invalid byte sequence/ =~ exception.message | |
| Notifier.exception_notification(env, exception).deliver | |
| env['exception_notifier.delivered'] = true |
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
| ## Option A | |
| scope "search", :controller => :search do | |
| root :to => 'search#index', :as => 'search' | |
| get :users, :as => "search_users" | |
| get :photos, :as => "search_photos" | |
| end | |
| ## Option B | |
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
| cls = controller_name.classify.constantize | |
| paramtest = cls.new | |
| paramtest.attributes.map{|name,val| paramtest[name] = name } | |
| to_param = paramtest.to_param | |
| @object = cls.send("find_by_#{to_param}", params[:id]) |
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
| <?php | |
| ... | |
| //// Starting @ line 635 of FBAOutboundServiceMWS/Client.php | |
| list($other, $responseBody) = explode("\r\n\r\n", $response, 2); | |
| $other = preg_split("/\r\n|\n|\r/", $other); | |
| list($protocol, $code, $text) = explode(' ', trim(array_shift($other)), 3); | |
| // Re-check for new header after continue header. |
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
| arels = [Vote, Comment, Love].collect{|u| | |
| t = u.arel_table | |
| u.select([ | |
| t[:created_at].maximum.as("ts"), | |
| t[:photo_id].as("what_id"), | |
| "'Photo' AS what_type" | |
| ]).group(t[:photo_id]).arel | |
| } | |
| union = Arel::Nodes::Union.new(arels[0], arels[1]) |
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
| SELECT photos.id FROM photos | |
| LEFT OUTER JOIN votes ON votes.photo_id = photos.id | |
| LEFT OUTER JOIN flags ON flags.photo_id = photos.id AND flags.type="Love" | |
| LEFT OUTER JOIN comments ON comments.photo_id = photos.id | |
| WHERE photos.user_id = 38218 | |
| GROUP BY photos.id; |
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 Challenge < ActiveRecord::Base | |
| has_many :challenge_photos, :dependent=>:destroy | |
| has_many :photos, :through=>:challenge_photo | |
| 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
| validate :group_is_real | |
| def group_is_real | |
| errors.add(:group, "must be an already existing group") if group_id and !group | |
| 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
| root :to => 'application#index', :as => :home | |
| root :to => 'application#index', :as => :new_user, :via=>:get, :defaults=>{:anchor=>"signup"} | |
| root :to => 'application#index', :as => :login_users, :via=>:get |
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
| TIMESTAMPDIFF(HOUR, '2012-08-30 22:13:31', "2012-12-19 19:04:37") -- Gives me 2660 | |
| time_to_sec(timediff("2012-12-19 19:04:37", '2012-08-30 22:13:31'))/3600 -- Gives me 838.9997 |