Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / connection_fix.rb
Created November 19, 2009 20:00
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/
named_scope :conditions, lambda { |args| {:conditions => args} }
named_scope :filter, lambda{ |options|
options ||= {}
options.stringify_keys!
scope = scoped(Hash.new)
unless options['active'].blank?
scope = scope.conditions :active => options['active']
end
[user]
name =
email =
[github]
user =
token =
[sendemail]
smtpuser =
smtpencryption = tls
smtpserver = smtp.gmail.com
@ddemaree
ddemaree / config.ru
Created April 9, 2011 14:49
Rackup file for Rails 2.3.x projects (very useful for getting legacy apps running on pow.cx)
# Rails.root/config.ru
require "config/environment"
use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new
@abriening
abriening / application_controller.rb
Created September 30, 2011 21:42
Add support for handling 405 Method Not Allowed & 501 Not Implemented
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
@jc00ke
jc00ke / capybara-helpers.rb
Created January 28, 2012 07:47
Capybara helpers
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s
page.driver.render path
Launchy.open path
end
Rails.application.config.generators do |g|
g.template_engine :haml
g.javascript_engine :js
g.integration_tool :cucumber
g.test_framework :test_unit, :fixture => false,
:views => true,
:fixture_replacement => :factory_girl
end
@abriening
abriening / Preferences.sublime-settings.json
Last active December 17, 2015 17:19
Sublime Text user preferences
{
"color_scheme": "Packages/Color Scheme - Default/SpaceCadet.tmTheme",
"default_line_ending": "unix",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"font_size": 15.0,
"highlight_column": true,
"highlight_line": true,
"highlight_modified_tabs": true,
"show_tab_close_buttons": false,