This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory.define :application do |factory| | |
factory.attachment :sample, "public/samples/sample.doc", "application/msword" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
OlderNewer