Skip to content

Instantly share code, notes, and snippets.

View p8's full-sized avatar

Petrik de Heus p8

View GitHub Profile
View gist:8ed895c2de3cff57bcb5ae9f256f5268
require "bundler/setup"
require "active_record"
begin
require "benchmark/ips"
rescue LoadError
raise LoadError, "Run install `gem install benchmark-ips`"
end
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.create_table(:orders) { |t| }
View gist:06c9655209b1cc85df87ae8894a6dcd4
require "bundler/setup"
require "active_record"
require "benchmark/ips"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.create_table(:orders) { |t| }
ActiveRecord::Base.connection.create_table(:items) do |t|
t.references :order, null: false
t.references :product, null: false
end
@p8
p8 / merge.rb
Last active April 26, 2020 13:03
RSpec Mono Repo merge script
View merge.rb
#!/usr/bin/env ruby
working_dir = 'working'
Repo = Struct.new(:name, :url, :branch)
repos = [
Repo.new('rspec', 'git@github.com:rspec/rspec.git'),
Repo.new('rspec-core', 'git@github.com:rspec/rspec-core.git'),
Repo.new('rspec-expectations', 'git@github.com:rspec/rspec-expectations.git'),
Repo.new('rspec-mocks', 'git@github.com:rspec/rspec-mocks.git'),
View gist:0b308317c45c7d9d10ec01fc59b30fe6
desc "Copies order insertion"
task :copy_order_insertion => :environment do
current_version = ENV['CURRENT_VERSION'].try(:upcase)
raise "Must specify CURRENT_VERSION" unless current_version
new_version = ENV['NEW_VERSION'].try(:upcase)
raise "Must specify NEW_VERSION" unless new_version
# copy files
paths = %w[
app/models
@p8
p8 / lithp.rb
Created January 26, 2012 00:34 — forked from fogus/lithp.rb
View lithp.rb
class Lisp
Fs = {
:label => lambda {|name,value| Fs[name] = lambda { value } },
:car => lambda {|sexp| sexp.first },
:cdr => lambda {|sexp| sexp.slice(1, sexp.size) },
:cons => lambda {|head,tail| [head] + tail },
:atom => lambda {|sexp| !sexp.is_a?(Array) },
:eq => lambda {|a,b| a == b },
:if => lambda {|cnd,thn,els| cnd ? thn : els }
}
@p8
p8 / gist:6493058
Created September 9, 2013 08:43
Commit as another user
View gist:6493058
git commit -m "Removed trailing whitespace" --author="Whitespace Remover <whitespace-remover@example.com>"
@p8
p8 / eigenclass
Created September 29, 2010 22:16
View eigenclass
String.class_eval { def instance_method; "instance method"; end }
String.class.class_eval { def class_method; "class method"; end }
String.class.class.class_eval { def eigenclass_method; "eigenclass method"; end }
"a".instance_method # => "instance method"
String.class_method # => "class method"
class X < String
eigenclass_method
end # => "eigenclass method"