Skip to content

Instantly share code, notes, and snippets.

View modsognir's full-sized avatar

Jared Fraser modsognir

View GitHub Profile
You have joined the channel
Pseudomonkey: I ONLY DRINK THE BLOOD OF MY ENEMIES
AdamSeabrook: I am so rich I pay my peons to drink for me
Disconnected
@modsognir
modsognir / idea.rb
Created January 15, 2013 11:38 — forked from kalleth/idea.rb
field :name
accessible
validates :presence do
message "please provide a name"
end
end
field :email
accessible
validates :format do
@modsognir
modsognir / valid.rb
Created October 11, 2012 02:54 — forked from notahat/valid.rb
Testing fail?
# I have a class that delegates functionality to a couple of objects that it
# constructs. I want to test this in isolation. I want to make sure that the
# objects are constructed with the right arguments. I also want to make sure
# that the results from the objects are handled correctly.
#
# I'm finding it hard to structure the code and test in a way that isn't
# cumbersome. What's below works, but it feels like a lot of stubbing and setup
# for something the should be simpler.
#
def password_required?
!persisted? || password.present? || password_confirmation.present?
end
Failure/Error: Unable to find matching line from backtrace
SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:97:in `close'
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:97:in `ensure in prepare'
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:97:in `prepare'
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:134:in `execute'
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/gems/sqlite3-1.3.5/lib/sqlite3/database.rb:484:in `transaction'
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/bundler/gems/rails-ee6e3c128b72/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:304:in `block in begin_db_transaction'
# /Users/jaredfraser/.rvm/gems/ruby-1.9.3-p0-falcon/bundler/gems/rails-ee6
RSpec.configure do |config|
counter = -1
config.after(:each) do
counter += 1
if counter > 9
GC.enable
GC.start
GC.disable
counter = 0
var Inspect = {
TYPE_FUNCTION: 'function',
// Returns an array of (the names of) all methods
methods: function(obj) {
var testObj = obj || self;
var methods = [];
for (prop in testObj) {
if (typeof testObj[prop] == Inspect.TYPE_FUNCTION && typeof Inspect[prop] != Inspect.TYPE_FUNCTION) {
methods.push(prop);
}
@modsognir
modsognir / gist:1005830
Created June 3, 2011 03:38
Speed up cucumber
class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f
@@last_gc_run = Time.now
def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
end
@modsognir
modsognir / ruby_require_speed.patch
Created May 27, 2011 02:14 — forked from xaviershay/ruby_require_speed.patch
This drastically speeds up require time on ruby 1.9 (17s down to 10s in our production rails app) , at the expense of disabling some edge case handling around autoloading. YMMV but it works for our rails app.
From 2fb8432982b7e8ffc4c05f912f47cd9ca7261427 Mon Sep 17 00:00:00 2001
From: Xavier Shay <xavier@rhnh.net>
Date: Sun, 1 May 2011 10:25:18 +1000
Subject: [PATCH] Disable some edge cases in requiring to speed it up.
---
load.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/load.c b/load.c
module Resque
class Task
attr_accessor :parent, :args
attr_accessor :queue, :failed_at, :payload, :exception, :error, :backtrace, :worker
def initialize(options={})
options['parent'] = options.delete('class')
options.each do |opt, val|
self.send("#{opt}=", val)
end