Skip to content

Instantly share code, notes, and snippets.

View jrafanie's full-sized avatar

Joe Rafaniello jrafanie

  • New Jersey
View GitHub Profile
@jrafanie
jrafanie / inline_rails_server.rb
Last active April 7, 2016 14:53
puma 3.0.0+ resets proctitle in rails server
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'
gem 'rails', github: 'rails/rails'
@jrafanie
jrafanie / recreation_script.rb
Last active February 24, 2016 04:38
Uniqueness with an after_create that saves fails on rails master
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'
gem 'rails', github: 'rails/rails'
@jrafanie
jrafanie / output.txt
Last active February 2, 2016 16:25
ruby Method#owner lies
1.9.3
ChildClass#f, owner: ParentClass, original_name:
ParentClass#f, owner: ParentClass, original_name:
ChildClass#g1, owner: GrandparentClass, original_name:
ParentClass#g1, owner: GrandparentClass, original_name:
ChildClass#g2, owner: ParentClass, original_name:
ParentClass#g2, owner: ParentClass, original_name:
2.0.0
@jrafanie
jrafanie / cow_wat.rb
Last active January 22, 2016 22:32
Unexpected copy on write
# From: http://stackoverflow.com/questions/30353272/garbage-collector-in-ruby-2-2-provokes-unexpected-cow
# Modified to use rails and bundler/inline magic to load rails instead of creating a big object
require 'bundler'
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
@jrafanie
jrafanie / fork.rb
Last active January 15, 2016 15:21
Testing if Process.fork requires 4.2 ActiveRecord disconnect/reconnect before after fork
puts "Parent: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}"
SchemaMigration.count
# Place I thought we'd need to disconnect
# ActiveRecord::Base.clear_all_connections!
puts "Parent: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}"
10.times do
pid = fork do
puts "Child: #{Process.pid} #{ActiveRecord::Base.connection_pool.connections.collect(&:spid)}"
@jrafanie
jrafanie / boom.rb
Last active December 18, 2015 16:58 — forked from tenderlove/boom.rb
minitest-stub_any_instance fails with ruby 2.3.0-preview2
# Fork of the rspec boom.rb: https://gist.github.com/tenderlove/183d0d7244f2f2da32aa from https://github.com/rspec/rspec-mocks/issues/1042
# This one is for minitest.
# Run this with minitest/minitest-stub_any_instance, it will randomly fail in ruby 2.3.0-preview2 when the ".new" example runs last.
# It passes if the stub any instance test method happens last with:
#
# Running
# <UnboundMethod: SmallCircle(Circle)#area>
# ..
#
# It fails with
@jrafanie
jrafanie / rspec_mock_ruby23_wat.rb
Last active December 16, 2015 19:49
rspec any_instance doesn't rollback stub with ruby 2.3.0-preview2
# Run this with rspec 2 or 3, it will randomly fail in ruby 2.3.0-preview2 when the ".new" example runs last.
# It fails with
# 1) SmallCircle .new
# Failure/Error:
# def area
# super(2)
#
# ArgumentError:
# wrong number of arguments (given 1, expected 0)
# inline_spec.rb:23:in `area'
@jrafanie
jrafanie / 2.3.0-preview2.txt
Created December 15, 2015 22:41
rspec-mocks at b94e242ebbc5 fails to redefine methods/super method in ruby 2.3-preview2
05:29:41 ~/Code/rspec-mocks (master) (2.3.0-preview2) + be rake spec
/Users/joerafaniello/.rubies/ruby-2.3.0-preview2/bin/ruby -w -I/Users/joerafaniello/Code/rspec-core/lib:/Users/joerafaniello/Code/rspec-support/lib /Users/joerafaniello/Code/rspec-core/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb --color
Run options:
include {:focus=>true}
exclude {:ordered_and_vague_counts_unsupported=>true}
All examples were filtered out; ignoring {:focus=>true}
Randomized with seed 438
....................................................................................................................................................................................................................................................................................*...................................................................................................................................................................../Users/joerafaniello/Code/rspec-mocks/lib/rspec/mocks/method_double.rb:63: warning: metho
@jrafanie
jrafanie / Lots of duplicate strings created in routing, rails 4-2-stable
Last active October 21, 2015 19:38
Lots of duplicate strings created in routing
# Using rails 4.2.4 from git://github.com/jrafanie/rails.git (at naively_retain_separators)
# Retained String count: 27681
# Retained String memsize: 1165431
# Using rails 4.2.4 from git://github.com/rails/rails.git (at 4-2-stable)
# Retained String count: 29890
# Retained String memsize: 1538153
@jrafanie
jrafanie / run_refresh.rb
Last active October 14, 2015 19:26
Track allocations in ems refresh
# How to run:
# bundle exec evm:db:reset > /dev/null && bundle exec rails r setup_ems.rb && bundle exec rails r run_refresh.rb
def miq_trace(description = "")
require 'allocation_tracer'
ObjectSpace::AllocationTracer.setup(%i{type class})
result = ObjectSpace::AllocationTracer.trace do
yield
nil