Skip to content

Instantly share code, notes, and snippets.

View naveedkakal's full-sized avatar

Naveed Kakal naveedkakal

View GitHub Profile
@naveedkakal
naveedkakal / TimeZones.md
Created July 13, 2017 22:21
Time zone cheat sheet

Rails Date and Time

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.


Examples

# 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
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, '$').
@naveedkakal
naveedkakal / ruby-fun-2017-01-03.rb
Last active January 5, 2017 20:17 — forked from pricees/ruby-fun-2017-01-03.rb
2017-01-03 Lightning Talk
# 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
####################################################################
@naveedkakal
naveedkakal / 0_reuse_code.js
Created December 13, 2016 03:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
class User < ActiveRecord::Base
has_many :contacts
end
class Contact < ActiveRecord::Base
end
class DomesticContact < Contact
validate :us_zip_format_validation
# Override ActiveRecord#readonly?
def readonly?
my_locking_conditions? || super
end