Skip to content

Instantly share code, notes, and snippets.

View paulelliott's full-sized avatar

Paul Elliott paulelliott

View GitHub Profile
@leshill
leshill / Procfile
Created November 28, 2011 20:01
Unicorn config for cedar stack on Heroku.
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
@davelyon
davelyon / silece_assets.rb
Created November 16, 2011 21:48
Silence Asset Logging in Development
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def before_dispatch_with_quiet_assets(env)
before_dispatch_without_quiet_assets(env) unless env['PATH_INFO'].index("/assets/") == 0
end
alias_method_chain :before_dispatch, :quiet_assets
end
end
@jt
jt / regext.txt
Created August 22, 2011 18:41
Regular expression notes
- any character you use it will literally match it except special characters
^ $ ? . / \ [ ] { } ( ) + * - all the special characters that will need escaping if you don't want them to be special
// - regexp ruby class
Common Patterns (I authored)
/[\w+\.~-]+@[\w~-]+.[\w\.]+/ - match emails, conforms to RFC 3986 section 3.3
/\+?(\d)?[-|\.|\s]?\(?(\d{3})\)?[-|\.|\s]?(\d{3})[-|\.|\s]?(\d{4})/ - match phone numbers, https://gist.github.com/1009331
Strategies
Fabricate(:person) do
ssn { sequence(:ssn, 111111111) }
email { sequence(:email) { |i| "user#{i}@example.com" } }
end
@tomafro
tomafro / instrumentation.rb
Created February 18, 2011 09:13
Experimental Mongo Instrumentation for Rails 3
module Mongo
module Instrumentation
def self.instrument(clazz, *methods)
clazz.module_eval do
methods.each do |m|
class_eval %{def #{m}_with_instrumentation(*args, &block)
ActiveSupport::Notifications.instrumenter.instrument "mongo.mongo", :name => "#{m}" do
#{m}_without_instrumentation(*args, &block)
end
end
class Message < ActiveRecord::Base
include Postgre::Searchable
has_many :tags, inverse_of: :message
search_on do |message|
[ message.subject,
message.body,
message.tags.map(&:name) ]
end
@andregoncalves
andregoncalves / jquery.textchange.js
Created June 18, 2010 16:59 — forked from mkelly12/jquery.textchange.js
Added contenteditable support
(function ($) {
$.event.special.textchange = {
setup: function (data, namespaces) {
$(this).bind('keyup.textchange', $.event.special.textchange.handler);
$(this).bind('cut.textchange paste.textchange input.textchange', $.event.special.textchange.delayedHandler);
},
teardown: function (namespaces) {