Skip to content

Instantly share code, notes, and snippets.

View bench.rb
require 'benchmark/ips'
require 'set'
set = Set[:$or, :$and, :$nor]
array = %i($or $and $nor)
Benchmark.ips do |x|
x.config(:time => 10, :warmup => 2)
View gist:632cb0e63ad314c34521
if Rails::VERSION::MAJOR > 4
raise "This patch is obsolete and should be removed"
class Time
def compare_with_coercion(other)
# we're avoiding Time#to_datetime and Time#to_time because they're expensive
if other.class == Time
elsif other.is_a?(Time)
View gist:d3ff215e88334dd7542a
event = fn
{:startElement, _, 'Contents', _, _}, _, state ->
put_in(state[:current], %{})
{:startElement, _, _name, _, _}, _, state ->
put_in(state[:value], "")
{:characters, data}, _, state ->
update_in(state[:value], &(to_string(data) <> &1))
{:endElement, _, 'Contents', _}, _, state ->
fcheung / gist:4072448
Created Nov 14, 2012
BritRuby proposal
View gist:4072448

Going Native

We all love ruby, but sometimes ruby is not enough. Whether it be a performance bottleneck, a killer library written in C or some platform specific functionality you just have to have, sometimes you need to drop down a level.

There have been many talks that show how to take the first steps in writing a ruby C extension. This isn't one of them. I propose instead to give an overview of different ways of extending ruby and show what each approach brings to the table. I intend to cover 'classic' C extensions, RubyInline and FFI across a range of ruby implementations.

About me

View gist:42383
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb
index 83043c2..8c2507e 100644
--- a/activerecord/lib/active_record/named_scope.rb
+++ b/activerecord/lib/active_record/named_scope.rb
@@ -93,7 +93,11 @@ module ActiveRecord
(class << self; self end).instance_eval do
define_method name do |*args|
- scopes[name].call(self, *args)
+ if scoped? :find