Skip to content

Instantly share code, notes, and snippets.

MyExceptions = [RangeError, RegexpError, IOError].freeze
begin
raise IOError, "should be rescued"
rescue *MyExceptions => e
puts e
end
# Run annotate task after db:migrate
# and db:rollback tasks
Rake::Task['db:migrate'].enhance do
Rake::Task['annotate'].invoke
Rake::Task['db:test:prepare'].invoke
end
Rake::Task['db:rollback'].enhance do
Rake::Task['annotate'].invoke
Rake::Task['db:test:prepare'].invoke

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh root@123.123.123.123

Add ssh fingerprint and enter password provided in email

// To get this code to work, simply add a placeholder attribute to any of your inputs.
// This code requires no-conflict jQuery (var $j = jQuery.noConflict();) and Modernizr.
// Also you should add something similar to the following to your stylesheets.
//
// .placeholder{
// color: #666;
// }
jQuery.fn.set_placeholder = function() {
if ($j(this).attr('placeholder') && ($j(this).val() == '' || $j(this).val() == $j(this).attr('placeholder'))) {
@jondkinney
jondkinney / will_paginate_init.rb
Created April 19, 2010 20:15
Allows will_paginate to work with the row_number function for both normal pagination and when passed custom sql through the paginate_by_sql method
module ActiveRecord
module Associations
module ClassMethods
def construct_finder_sql_for_association_limiting(options, join_dependency)
scope = scope(:find)
# Only join tables referenced in order or conditions since this is particularly slow on the pre-query.
tables_from_conditions = conditions_tables(options)
tables_from_order = order_tables(options)
all_tables = tables_from_conditions + tables_from_order
#NOTE: jonk (04/14/2010) => monkey patching will_paginate for when paginate_by_sql is specified
require 'will_paginate/core_ext'
module WillPaginate
module Finder
module ClassMethods
def find_table_primary_key_columns(table_name)
@find_table_primary_key_columns_cache ||= {}
if @find_table_primary_key_columns_cache[table_name].nil?
table_name = table_name.split('.').last.delete("[]")
After do |scenario|
if scenario.status == :failed
save_and_open_page
end
end
module Webrat
module SaveAndOpenPage
def save_and_open_page
return unless File.exist?(Webrat.configuration.saved_pages_dir)
@jondkinney
jondkinney / presonus_uc_cleanup
Created February 16, 2011 04:20
Delete PreSonus UC Files on OS X 10.5 and 10.6
on run {input, parameters}
-- Setup the list of the main files to be deleted
set searchList to {¬
POSIX file ("/Applications/Universal Control.app") as text, ¬
POSIX file ("/Applications/FireStudio Control Console.app") as text, ¬
POSIX file ("/Applications/FireControl.app") as text, ¬
POSIX file ("/Applications/FireStudio Lightpipe Mixer.app") as text, ¬
POSIX file ("/Applications/StudioLive.app") as text, ¬
POSIX file ("/Library/Application Support/PaeFireStudio") as text, ¬
@jondkinney
jondkinney / gist:828864
Created February 16, 2011 04:22
PreSonus UC Cleanup
on run {input, parameters}
-- Setup the list of the main files to be deleted
set searchList to {¬
POSIX file ("/Applications/Universal Control.app") as text, ¬
POSIX file ("/Applications/FireStudio Control Console.app") as text, ¬
POSIX file ("/Applications/FireControl.app") as text, ¬
POSIX file ("/Applications/FireStudio Lightpipe Mixer.app") as text, ¬
POSIX file ("/Applications/StudioLive.app") as text, ¬
POSIX file ("/Library/Application Support/PaeFireStudio") as text, ¬
@jondkinney
jondkinney / setup_textmate_rails_dev.md
Created June 16, 2011 08:16
Setup Textmate for Rails Dev on OS X

##Setup Textmate for Rails Dev on OS X

This guide was written by Jon Kinney for the Green Bay Ruby User Group. Jon works at Intridea and they graciously sponsor the Green Bay RUG meetings.

These guides were also partially completed using time from Intridea's SparkTime initiative which aims to give employees "outside projects" to work on during their normal work week.

If you find any issues with these suggestions please let me know. I've amassed these tips/tricks over several years of full time Rails development using Textmate but just because it works on my system doesn't always mean it will be problem free universally. Thanks to all the blog authors whose articles helped me learn Textmate over the years but whose links/posts I've lost or forgotten over time. If you have a cool Textmate tip or trick please post it in the comments!