Skip to content

Instantly share code, notes, and snippets.

View davelyon's full-sized avatar

Dave Lyon davelyon

View GitHub Profile
Given "a user" do
@user = User.new
end
When "I activate that user" do
@user.avtivate!
end
# 10 other steps that all depend on/change "@user"
@davelyon
davelyon / statefulton_sample.rb
Created February 3, 2012 19:47
Statefulton Example
Statefulton(:user) do
builder { User.new }
make "a"
expects "that" # Calling "that" will return the singular instance
end
# Given a user
# When I activate that user
@davelyon
davelyon / silece_assets.rb
Created November 16, 2011 21:48
Silence Asset Logging in Development
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def before_dispatch_with_quiet_assets(env)
before_dispatch_without_quiet_assets(env) unless env['PATH_INFO'].index("/assets/") == 0
end
alias_method_chain :before_dispatch, :quiet_assets
end
end
@davelyon
davelyon / Guardfile
Created June 21, 2011 18:39
Guardfile
require 'guard/rspec'
extensions = ["Guard::RSpec", "Guard::Schema", "Guard::Routes"]
module ::Guard
class Schema < ::Guard::Guard
def run_on_change(_)
UI.info "Clearing the way"
`rake db:test:prepare`
UI.clear
UI.info "Ready to lead the charge!"
@davelyon
davelyon / cors.rb
Created May 23, 2011 13:21
Cross-Origin Resource Sharing on Rails
def cross_site_sharing
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = 'POST, OPTIONS'
headers['Access-Control-Allow-Headers'] = 'X-Requested-With'
headers['Access-Control-Max-Age'] = '1278000'
headers['Content-Length'] = '0'
headers['Content-Type'] = 'text/plain'
render nothing: true, status: 200
end
@davelyon
davelyon / euler.rb
Created February 23, 2011 02:38
Project Euler Fun for ACM Meeting
# 1
(0..1000).reject {|x| not (x%3 == 0 or x%5 == 0) }.inject(:+)
@davelyon
davelyon / acmuug.email
Created January 26, 2011 15:21
ACM/UUG Email
Student Computer Science Organizations have new days, times
The NMU Association for Computing Machinery (ACM), which previously met Fridays at 5pm will now be meeting Thursdays at 5pm in order to make meetings more convenient for students to attend. If you are unfamiliar with this organization, ACM is a campus organization that explores a wide range of Computer Science related topics, and focuses on student run presentations and discussions. Previous topics have included overviews of the Ruby and Python programming languages, test driven development, iPhone programming, and game development. For more information, contact the ACM President Dave Lyon (dlyon@nmu.edu).
This weeks ACM meeting: Wireshark and Network Discovery (Darren StAmour), Mike Campfield discusses his internship (3D/Game Design)
// Todo: UUG Bits Here
@davelyon
davelyon / itunes_xml_parse.rb
Created November 19, 2010 04:33
Parse an itunes XML file to something html-ish
require 'rubygems'
require 'plist'
r = Plist::parse_xml("/Users/dave/Desktop/ItunesLibrary.xml")
lib = Hash.new()
r["Tracks"].each do |track|
album = track[1]["Album"]
cp $2 "$1/$2"
cd $1
# Run with . ./test.sh $DIR_TO_CP_TO $FILE
var fortunes=new Array(" One learns to itch where one can scratch. -- Ernest Bramah "," One meets his destiny often on the road he takes to avoid it. "," One monk said to the other, \"The fish has flopped out of the net! How will it live?\" The other said, \"When you have gotten out of the net, I'll tell you.\" "," Only that in you which is me can hear what I'm saying. -- Baba Ram Dass "," Only those who leisurely approach that which the masses are busy about can be busy about that which the masses take leisurely. -- Lao Tsu "," Paradise is exactly like where you are right now ... only much, much better. -- Laurie Anderson "," Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away. -- Antoine de Saint-Exupery "," Perhaps the biggest disappointments were the ones you expected anyway. "," Philosophy will clip an angel's wings. -- John Keats "," Push where it gives and scratch where it itches. "," Reality always seems harsher in the early morning. ",