Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / file.md
Last active April 19, 2024 09:09
Using Jemalloc 5 with Ruby.md

For years, people have been using jemalloc with ruby. There are various benchmarks and discussions. Legend had it that Jemalloc 5 doesn't work as well as Jemalloc 3.

Then, one day, hope appeared on the horizon. Someone offered a config for Jemalloc 5.

The recipe would be something like this (shown with official docker ruby image).

FROM ruby:3.1.2-bullseye
@natematykiewicz
natematykiewicz / migrate-sidekiq-redis.rb
Last active February 21, 2024 17:18
Migrate Sidekiq Redis
# A script to migrate Sidekiq's redis to a new server.
# This obviously can work for any redis, but I only handled
# data types that Sidekiq uses.
require 'redis'
old_redis = Redis.new url: 'redis://old-redis:6379'
new_redis = Redis.new url: 'redis://new-redis:6379'
unknowns = []
@drnic
drnic / schema_dumper.rb
Last active February 6, 2024 16:01
Our rails db includes our own tables/schema and the Salesforce/Heroku Connect schema (under "salesforce.*"). We place this file in config/initializers/schema_dumper.rb and now our rails db:schema:dump includes both our own tables and the salesforce. tables.
# This solution was based on https://gist.github.com/GlenCrawford/16163abab7852c1bd550547f29971c18
Rails.configuration.to_prepare do
ActiveRecord::SchemaDumper.ignore_tables = %w[
salesforce._hcmeta
salesforce._sf_event_log
salesforce._trigger_log
salesforce._trigger_log_archive
]
end
@palkan
palkan / README.md
Created January 24, 2022 13:29
Rails boot time profiling

Add the following to application.rb:

$icallbacks = []
$icallbacks.define_singleton_method(:print) do
  puts sort_by { |(a, b)| -b }.map { |(a, b)| "#{b}\t\t#{a}" }.join("\n")
end

ActiveSupport::Notifications.subscribe("load_config_initializer.railties") do |event|
 $icallbacks << [event.payload[:initializer], event.duration]
@matthewd
matthewd / db-switch.rb
Created April 1, 2021 05:50
bin/db-switch
#!/usr/bin/env ruby
require(Dir.pwd + "/config/environment")
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
ActiveRecord::Base.establish_connection(db_config.config)
context = ActiveRecord::Base.connection.migration_context
missing_migrations = []
@DmitryTsepelev
DmitryTsepelev / change_column_type.rb
Created August 27, 2020 08:46
How to change column type (e.g., int -> bigint) without downtime
ActiveRecord::Migration.remove_foreign_key(:current_table, :foreign_table) # no lock
ActiveRecord::Migration.add_column(:current_table, :column_bigint, :bigint) # no lock
copy_data = lambda do
CurrentTable.where(column_bigint: nil).where.not(column: nil).in_batches do |batch|
batch.update_all("column_bigint = column")
end
end
def recurse(i)
recurse(i-1) if i > 0
end
threads = ARGV[0].to_i
puts "Running with #{threads} threads!"
threads.times do
Thread.new do
recurse(500)
sleep
puts "done"
<?xml version="1.0"?>
<!--
Tap CAPS for ESC, hold CAPS + hjkl for Vim movement.
Open "System Preferences > Keyboard > Modifier Keys..." and change caps lock configuration to "No Action"
Use Seil to remap caps to F19 (80)
-->
<root>
@jjb
jjb / file.md
Last active September 13, 2021 17:46
Trying to figure out performance impact of RUBY_GC_HEAP_GROWTH_FACTOR
@searls
searls / market_research.rb
Last active September 18, 2018 03:21
Was chatting with @mfeathers about retaining Ruby's chained Enumerable style, but finding a way to inject names that reflects the application domain (as opposed to just littering functional operations everywhere, which may be seen as a sort of Primitive Obsession)
# A little toy file demonstrating how to build chainable
# data transformations that reveal some amount of intent
# through named extracted methods.
#
# Kudos to @mfeathers for giving me the idea to try this
#
# Copyright Test Double, LLC, 2016. All Rights Reserved.
require_relative "marketing_refinements"