Skip to content

Instantly share code, notes, and snippets.

pete higgins phiggins

Block or report user

Report or block phiggins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@phiggins
phiggins / benchmark_append.rb
Created Oct 22, 2014
What is the fastest way to add one thing to an array without mutating the array?
View benchmark_append.rb
require 'benchmark/ips'
a = (0..10).to_a
Benchmark.ips do |x|
x.report("push") { a.dup.push(100) }
x.report("shovel") { a.dup << 100 }
x.report("concat") { a.dup.concat([100]) }
x.report("+") { a + [100] }
x.report("unshift") { a.dup.unshift(100) }
View benchmark_callback_send.rb
require 'objspace'
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection adapter: "sqlite3",
database: ":memory:"
ActiveRecord::Base.connection.instance_eval do
create_table(:articles) { |t| t.string :name }
end
@phiggins
phiggins / gist:97089e6eb5ac40298439
Created Sep 28, 2014
allocation_tracer segfault
View gist:97089e6eb5ac40298439
test_error.rb:3: [BUG] Segmentation fault at 0x00000000000000
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0005 p:---- s:0012 e:000011 CFUNC :inspect
c:0004 p:---- s:0010 e:000009 CFUNC :inspect
c:0003 p:---- s:0008 e:000007 CFUNC :p
c:0002 p:0024 s:0004 E:001dc8 EVAL test_error.rb:3 [FINISH]
c:0001 p:0000 s:0002 E:001f18 TOP [FINISH]
View gist:741a4d305c70d9113c06
> elements = {a1: 'a', b1: 'b', b2: 'b', b3: 'b', c1: 'c'}
=> {:a1=>"a", :b1=>"b", :b2=>"b", :b3=>"b", :c1=>"c"}
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b2, "b"], [:b3, "b"], [:b1, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b1, "b"], [:b3, "b"], [:b2, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b1, "b"], [:b3, "b"], [:b2, "b"], [:c1, "c"]]
> elements.group_by {|(_, val)| val }.flat_map {|(_, vals)| vals.shuffle }
=> [[:a1, "a"], [:b2, "b"], [:b1, "b"], [:b3, "b"], [:c1, "c"]]
View gist:9755989
diff --git a/rspec-support/lib/rspec/support/hunk_generator.rb b/rspec-expectations/lib/rspec/expectations/differ.rb
index 5b0d68d..cef9a1f 100644
--- a/rspec-support/lib/rspec/support/hunk_generator.rb
+++ b/rspec-expectations/lib/rspec/expectations/differ.rb
@@ -1,10 +1,7 @@
-require 'diff/lcs'
-require 'diff/lcs/hunk'
-
module RSpec
- module Support
View gist:9755971
diff --git a/rspec-support/spec/rspec/support/encoded_string_spec.rb b/rspec-expectations/spec/rspec/expectations/encoded_string_spec.rb
index a9d4052..95b2f97 100644
--- a/rspec-support/spec/rspec/support/encoded_string_spec.rb
+++ b/rspec-expectations/spec/rspec/expectations/encoded_string_spec.rb
@@ -1,6 +1,4 @@
-require 'spec_helper'
-
-module RSpec::Support
+module RSpec::Expectations
describe EncodedString do
View gist:9755964
diff --git a/rspec-support/lib/rspec/support/encoded_string.rb b/rspec-expectations/lib/rspec/expectations/encoded_string.rb
index 654a208..eeb0b16 100644
--- a/rspec-support/lib/rspec/support/encoded_string.rb
+++ b/rspec-expectations/lib/rspec/expectations/encoded_string.rb
@@ -1,5 +1,5 @@
module RSpec
- module Support
+ module Expectations
# @private
class EncodedString
View gist:9755957
diff --git a/rspec-support/lib/rspec/support/differ.rb b/rspec-expectations/lib/rspec/expectations/diff_presenter.rb
index 26da8d8..dd6e95d 100644
--- a/rspec-support/lib/rspec/support/differ.rb
+++ b/rspec-expectations/lib/rspec/expectations/diff_presenter.rb
@@ -1,27 +1,14 @@
-RSpec::Support.require_rspec_support 'encoded_string'
-RSpec::Support.require_rspec_support 'hunk_generator'
-
+require 'diff/lcs'
+require 'diff/lcs/hunk'
View gist:9755950
diff --git a/rspec-support/spec/rspec/support/differ_spec.rb b/rspec-expectations/spec/rspec/expectations/diff_presenter_spec.rb
index 69b1237..0c19de4 100644
--- a/rspec-support/spec/rspec/support/differ_spec.rb
+++ b/rspec-expectations/spec/rspec/expectations/diff_presenter_spec.rb
@@ -1,18 +1,21 @@
# encoding: utf-8
-require 'spec_helper'
require 'ostruct'
module RSpec
View diff of diff_presenter.rb
--- rspec-expectations/lib/rspec/expectations/diff_presenter.rb 2014-03-23 23:31:14.214580118 -0700
+++ rspec-support/lib/rspec/support/diff_presenter.rb 2014-03-23 23:27:18.402592651 -0700
@@ -1,14 +1,26 @@
-require 'diff/lcs'
-require 'diff/lcs/hunk'
+require "rspec/support/encoded_string"
+require "rspec/support/differ"
require 'pp'
-RSpec::Support.require_rspec_expectations "encoded_string"
-RSpec::Support.require_rspec_expectations "differ"
You can’t perform that action at this time.