Skip to content

Instantly share code, notes, and snippets.

bf4 / flag_registration.rb
Created April 19, 2024 05:43 — forked from synth/flag_registration.rb
Feature flag code detection
require "parser/current"
module Flipper
module FlagRegistration
# These functions are all memoized because they should be static for the
# lifetime of a deployment (albeit they are really static to a Ruby process)
def self.registered_flags
@registered_flags ||= YAML.load_file("config/feature_flags.yml")
bf4 / schema_dumper.rb
Created September 21, 2023 01:29 — forked from drnic/schema_dumper.rb
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
Rails.configuration.to_prepare do
ActiveRecord::SchemaDumper.ignore_tables = %w[
bf4 /
Created February 27, 2023 15:24 — forked from nemani/
Download All Lambda Functions
# Usage:
# ./
# ./ download us-east-1 my-function
# ./ help
# Downloads all aws-lambda functions to a subdirectory
# Assumes you have a role that has at least read access to lambda.
# Credits to
bf4 / migrate-sidekiq-redis.rb
Created September 2, 2022 04:10 — forked from natematykiewicz/migrate-sidekiq-redis.rb
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 = url: 'redis://old-redis:6379'
new_redis = url: 'redis://new-redis:6379'
unknowns = []
bf4 /
Created June 7, 2022 17:51
warnings and Ruby 3.0

on CI and local

export RUBYOPT="-W:deprecated" # show warnings, deprecations only
bf4 / db-switch.rb
Created August 30, 2021 18:21 — forked from matthewd/db-switch.rb
#!/usr/bin/env ruby
require(Dir.pwd + "/config/environment")
ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env).each do |db_config|
context = ActiveRecord::Base.connection.migration_context
missing_migrations = []
bf4 / db.rake
Created November 2, 2020 17:54
Rails 6.0 multi-db extensions for migration tasks
require "active_record"
databases = ActiveRecord::Tasks::DatabaseTasks.setup_initial_database_yaml
db_namespace = namespace :db do
if Rails.version.start_with?("6.0")
namespace :rollback do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
bf4 / dump_memcache.rb
Created August 2, 2019 19:48 — forked from rbalman/dump_memcache.rb
Dumping and restoring the memcache key values using telnet & dalli gem
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
require 'csv'
headings = %w(id expires bytes key)
rows = []
bf4 / live_database_dump.rb
Last active June 19, 2019 19:22 — forked from njakobsen/live_database_dump.rb
Live stream a database dump (or any other STDOUT) using Rails 4. Why would you want this? If you have a large database dump and want to avoid storing it in memory as Rails streams it. This allows pipe the dump directly into the http response instead of storing it as a file, sending it, and then deleting it. Let me know what you think! I've teste…
class DatabaseController < ApplicationController
def database_dump
database = Rails.configuration.database_configuration[Rails.env]["database"]
send_file_headers!(:type => 'application/octet-stream', :filename => "#{database}_#{}.backup")
pipe = IO.popen("pg_dump '#{database}' -F c")
stream =
while (line = # per
stream.write line
Thread.pass # per