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/
@tcocca
tcocca / missing_spec_generator.rb
Created August 19, 2010 12:44
A library to generate missing rspec spec files for a rails project (just drop in lib)
require 'erb'
class MissingSpecGenerator
def spec_file(spec_path, file_name, spec_template, namespace)
spec_name = file_name.gsub('.rb', '') + '_spec.rb'
if File.exist?("#{spec_path}/#{spec_name}")
puts "#{spec_path}/#{spec_name} exists"
else
puts "#{spec_path}/#{spec_name} missing"
require 'open-uri'
require 'digest/md5'
# Get your external IP address from IP Chicken to send to the Quova service request URL below
ip_address = (open("http://ipchicken.com") {|f|f.read.scan(/([0-9]{1,3}\.){3}[0-9]{1,3}/);$~})
# Your API credentials from http://developer.quova.com/apps/mykeys
API_KEY = 'yougottagetyourownforthispartrighthere'
SHARED_SECRET = 'yespleasegetyourown'
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@mikhailov
mikhailov / ruby_gc.sh
Created March 11, 2011 10:33
Ruby’s GC Configuration
- http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/
- http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_HEAP_SLOTS_INCREMENT=100000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
@shedd
shedd / schedule.rb
Created May 7, 2011 15:03
Lockrun support for Whenever cron jobs
# Support running Whenever cron jobs with Lockrun
# Lockrun: http://www.unixwiz.net/tools/lockrun.html
# lockrun typically installed at /usr/bin/lockrun
# On Mac, install with: brew install lockrun
# Lockrun prefix for cronjobs: /usr/bin/lockrun --lockfile=/path/to/tmp/JOBNAME.lockrun -- sh -c "COMMAND"
def wrap_with_lockrun command
"/usr/bin/env lockrun --lockfile=:path/tmp/:lockfile.lockrun -- sh -c \"#{ command }\""
end
#redefine the three default job types to use Lockrun (i.e. just add 'lockrun_' in front of the existing job names)
@drnic
drnic / freeze_gem_cli
Created May 12, 2011 15:10
Installs a gem in a specific RVM ruby/gemset, and creates wrapper script to always use that specific ruby/gemset.
#!/usr/bin/env ruby
# Installs a gem in a specific RVM ruby/gemset, and helps you create
# an alias to a CLI/bin script to always use that gemset.
# Wonderfully useful for utility scripts (engineyard's ey or github-gem's gh)
#
# USAGE:
# freeze_gem_cli engineyard ey
# freeze_gem_cli github gh ruby-1.8.7p334
#
@shedd
shedd / assets.rake
Created June 20, 2011 18:05
Check asset encoding for valid UTF-8
namespace :assets do
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")
@shedd
shedd / gist:1162432
Created August 22, 2011 13:56
Wrap New Relic Instrumentation around Hoptoad Rake wrapper
# Add New Relic instrumentation
# ** define this before the lib/tasks are included
def task_with_new_relic_and_hoptoad(options)
caller_method = options.keys.first
task(options) do
require 'newrelic_rpm'
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
NewRelic::Agent.manual_start
@jackkinsella
jackkinsella / autoclose_janus
Created September 4, 2011 18:48
How to add autoclose to Janus
#~/.janus.rake file
vim_plugin_task "autoclose", "git://github.com/Townk/vim-autoclose.git"
#~/vimrc.local file
let g:AutoClosePairs = {'(': ')', '{': '}', '[': ']', '"': '"', "'": "'", '#{': '}', '|':'|' }
let g:AutoCloseProtectedRegions = ["Character"]