Skip to content

Instantly share code, notes, and snippets.

View woods's full-sized avatar

Scott Woods woods

View GitHub Profile
@woods
woods / gist:5642596
Created May 24, 2013 10:21
Load just the models and lib of a Rails project. This can be useful for model/component/service specs that depend on ActiveRecord, but no other part of Rails. Running the tests in this fashion helps to make sure you don't introduce any other Rails dependencies into your code, and it helps those tests to load a few seconds faster since we're not …
require 'bundler/setup'
require 'active_support'
require 'active_support/dependencies'
ActiveSupport::Dependencies.autoload_paths += %w{ app/models lib }
require 'active_record'
db_config = YAML.load_file('config/database.yml')
ActiveRecord::Base.establish_connection(db_config['test'])
@woods
woods / gist:5637140
Created May 23, 2013 15:57
#centregives twitter mentions as of 5/23 @ 11:55am. Does not include mentions from users who have had more than 50 #centregives tweets.
screen_name | full_name | number_of_tweets
-----------------+----------------------+------------------
TheStateTheatre | The State Theatre | 1468
discoveryspace | Discovery Space | 1463
CentreCoPAWS | Centre County PAWS | 618
CentreFNDN | Centre Foundation | 292
ccwrcedteam | CCWRC | 250
AllaynB | Allayn Beck | 157
TheHouseofCare | The House of Care | 156
olliatpsu | OLLI at Penn State | 147
@woods
woods / 1_routing_spec.rb
Last active December 16, 2015 11:19
This is the most succinct style I can come up with for writing routing specs.
require 'component/component_spec_helper'
describe "Routing", type: :routing do
describe "for the home page" do
specify {{ get: '/' }.should route_to('lists#index') }
end
describe "for authentication" do
specify {{ get: '/auth/new' }.should route_to('sessions#new') }
specify {{ get: '/auth/37signals/callback' }.should route_to('sessions#create', provider: '37signals') }
specify {{ get: '/auth/failure' }.should route_to('sessions#failure') }
@woods
woods / clean_up_old_releases.rb
Created December 5, 2012 19:01
The script that we use to clean up old capistrano releases
#!/opt/ruby/bin/ruby
# This script will clean out old capistrano releases from a set of
# subdirectories, but will keep a minimum number. It's designed to be run as
# a cron job.
#
# (c) Copyright 2008 West Arete Computing, Inc.
require 'thread'
require 'fileutils'
@woods
woods / .prompt.bash
Created August 25, 2012 16:25
My custom bash prompt
#!/bin/bash
#
# Scott Woods's custom bash prompt.
#
# Load this file by adding the following to the bottom of your ~/.bashrc:
#
# function prompt_command {
# export PS1=$(~/.prompt.bash)
# }
# export PROMPT_COMMAND='export LAST_RETURN_VALUE=$? ; prompt_command'
@woods
woods / enable_trim.sh
Created August 12, 2012 20:19
Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion.
#!/bin/bash
#
# Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion
#
# Source: http://digitaldj.net/2011/07/21/trim-enabler-for-lion/
set -e
set -x
# Back up the file we're patching
@woods
woods / example.rb
Created May 8, 2012 03:05
How to dynamically query enum values from Postgresql in Rails
sql = %{
select enumlabel
from pg_enum
where enumtypid = 'company_status'::regtype
order by oid
}
result = ActiveRecord::Base.connection.execute(sql)
result.each do |row|
@woods
woods / existing_ruby_class.rb
Created March 6, 2012 21:43
Read existing Ruby source files into their own namespace after the fact
class A
@counter = 0
def self.inc
@counter += 1
end
end
@woods
woods / bootstrap_chef_server.sh
Created December 17, 2011 13:33
Set up rackspace cloud server as chef server
#!/bin/bash
set -e # Exit on error
set -x # Print each command
# Set up the OpsCode repository
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
gpg --export packages@opscode.com | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg
apt-get update