This file contains 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
dc = Arel::Nodes::NamedFunction.new "DATE", [ p[:created_at] ] ## second argument must be an array | |
## Sub this... | |
arel.project("DATE(`photos`.`created_at`)") | |
## For this... | |
arel.project(dc.to_sql) | |
arel.to_sql >> "SELECT DATE(`photos`.`created_at`) FROM `photos` INNER JOIN `votes` ON `photos`.`id` = `votes`.`photo_id`" |
This file contains 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 ZohoOrder | |
include ActiveModel::Model | |
include ActiveModel::Validations::Callbacks | |
ZohoFields = [ | |
'ID', | |
'Added_Time' | |
] | |
def self.converted_zoho_attributes |
This file contains 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 Spam | |
require 'zendesk_api' | |
def self.client | |
@client ||= ZendeskAPI::Client.new do |config| | |
config.url = "https://pediment.zendesk.com/api/v2" # e.g. https://mydesk.zendesk.com/api/v2 | |
config.username = "admin@pediment.com" | |
config.password = "pedb00ks" | |
config.retry = true | |
end |
This file contains 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
{ | |
"height":2448, | |
"width":3264, | |
"md5":"8c6e38213c009aa62ccbfed210db7189", | |
"exif":{ | |
"EXIF ApertureValue":"None", | |
"Image ExifOffset":"204", | |
"EXIF ComponentsConfiguration":"YCbCr", | |
"GPS GPSLatitudeRef":"N", | |
"GPS GPSAltitudeRef":"0", |
This file contains 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 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 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 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 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 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; |
NewerOlder