Skip to content

Instantly share code, notes, and snippets.

View byroot's full-sized avatar

Jean Boussier byroot

View GitHub Profile
@byroot
byroot / wtf.rb
Last active August 29, 2015 13:57
class Foo
def bar(*args)
attribute(:bar, *args)
end
def attribute(name)
puts name
end
module IdempotentCounterCache
module BuilderExtension
def add_counter_cache_callbacks(reflection)
super
cache_column = reflection.counter_cache_column
foreign_key = reflection.foreign_key
# This skip_callback do not work... may be related to https://github.com/rails/rails/issues/12571
# model.skip_callback(:destroy, :before, "belongs_to_counter_cache_before_destroy_for_#{name}")
$ bundle exec ruby per_thread_registry_benchmark.rb
Calculating -------------------------------------
thread-safe 25.176k i/100ms
thread-unsafe 30.069k i/100ms
-------------------------------------------------
thread-safe 1.480M (± 6.5%) i/s - 7.377M
thread-unsafe 2.480M (± 7.2%) i/s - 12.328M
Calculating -------------------------------------
thread-safe 72.674k i/100ms
-------------------------------------------------
thread-safe 2.128M (± 5.8%) i/s - 10.610M
Calculating -------------------------------------
thread-unsafe 109.385k i/100ms
-------------------------------------------------
thread-unsafe 5.545M (± 7.9%) i/s - 27.565M
require 'benchmark/ips'
require 'active_support/cache'
require 'memcached'
require 'active_support/cache/memcached_store'
require 'active_support/cache/dalli_store'
$dalli = ActiveSupport::Cache::DalliStore.new('127.0.0.1:11211')
$memcached = ActiveSupport::Cache::MemcachedStore.new('127.0.0.1:11211')
KEY = 'somekey'
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
class Recette < AR::Base
has_many :ingredients
end
class Ingredient < AR::Base
belongs_to :recette
has_one :ingedient_type
end
class IngredientType < AR::Base
class A:
def open(self):
# code avant
self._open(self)
# code après
class B(A):
def _open(self):
pass
require 'spec_helper'
describe User do
it{ should have_field(:email).of_type(String) }
it{ should have_field(:username).of_type(String) }
it{ should have_field(:password_hash).of_type(String) }
it{ should have_field(:password_salt).of_type(String) }
it{ should have_field(:activation_token).of_type(String) }
module Mongoid
module Mutation
def as(klass, extra_attributes={})
klass.new(attributes_for(klass, extra_attributes)).tap do |mutation|
mutation.new_record = new_record?
mutation.send(:modifications)['_type'] = [self._type, klass.name]
end
end