Skip to content

Instantly share code, notes, and snippets.

View p8's full-sized avatar

Petrik de Heus p8

View GitHub Profile
@p8
p8 / eigenclass
Created September 29, 2010 22:16
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"
@p8
p8 / lithp.rb
Created January 26, 2012 00:34 — forked from fogus/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
git commit -m "Removed trailing whitespace" --author="Whitespace Remover <[email protected]>"
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 / merge.rb
Last active April 26, 2020 13:03
RSpec Mono Repo merge script
#!/usr/bin/env ruby
working_dir = 'working'
Repo = Struct.new(:name, :url, :branch)
repos = [
Repo.new('rspec', '[email protected]:rspec/rspec.git'),
Repo.new('rspec-core', '[email protected]:rspec/rspec-core.git'),
Repo.new('rspec-expectations', '[email protected]:rspec/rspec-expectations.git'),
Repo.new('rspec-mocks', '[email protected]:rspec/rspec-mocks.git'),
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
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| }