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
@mattwhite
mattwhite / build-bash-lenny.sh
Last active August 29, 2015 14:06
Compile Bash 3.2 from source for Debian Lenny to patch the shellshock vulnerabilities (CVE-2014-6271, CVE-2014-7169, CVE-2014-6277, CVE-2014-6278, CVE-2014-7186, CVE-2014-7187)
# inspired by http://askubuntu.com/a/528171 and the comments below
# build bash 3.2, though this should work for other versions as well
BASH_MAJOR=3
BASH_MINOR=2
# prerequisites
sudo apt-get install build-essential gettext bison
# get bash source
# 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
@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
@Aryk
Aryk / gist:1024359
Created June 14, 2011 05:05
Nested has_many :through support
module NestedHasManyThrough
module Reflection # :nodoc:
def self.included(base)
base.send :alias_method_chain, :check_validity!, :nested_has_many_through
end
def check_validity_with_nested_has_many_through!
check_validity_without_nested_has_many_through!
rescue ActiveRecord::HasManyThroughSourceAssociationMacroError => e
# now we permit has many through to a :though source
@karmi
karmi / geo_distance_filter_in_tire.rb
Created June 28, 2011 14:13
Geo Distance Filter Support in Tire/ElasticSearch
require 'tire'
require 'active_support/core_ext/numeric'
require 'active_support/core_ext/time/zones'
# Tire.configure { logger STDERR, level: 'debug' }
class Time; DATE_FORMATS.update lucene: "%Y-%m-%dT%H:%M"; end
Tire.index 'venues' do
@karmi
karmi / tire_http_clients_benchmark.rb
Created September 8, 2011 18:15
Benchmark Tire gem with RestClient and Curb HTTP Clients
#
# A basic, synthetic benchmark of the impact HTTP client has
# on the speed of talking to ElasticSearch in the Tire gem.
#
# In general, Curb seems to be more then two times faster the RestClient, in some cases it's three
# to five times faster. I wonder if keep-alive has anything to do with it, but it probably does.
#
# Run me with:
# $ git clone git://github.com/karmi/tire.git
# $ cd tire