When using the Date
, Time
, and DateTime
classes in ruby you must use time zone sensitive methods. The database stores records without a timezone, in UTC. Rails parses these times to the configured timezone, when using time-zone sensitive methods.
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
# Override ActiveRecord#readonly? | |
def readonly? | |
my_locking_conditions? || super | |
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
class User < ActiveRecord::Base | |
has_many :contacts | |
end | |
class Contact < ActiveRecord::Base | |
end | |
class DomesticContact < Contact | |
validate :us_zip_format_validation | |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
# Credit: Ted Price, Lightning talk - 1-05-2017 | |
# `warn` | |
# Use to write to stderr | |
puts "Hello stdout!" | |
warn "Hello stderr!" | |
# ruby __FILE__ 1> stdout.txt 2> stderr.txt | |
#################################################################### |
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
let defaultParams = {}; | |
const INVALID_RESPONSE_TYPE = 'INVALID_RESPONSE_TYPE'; | |
// TODO(pwong): do we need this? | |
function encodeUriQuery(val) { | |
return encodeURIComponent(val). | |
replace(/%40/gi, '@'). | |
replace(/%3A/gi, ':'). | |
replace(/%24/g, '$'). |
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
# This allows us to set a different date | |
# in the admin area, and use TimeCop to process each | |
# request as being on that different date - useful for | |
# testing different phases of the challenge. | |
module TimeTravelFilters | |
extend ActiveSupport::Concern | |
included do | |
if Rails.env.development? || Rails.env.staging? | |
around_filter :time_travel_for_request |