Skip to content

Instantly share code, notes, and snippets.

@lawrencepit
lawrencepit / connection_fix.rb
Created January 15, 2012 22:42 — forked from mauricioszabo/connection_fix.rb
MySQL server has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@lawrencepit
lawrencepit / frogger.rb
Created July 13, 2011 06:19 — forked from dougo-chris/frogger.rb
Frogger for rspec
####################################################
# this file belongs in the ./spec/support directory
####################################################
require 'rspec/core/formatters/base_formatter'
class RSpec::Frogger < RSpec::Core::Formatters::BaseFormatter
COLOR_START = "\e[34m" # blue
COLOR_FAILED = "\e[31m" # red
COLOR_PASSED = "\e[32m" # green
# Chuck this in config/initializers for view-first validations
ActionView::Base.default_form_builder.class_eval do
def error(field)
errors(field).first
end
def errors(field)
object.errors.for(field)
end
end
##
# Calendar helper with proper events
# http://www.cuppadev.co.uk/webdev/making-a-real-calendar-in-rails/
#
# (C) 2009 James S Urquhart (jamesu at gmail dot com)
# Derived from calendar_helper
# (C) Jeremy Voorhis, Geoffrey Grosenbach, Jarkko Laine, Tom Armitage, Bryan Larsen
# Licensed under MIT. http://www.opensource.org/licenses/mit-license.php
##
# Consider:
def parse(*options)
if options[0].is_a?(Symbol)
if options[0] == :foo
"foo!"
elsif options[0] == :bar
"bar!"
elsif options[0] == :force
if options[1] == "foo"