Skip to content

Instantly share code, notes, and snippets.

View woods's full-sized avatar

Scott Woods woods

View GitHub Profile
@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 / 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 / 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 / helper.rb
Created May 30, 2013 03:16
Helpers for embedding or displaying links to a Google map
module GoogleMapsHelper
# Returns a URL to use in an iframe for embedding a Google map
# Reference: http://asnsblues.blogspot.com/2011/11/google-maps-query-string-parameters.html
def google_maps_embed_url(address)
"#{google_maps_url(address)}&output=embed"
end
# Returns a URL to use for linking to a Google map
# Reference: http://asnsblues.blogspot.com/2011/11/google-maps-query-string-parameters.html
<div id="social-media-icons">
<a href="Facebook.com/runthenightltd" target="_blank"><img src="http://niftyweb.cdbaby.netdna-cdn.com/rkc-social-set-1/facebook.png" align="left" border="0"></a><a href="Twitter.com/runthenightltd" target="_blank"><img src="http://niftyweb.cdbaby.netdna-cdn.com/rkc-social-set-1/twitter.png" border="0" align="left"></a><a href="YouTube.com/runthenighttv" target="_blank"><img src="http://niftyweb.cdbaby.netdna-cdn.com/rkc-social-set-1/youtube.png" border="0" align="left"></a>
<br>
</div>
@woods
woods / git_aliases.sh
Created August 5, 2013 15:15
West Arete's git / bash setup.
# git aliases. Add new ones to the bottom of ~/.git-completion.bash to enable
# autocomplete.
alias ga='git add'
alias gap='git add -p'
alias gau='git add -u'
alias gb='git branch'
alias gc='git commit -v'
alias gca='git commit -a -v'
alias gco='git checkout'
alias gd='git diff'
@woods
woods / en.yml
Created August 5, 2013 20:29
An example of how to specify attribute-to-English mappings for custom objects to pass to form_for. This file shows the mapping for a "payment" object. Note that it does not have to be an ActiveRecord.
en:
helpers:
label:
payment:
first_name: First Name
last_name: Last Name
email: Email
company: Company
card_number: Credit Card Number
card_expiration_date: Expiration Date
@woods
woods / gist:6258842
Created August 17, 2013 21:48
Ruby exception hierarchy
Exception
NoMemoryError
ScriptError
LoadError
NotImplementedError
SyntaxError
SignalException
Interrupt
StandardError
ArgumentError
@woods
woods / clean_up_old_releases.rb
Last active December 21, 2015 14:58
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.
#!/usr/bin/env 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 'date'
require 'fileutils'
@woods
woods / update_ip_address.sh
Created August 26, 2013 15:41
Example script to set a dynamic record in DNSimple based on the current cable modem address. This can be run in /etc/cron.hourly.
#!/bin/bash
#
# Since paig is on a dynamic IP address cable modem, we use this script to
# periodically update DNS with the current record. In this case, we're using
# the hostname paig.2surfers.com.
#
# Keep the contents of this file secret, since it contains the domain's API
# key. The ID of the record to be updated by hovering over it in DNSimple's
# web interface.