Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
source "https://rubygems.org"
ruby "3.2.0"
gem "debug"
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(false) do
source 'https://rubygems.org'
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(false) do
source 'https://rubygems.org'
@tbuehlmann
tbuehlmann / comment.rb
Last active February 13, 2021 15:18
Flaky!
class Comment < ActiveRecord::Base
belongs_to :post, counter_cache: true
end
# config/deploy.rb
# …
# Puma tasks are in lib/capistrano/tasks/puma.rake
after 'deploy:finished', 'puma:restart'
# Sidekiq tasks are in lib/capistrano/tasks/sidekiq.rake
after 'deploy:starting', 'sidekiq:quiet'
after 'deploy:updated', 'sidekiq:stop'
#!/usr/bin/env ruby
puts ARGV[0]
require 'benchmark'
N = 10_000_000
Benchmark.bmbm do |bm|
bm.report('String') do
N.times do
a = 'foobarfoobarhmm'
a.sub('foo', 'BAR')
end
posts = Post.all
ActiveRecord::Associations::Preloader.new.preload(posts, :comments, Comment.where('id > 42'))
def some_method
some_variable = 42
yield some_variable
end
some_method do |that_variable|
puts that_variable
end