Skip to content

Instantly share code, notes, and snippets.

View shinzui's full-sized avatar
👨‍💻

Nadeem Bitar shinzui

👨‍💻
  • Los Angeles / San Francisco
  • X @shinzui
View GitHub Profile
@shinzui
shinzui / factories.rb
Created February 2, 2010 08:44 — forked from technicalpickles/factories.rb
Factory Girl Attachment
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end
module ParameterizedConcern
def extended(mod = nil, &block)
unless mod
@extended_block = block
return
end
mod.module_eval(&@extended_block) if @extended_block
end
module ParameterizedConcern
def extended(mod = nil, &block)
unless mod
@extended_block = block
return
end
mod.module_eval(&@extended_block) if @extended_block
end
@shinzui
shinzui / connection_fix.rb
Created February 24, 2010 02:26 — forked from defunkt/connection_fix.rb
MySQL has gone away fix
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@shinzui
shinzui / capture_io.rb
Created February 28, 2010 11:19
Capture stdout and stderr for testing
def capture_io
require "stringio"
orig_stdout, orig_stderr = $stdout, $stderr
captured_stdout, captured_stderr = StringIO.new, StringIO.new
$stdout, $stderr = captured_stdout, captured_stderr
yield
return captured_stdout.string, captured_stderr.string
@shinzui
shinzui / current_user.rb
Created March 22, 2010 07:04
Current user in model
module SentientUser
def self.included(base)
base.class_eval {
def self.current
Thread.current[:user]
end
def self.current=(o)
raise(ArgumentError,
begin
load File.join(ENV["HOME"], ".irbrc") if File.exists?("#{ENV["HOME"]}/.irbrc")
rescue LoadError => le
puts le
rescue => exception
puts "Error : 'load #{ENV["HOME"]}/.irbrc' : #{exception.message}"
end
require "resque"
require "resque/failure/multiple"
require "resque/failure/redis"
# Configure Resque connection from config/redis.yml. This file should look
# something like:
# development: localhost:6379
# test: localhost:6379:15
# production: localhost:6379
Resque.redis = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]
@shinzui
shinzui / gist:385440
Created April 30, 2010 16:31 — forked from lsegal/gist:359307
Callbacks
module Callbacks
@@callbacks = {}
def has_callback_hook(name)
@@callbacks[name] = []
class_eval <<-CLASS
def #{name}_add block
@callbacks[#{name}] << block
end
@shinzui
shinzui / terms_of_service.markdown
Created May 10, 2010 05:20 — forked from devver/terms_of_service.markdown
Devver open source Terms of Service

Terms of Service

Last revised on [DATE]

The Gist

[COMPANY] operates the [SERVICE] service, which we hope you use. If you use it, please use it responsibly. If you don't, we'll have to terminate your account.

For paid accounts, you'll be charged on a monthly basis. You can cancel anytime, but there are no refunds.