Skip to content

Instantly share code, notes, and snippets.

@composerinteralia
composerinteralia / active_record_bug.rb
Last active January 31, 2017 21:27
Collection Singular Ids Bug
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"
@composerinteralia
composerinteralia / factory_bot_benchmark.rb
Last active June 23, 2020 17:07
Factory Bot Benchmark
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"
@composerinteralia
composerinteralia / old_ruby_bug.rb
Last active September 29, 2017 11:57
Ruby bug causing weirdness in RSpec
RUBY_VERSION='2.1.10'
# Fails with 2.0.0 and 2.1.10
# Passes with 2.3.1 and 2.4.1
# Have not tried with any other versions
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
@composerinteralia
composerinteralia / invoking_blocks.rb
Last active October 29, 2017 16:26
Benchmarking yield, call, instance_eval
require 'benchmark'
def yielder
yield
end
def caller(&block)
block.call
end
@composerinteralia
composerinteralia / bug.rb
Last active October 5, 2021 16:43
Active Record counter_cache + inverse_of bug
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "main"
@composerinteralia
composerinteralia / multi-db-after-commit-bug.rb
Last active October 13, 2021 17:57
Bug with multiple databases, through association, and after_commit callback
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", path: "/Users/composerinteralia/code/rails/rails"
@composerinteralia
composerinteralia / autosave_validations.rb
Created October 28, 2022 20:12
Autosave validations
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
class SeedQueue
def self.<<(seed)
seed.plant
end
end
class Seed
include ActiveModel::Attributes
end
@composerinteralia
composerinteralia / quine_about_quines.rb
Last active December 4, 2022 18:57
Quine about quines
# Quines are programs that print their own source code
# This program is a quine that explains how some Ruby quines work
# This first one uses a heredoc with 2 as the delimiter
# The beginning of the program appears twice (before and inside the heredoc)
# Then it puts the string twice (* 2) and puts 2
puts <<2*2,2
# Quines are programs that print their own source code
# This program is a quine that explains how some Ruby quines work
@composerinteralia
composerinteralia / hello_world
Last active December 5, 2022 01:45
A hello world program written in Ruby
-> ( #
_ ,
& __
){ t=
-> { ;
__[ [
_1], _[2
], _[
1] ]}
_=__[ _[3 ..