Skip to content

Instantly share code, notes, and snippets.

View jcf's full-sized avatar
❤️

James Conroy-Finn jcf

❤️
View GitHub Profile
@jcf
jcf / 0-readme.md
Created September 18, 2012 17:22 — forked from burke/0-readme.md
ruby-1.9.3-p194 cumulative performance patch.

Patched ruby 1.9.3-p194 for 30% faster rails boot

Overview

This script installs a patched version of ruby 1.9.3-p194 with boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Many thanks to funny-falcon for the performance patches.

start() {
set -e
if [ $# -ne 1 ]; then
echo "You need to supply a queue number. Usage: start queue-number"
else
cd ~/Code/broadcast
export RAILS_ENV=production
export QUEUE=support"$1"
git pull --rebase origin master
@jcf
jcf / query_trace.rb
Created January 17, 2012 15:30 — forked from belt/query_trace.rb
QueryTrace... ported to rails3
require 'term/ansicolor'
# yeilds a stacktrace for each SQL query
# put this file in config/initializers
class QueryTrace < ActiveSupport::LogSubscriber
include Term::ANSIColor
attr_accessor :trace_queries
def sql(event) #:nodoc:
return unless QueryTrace.enabled? && logger.debug? && Rails.env.development?
@jcf
jcf / email_validator.rb
Created September 2, 2011 10:48 — forked from stauntonknight/email_validator.rb
Rails 3 Email Validator
require 'mail'
class EmailValidator < ActiveModel::EachValidator
attr_reader :record, :attribute, :value, :email, :tree
def validate_each(record, attribute, value)
@record, @attribute, @value = record, attribute, value
@email = Mail::Address.new(value)
@tree = email.__send__(:tree)
%w(red amber green).map.with_index do |color, index|
color if ((index + 1) / 3.0) < (count.to_f / total.to_f)
end.compact.first
@jcf
jcf / factories.rb
Created September 8, 2010 08:25 — forked from jferris/factories.rb
Factory.define :post do |post_factory|
post_factory.user { Factory.build(:user) }
end
// An Unobtrusive Javascript (UJS) driver based on explicit behavior definitions. Just
// put a "data-behaviors" attribute on your view elements, and then assign callbacks
// for those named behaviors via Behaviors.add.
var Behaviors = {
add: function(event, behavior, callback) {
return $('*[data-behaviors~=' + behavior + ']').bind(event, callback);
}
};
module Math
def self.factorial(f)
f == 0 ? 1 : f * factorial(f - 1)
end
end
# Or we can extend an instance of Fixnum so we can do 5.factorial :)
class Fixnum
def factorial
self == 0 ? 1 : self * (self - 1).factorial
module Math
def self.factorial(f)
f == 0 ? 1 : f * factorial(f - 1)
end
end
# Or we can extend an instance of Fixnum so we can do 5.factorial :)
class Fixnum
def factorial
self == 0 ? 1 : self * (self - 1).factorial
def build_message
message = PORTFOLIO_FIELDS.graph{|field, _| [field, send(field)] }
self.message = message.delete_if { |_, value| value.nil? }
end