Skip to content

Instantly share code, notes, and snippets.

View cwsaylor's full-sized avatar

Chris Saylor cwsaylor

View GitHub Profile
# To Audit Foo model, create a model called Foo::BarLog with a foreign key of bar_id and include this concern
module Auditable
extend ActiveSupport::Concern
included do
after_save :audit
has_many :audits, class_name: "#{self}Log"
end
# To audit Foo model, create a model called FooLog and include this concern
module Auditable
extend ActiveSupport::Concern
included do
after_save :audit
end
module InstanceMethods
Assignments for 9-7-12 (as of Sep 6 17:20 2012 eastern time)
Field 1 - 3: Staff name, unique ID, backup ID
Field 4 - 6: Assignment name (in quotes), unique ID, backup ID
Field 7 - 8: Date and time of assignment (GMTO=-5 1)
Field 9 -14: Staff type, Pager, Tel, Email, Messagable, Shift note
"Mars Rover",249,2,"Call",251,7,9-7-12,0715,1900,"MD","2244","","[email protected]",1,""
"Venus Moon",257,4,"Backup",252,8,9-7-12,1900,0700,"ML","9999","","[email protected]",1,""
"Doximity Tester",353,20,"Phones",332,9,9-7-12,0745,1800,"Dox","[email protected]","","[email protected]",1,""
#[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
eval "$(rbenv init -)"
alias json='python -mjson.tool | pygmentize -f terminal256 -l javascript -O style=native'
export NODE_PATH=/usr/local/lib/node_modules
[28] pry(main)> ::ActiveSupport::TimeZone[-5].name
=> "America/New_York"
[29] pry(main)> Time.now.in_time_zone("America/New_York")
=> Mon, 23 Jul 2012 14:19:39 EDT -04:00
[30] pry(main)> Time.now.in_time_zone(-5)
=> Mon, 23 Jul 2012 14:22:37 EDT -04:00
-if @item.errors.any?
#error_explanation
%h2= "#{pluralize(@item.errors.count, "error")} prohibited this item from being saved:"
%ul
- @item.errors.full_messages.each do |msg|
%li= msg
@cwsaylor
cwsaylor / hundred_percent_input.css
Created January 28, 2012 01:59
Fix 100% form elements
/* http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-encourage-responsive-form-elements-to-play-nice/ */
input[type='text'],
textarea {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
@cwsaylor
cwsaylor / controller.rb
Created January 17, 2012 00:41
Prevent page caching
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
@cwsaylor
cwsaylor / development.rb
Created August 3, 2011 18:12
Log sql queries to console in Rails 3.0
ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console
@cwsaylor
cwsaylor / lightbulb.rb
Created May 20, 2011 18:11
lightbulb.rb
#!/usr/bin/env ruby
def toggle(i)
i == 0 ? 1 :0
end
# turn on every bulb
bulbs = Array.new 100, 1
# Turn off every x bulb