Skip to content

Instantly share code, notes, and snippets.

View maccman's full-sized avatar
🦜
gpu poor

Alex MacCaw maccman

🦜
gpu poor
View GitHub Profile
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
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
#!/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)
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
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
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
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
/*
Alex MacCaw
Simple tabs lib
<script type="text/javascript" charset="utf-8">
jQuery(function($){
$("#tabs a").tabs();
});
</script>
// 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']");
# 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
OSZAR »