This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AfterCommit | |
def self.included(base) | |
base.class_eval do | |
[:save, :save!].each do |method| | |
alias_method_chain method, :after_commit | |
end | |
end | |
base.define_callbacks :after_commit, :after_commit_on_create | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
class Processor | |
LOG_DIR = File.join(Rails.root, 'log') | |
class Daemon | |
PID_DIR = File.join(Rails.root, 'tmp', 'pids') | |
class << self | |
def daemonize!(name) | |
fork do | |
Process.setsid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.dirname(__FILE__) + '/../config/environment' | |
def start_processor(queue) | |
puts "Starting #{queue} processor..." | |
klass = queue.to_s.camelize.constantize | |
klass.start!(true) | |
end | |
def stop_processor(queue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
private | |
def attributes_protected_by_default | |
default = [ self.class.primary_key, self.class.inheritance_column ] | |
default.concat ['created_at', 'created_on', 'updated_at', 'updated_on'] | |
default << 'id' unless self.class.primary_key.eql? 'id' | |
default | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Paperclip | |
module Storage | |
module Better | |
def self.extended base | |
require 'aws/s3' | |
base.instance_eval do | |
@bucket = @options[:bucket] | |
@bucket = @bucket.call(self) if @bucket.is_a?(Proc) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TransactionalIncrement | |
def increment!(att, by = 1) | |
increment(att, by) | |
changed_attributes.delete(att.to_s) | |
self.class.update_counters(id, att => by) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. | |
This Ruby causes the following error: | |
window.send("test2=", { | |
:setup => method(:setup), | |
:send => method(:send) | |
}) | |
terminate called after throwing an instance of 'std::logic_error' | |
what(): basic_string::_S_construct NULL not valid | |
Abort trap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Alex MacCaw | |
Simple tabs lib | |
<script type="text/javascript" charset="utf-8"> | |
jQuery(function($){ | |
$("#tabs a").tabs(); | |
}); | |
</script> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sold on jQuery - just re-wrote the following Prototype code: | |
Element.observe(window, 'load', function(){ | |
// This is for slow forms (like the signup one), | |
// so the user doesn't click 'Submit' twice. | |
$$('form.slow').each(function(frm){ | |
var sub = frm.down("input[type='submit']"); | |
if(sub) sub.disabled = ''; | |
$(frm).observe('submit', function(e){ | |
var sub = frm.down("input[type='submit']"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gets a good score on YSlow | |
# Deflate | |
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript application/javascript application/x-javascript text/js | |
BrowserMatch ^Mozilla/4 gzip-only-text/html | |
BrowserMatch ^Mozilla/4.0[678] no-gzip | |
BrowserMatch ^HMSIE !no-gzip !gzip-only-text/html | |
<LocationMatch "^/(images|javascripts|stylesheets)/.*$"> | |
# The Last-Modified time has the same effect as an ETag here |