Skip to content

Instantly share code, notes, and snippets.

View neilmiddleton's full-sized avatar
🏠
Working from home

Neil Middleton neilmiddleton

🏠
Working from home
View GitHub Profile
require 'test_helper'
require 'admin/comments_controller'
class Admin::CommentsController; def rescue_iction(e) raise e end; end
class CommentControllerTest < ActionController::TestCase
should "get index" do
Factory(:comment)
Factory(:comment)
@neilmiddleton
neilmiddleton / deployments.rake
Created October 15, 2010 16:18
Integrates CodebaseHQ deployment notifications into Heroku-san
desc 'After_deploy callback'
task :before_deploy => :environment do |t, args|
username = `git config codebase.username`.chomp.strip
api_key = `git config codebase.apikey`.chomp.strip
if username == '' || api_key == ''
puts " * Codebase is not configured on your computer. Bundle the codebase gem and run 'codebase setup' to auto configure it."
puts " * Deployments will not be tracked."
next
@neilmiddleton
neilmiddleton / gist:703612
Created November 17, 2010 16:38
SQL Find and Replace
SET NOCOUNT ON
DECLARE @stringToFind VARCHAR(100)
DECLARE @stringToReplace VARCHAR(100)
DECLARE @schema sysname
DECLARE @table sysname
DECLARE @count INT
DECLARE @sqlCommand VARCHAR(8000)
DECLARE @where VARCHAR(8000)
DECLARE @columnName sysname
# Delete old prototype drivers
# Do this first so that you don't delete the new jQuery rails one below
inside('public/javascripts') do
FileUtils.rm_rf %w(controls.js dragdrop.js effects.js prototype.js rails.js)
end
# Download latest jQuery.min
get "http://code.jquery.com/jquery-latest.min.js", "public/javascripts/jquery.js"
# Download latest jQuery drivers
@neilmiddleton
neilmiddleton / HTML5BoilerPlateTemplate
Created February 1, 2011 16:08
HTML5 Boiler Plate Template
# Rails 3 simple template
# USE ONLY ON EMPTY APPS - USAGE:rails new app_name -m rails3-templates/base.rb
# Remove Default
run 'mv public/index.html public/test-rails3.html'
# Install JQuery
inside "public/javascripts" do
FileUtils.rm_rf %w(controls.js dragdrop.js effects.js prototype.js rails.js)
run "wget https://github.com/rails/jquery-ujs/raw/master/src/rails.js --no-check-certificate"
@neilmiddleton
neilmiddleton / Zippy
Created February 1, 2011 17:08
Zippy Application Template
# HTML 5 Boiler Plate
apply 'https://gist.github.com/806066.txt'
run "rm public/javascripts/jquery.js"
run "rm -rf public/build"
run "rm -rf public/demo"
run "rm -rf public/test"
# JQuery
apply 'https://gist.github.com/806025.txt'
@neilmiddleton
neilmiddleton / gist:966257
Created May 11, 2011 10:34
Create class from hash
def initialize(hash)
hash.each do |k,v|
self.instance_variable_set("@#{k.underscore}", v)
self.class.send(:define_method, k.underscore, proc{self.instance_variable_get("@#{k.underscore}")})
self.class.send(:define_method, "#{k.underscore}=", proc{|v| self.instance_variable_set("@#{k.underscore}", v)})
end
end
@neilmiddleton
neilmiddleton / gist:1053981
Created June 29, 2011 14:47
Failing RSpec test
AboutYou.any_instance.stub!(:save).and_return(false)
post :create
assigns[:about_you].should be_new_record
flash[:notice].should be_nil
response.should render_template('new')
def create
@about_you = current_user.build_about_you(params[:about_you])
@neilmiddleton
neilmiddleton / gist:1089985
Created July 18, 2011 16:16
jQuery validation helpers
jQuery.validator.addMethod "min_age", (value, element) ->
date = value.split '-'
dob = new Date date[0], date[1], date[2]
_today = new Date()
_18_years_ago = new Date _today.getYear() - 18, _today.getMonth(), _today.getDay()
return dob < _18_years_ago
, "You must be over 18 years of age to use Nutmeg"
jQuery.validator.addMethod "max_age", (value, element) ->
date = value.split '-'
@neilmiddleton
neilmiddleton / gist:1226307
Created September 19, 2011 11:10
Postgres min_messages
development:
adapter: postgresql
host: localhost
min_messages: warning
database: foo_development