Skip to content

Instantly share code, notes, and snippets.

View byroot's full-sized avatar

Jean Boussier byroot

View GitHub Profile
$ 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
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}")
if Rails::VERSION::MAJOR >= 4
if Rails::VERSION::MINOR > 0
ActiveSupport::Deprecation.warn("This patch is probably not useful anymore. Check if https://github.com/rails/rails/pull/12425 have been released.")
end
class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
def type_cast(value, column)
case value
when TrueClass
@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
desc "convert a latin1 database with utf8 data into proper utf8"
task :convert_to_utf8 => :environment do
puts Time.now
dryrun = ENV['DOIT'] != '1'
conn = ActiveRecord::Base.connection
if dryrun
def conn.run_sql(sql)
puts(sql)
end
else
module Raven
class Report < Tilt::Template
def prepare
end
def evaluate(context, locals, &block)
if context.logical_path.include?('raven') || context.logical_path.include?('github-integration')
data
else
module SomeObserver
extend ActiveSupport::Concern
included do
after_create :do_something
end
def do_something
#
end
class Foo
@byroot
byroot / select2-testcase.html
Created June 15, 2012 17:34
SHow a failing case with select2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Select2 2.1</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Select2 JQuery Plugin">
<meta name="author" content="Igor Vaynberg">
import argparse
from pysrt import SubRipFile, SubRipItem, SubRipTime
parser = argparse.ArgumentParser(description='Merge 2 srt files.')
parser.add_argument('fin', type=str, nargs=2,
help='input file')
parser.add_argument(dest='fout', type=str, nargs=1,
help='the output file')