Skip to content

Instantly share code, notes, and snippets.

View cjbottaro's full-sized avatar

Christopher J. Bottaro cjbottaro

  • AcademicWorks, Inc
  • Austin, Tx
View GitHub Profile
require 'rubygems'
require 'activesupport'
dt = DateTime.now
puts dt.utc.to_f
# => 1240456717.12572
puts dt.to_time.to_f
# => 1240456717.12572
puts dt.utc.to_time.to_f
# => 1240455680.0
puts dt.to_time.utc.to_f
if File.exists?("my_git_ignored_file.yml")
::AppConfig = ApplicationConfiguration.new("my_git_ignored_file.yml")
else
::AppConfig = ApplicationConfiguration.new("my_normal_config_file.yml")
end
AppConfig.use_environment!(RAILS_ENV)
# app_config.yml
# --------------
# development:
# env: dev
# server: dev.domain.com
# production:
# env: prod
# server: prod.domain.com
#
# local_override.yml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body></body>
</html>
class ApplicationController < ActionController::Base
param_accessible [:id, :page]
end
# This will filter any param except for :id and :page for ALL controllers in your entire application (because you're calling param_accessible on ApplicationController).
@cjbottaro
cjbottaro / gist:1128108
Created August 5, 2011 17:54
unDRY rspec code
describe Object do
context "extented with MyModule" do
before(:all){ subject.extend(MyModule) }
it "should define #some_method" do
subject.should respond_to(:some_method)
end
end
end
describe Class do
@cjbottaro
cjbottaro / gist:1128091
Created August 5, 2011 17:50
DRY'ed rspec using shared_context with a block
shared_context "for_extending" do
context "extended with MyModule" do
before(:all){ subject.extend(MyModule) }
it "should define #some_method" do
subject.should respond_to(:some_method)
end
yield
end
end
@cjbottaro
cjbottaro / gist:1152006
Created August 17, 2011 16:55
cron job
#!/bin/bash
RVM_BIN=/usr/local/rvm/bin/rvm
EDITOR_UI=/home/onespot/editor-ui/current
$RVM_BIN 1.9.2@editor-ui ruby $EDITOR_UI/bin/openx_report.rb -e production > $EDITOR_UI/log/openx_report.log 2>&1
@cjbottaro
cjbottaro / gist:1167520
Created August 24, 2011 07:56
sleep in EM reactor
EM.run do
t = Time.now
Fiber.new{ sleep(1) }.resume
Fiber.new{ sleep(1) }.resume
puts Time.now - t
# 2 seconds have elapsed. No concurrency is achieved.
EM.stop
end
@cjbottaro
cjbottaro / gist:1205075
Created September 8, 2011 23:20
class vs instance vars in CoffeeScript
class Blah
@counter = 0
@incr: ->
return @counter += 1
constructor:
@counter = 0