Skip to content

Instantly share code, notes, and snippets.

View jordanmaguire's full-sized avatar

Jordan Maguire jordanmaguire

  • Perth
View GitHub Profile
@jordanmaguire
jordanmaguire / stub_env.rb
Created June 10, 2011 05:43
Function for stubbing out the Rails.env calls
def stub_env(new_env, &block)
original_env = Rails.env
Rails.instance_variable_set("@_env", ActiveSupport::StringInquirer.new(new_env))
block.call
ensure
Rails.instance_variable_set("@_env", ActiveSupport::StringInquirer.new(original_env))
end
@jordanmaguire
jordanmaguire / rails_env.rb
Created June 10, 2011 05:44
The Rails.env function
def env
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end
@jordanmaguire
jordanmaguire / stub_env_spec.rb
Created June 10, 2011 05:45
A spec demonstrating how stub_env works
it "passes" do
stub_env "development" do
Rails.env.should be_development
end
Rails.env.should be_test
end
@jordanmaguire
jordanmaguire / recursive_delete.sh
Created September 22, 2011 14:26
Find and Delete
#!/bin/bash
find . -name "*.wma*" -delete
@jordanmaguire
jordanmaguire / cleanup.sh
Created September 26, 2011 01:04
Removes unnecessary files from music collection
#!/bin/bash
find . -name "*.nfo" -delete
find . -name "*.sfv" -delete
find . -name "*.m3u" -delete
find . -name "*.html" -delete
find . -name "*.md5" -delete
find . -name "*.pls" -delete
@jordanmaguire
jordanmaguire / my_rename.sh
Created September 26, 2011 03:42
Recursively rename a bunch of files
#!/bin/bash
IFS=$'\n'
for FILE in `find . -name "*.wma.MP3" -type f`
do
mv $FILE `echo $FILE | sed s/.wma.MP3/.mp3/g`
done
@jordanmaguire
jordanmaguire / marks_challenge.sh
Created September 29, 2011 12:23
Mark's bash challenge
#!/bin/bash
echo -e "second\nthird\nfourth" > something.txt
echo -e "something.txt\n-------------"
cat something.txt
echo -e "first" | cat - something.txt > tmp && mv tmp something.txt
echo -e "\nsomething.txt\n-------------"
cat something.txt
@jordanmaguire
jordanmaguire / marks_challenge_2.sh
Created September 29, 2011 12:58
Marks Challenge 2
#!/bin/bash
echo -e "second\nthird\nfourth" > something.txt
echo -e "something.txt\n-------------"
cat something.txt
printf '%s\n' 0a "first" . w | ed -s something.txt
echo -e "\nsomething.txt\n-------------"
cat something.txt
@jordanmaguire
jordanmaguire / rspec_generators.rb
Created January 16, 2012 14:06
rspec generators
# Use the rspec generators
config.generators do |g|
g.view_specs false
g.helper_specs false
g.test_framework :rspec
end
@jordanmaguire
jordanmaguire / rspec_attributes.rb
Created June 26, 2012 01:29
This is a helpful RSpec pattern I've been playing with lately with great success
let(:vehicle) { FactoryGirl.create(:vehicle, vehicle_attributes) }
let(:vehicle_attributes) { {} }
describe "#to_s"
subject { vehicle.to_s }
let(:vehicle_attributes) { {name: "Carzilla"} }
it { should == "Carzilla" }
end