Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
module Paperclip
module ClassMethods
def has_attached_file name, options = {}
include InstanceMethods
write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil?
attachment_definitions[name] = {:validations => []}.merge(options)
after_save :save_attached_files
before_destroy :destroy_attached_files
module AWS
module S3
class Bucket
def copy_to(target)
each do |obj|
returning Base.put("/#{target}/#{obj.key}", { 'x-amz-copy-source' => "/#{name}/#{obj.key}", 'x-amz-metadata-directive' => 'COPY', 'Content-Length' => 0 }) do
S3Object.acl(obj.key, target, S3Object.acl(obj.key, name))
end
end
end
ca = ClientApplication.create(:name => 'Test Consumer App', :url => 'http://consumerapp.local')
consumer = OAuth::Consumer.new(ca.key, ca.secret, :site => 'http://localhost:3000')
request_token = consumer.get_request_token
`open #{request_token.authorize_url}`
# after POSTing that form...
db_request_token = RequestToken.last
ActiveRecord::Schema.define(:version => 20100824224246) do
create_table "users", :force => true do |t|
t.string "name"
t.text "friend_list"
t.datetime "created_at"
t.datetime "updated_at"
end
end
@stympy
stympy / subscription_plan.rb
Created October 25, 2010 21:20
Extension to SubscriptionPlan provided in the SaaS Rails Kit
Rails.application.config.to_prepare do
SubscriptionPlan.class_eval do
scope :active, where(:active => true)
scope :by_price, order(:amount)
end
end
en:
groceries:
sample_data: [Eggs, Milk, Bread]
function displaySuccess(message) {
$('body').scrollTo();
$('#success_message').remove();
$('#content').prepend(banner = $('<div class="ui-widget flash hidden" id="success_message"><div class="ui-state-corner-all ui-state-highlight"><p><span class="ui-icon ui-icon-info"></span>' + message + '</p></div></div>'));
banner.slideDown('normal', function() {
setTimeout(function() { banner.slideUp('slow'); }, 10000);
});
}
function formSubmit(data, status, xhr, form) {
@stympy
stympy / delayed_job.rb
Created April 12, 2011 19:43
Initializer with auto-spawn support
Delayed::Worker.auto_scale = true
if Rails.env.production?
Delayed::Worker.auto_scale_manager = ENV['HEROKU_APP'] ? :heroku : :local
else
Delayed::Worker.auto_scale_manager = :local
end
@stympy
stympy / gist:948168
Created April 29, 2011 11:00 — forked from therealadam/gist:731944
Trace slow queries in Rails
class QueryTracer < ActiveSupport::LogSubscriber
ACCEPT = %r{^(app|config|lib)}.freeze
FRAMES = 5
THRESHOLD = 300 # In ms
def sql(event)
return unless event.duration > THRESHOLD
callers = Rails.
backtrace_cleaner.
@stympy
stympy / generate_archives.rb
Created May 23, 2011 13:05
Archive generator plugin for jekyll
# Jekyll archive page generator with pagination.
#
# Based on the category generator from
# http://recursive-design.com/projects/jekyll-plugins/,
# which is copyright (c) 2010 Dave Perrett,
# http://recursive-design.com/ and is licensed under the MIT
# license (http://www.opensource.org/licenses/mit-license.php), and
# on the pagination code from Jekyll itself.
#
# This code is copyright (c) 2011 Benjamin Curtis, and is licensed