Skip to content

Instantly share code, notes, and snippets.

View tcocca's full-sized avatar

Tom Cocca tcocca

  • Boston Logic Technology Partners, Inc.
  • Boston, MA
View GitHub Profile
@njvitto
njvitto / deploy.rake
Created April 11, 2010 16:56 — forked from RSpace/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
# some experimentation around generating OG, IBU, & SRM for based on beer ingredients
grains = [{:name => 'Liquid Malt Extract', :amount => 6, :measurement => 'lbs', :efficency => 1, :ppg => 36, :color => 4},
{:name => 'Crystal Malt 60L', :amount => 1, :measurement => 'lbs', :efficency => 0.85, :ppg => 34, :color => 60}]
hops = [{:name => 'Fuggles', :amount => 2, :measurement => 'oz', :aau => 3.6, :time => 30},
{:name => 'Willamette', :amount => 1, :measurement => 'oz', :aau => 4.3, :time => 10}]
total_size = 5
boil_size = 3
@ctrochalakis
ctrochalakis / exception_notify_helper.rb
Created August 26, 2010 09:31
Using exception_notifier for rake tasks or scripts
# Exception notifier (rails3) only works as a rack middleware,
# but what if you need notifications inside a rake task or a script?
# This is a quick hack around that.
#
# Wrap your code inside an exception_notify block and you will be notified of exceptions
#
# exception_notify { clear_payments }
def exception_notify
yield
rescue Exception => exception
@barinek
barinek / Fast user switching with Devise
Created August 27, 2010 14:46
Fast user switching with Devise
Ever wondered how to login as another user within Devise?
Recently we had a feature request that would provide Admins with the ability
to sign is as another user. You could imagine live demonstrations or even production
support calls where you would like to be signed in as another user, yet not
have to ask for or decrypt their current password. After stewing for a bit, we found a
pretty nice solution with Devise.
Here's the Cucumber feature...
@sukima
sukima / calendar_controller_test.rb
Created October 6, 2010 15:27
Possible custom shoulda matcher
require 'test_helper'
class CalendarControllerTest < ActionController::TestCase
should route(:get, "/calendar").to(:action => :index)
should route(:get, "/calendar/events").to(:action => :events)
# Error:
# functional/calendar_controller_test.rb:9: undefined local variable or
# method `require_logged_in' for CalendarControllerTest:Class (NameError)
should require_logged_in
should require_logged_in.for(:events)
@cblunt
cblunt / factories.rb
Created October 15, 2010 14:01 — forked from technicalpickles/factories.rb
Simulate paperclip attachments with FactoryGirl in Rails 3
Factory.define :application do |factory|
factory.attachment :sample, "public/samples/sample.doc", "application/msword"
end
@HenrikJoreteg
HenrikJoreteg / JS Util solution using underscore.js
Created October 22, 2010 21:20
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&amp;')
.replace(/>/g,'&gt;')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@BinaryMuse
BinaryMuse / gist_tag.rb
Created January 31, 2011 00:44
A Liquid tag for Jekyll sites that allows embedding Gists and showing code for non-JavaScript enabled browsers and readers.
require 'cgi'
require 'digest/md5'
require 'net/https'
require 'uri'
module Jekyll
class GistTag < Liquid::Tag
def initialize(tag_name, text, token)
super
@text = text
@technicalpickles
technicalpickles / gist:839919
Created February 23, 2011 02:58
Rails 3 Application Template for making RVM, RVM gemsets, Passenger, and ruby-debug play nice-nice
file "config/setup_load_paths.rb", <<FILE
# based on http://blog.ninjahideout.com/posts/the-path-to-better-rvm-and-passenger-integration
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError