Skip to content

Instantly share code, notes, and snippets.

View migrate-sidekiq-redis.rb
# 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 Jun 7, 2022
warnings and Ruby 3.0

on CI and local

export RUBYOPT="-W:deprecated" # show warnings, deprecations only
bf4 / db-switch.rb
Created Aug 30, 2021 — forked from matthewd/db-switch.rb
View 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 Nov 2, 2020
Rails 6.0 multi-db extensions for migration tasks
View db.rake
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 Aug 2, 2019 — forked from BalmanRawat/dump_memcache.rb
Dumping and restoring the memcache key values using telnet & dalli gem
View dump_memcache.rb
#!/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 Jun 19, 2019 — 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…
View live_database_dump.rb
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
bf4 / clock
Created Apr 3, 2019
Script to run only in the specified minute range
View clock
#!/usr/bin/env bash
# Created by Benjamin Fleischer 2019
# Distributed under the MIT license
# Usage:
# MINUTE_RANGES="0...10 30...40" ./clock echo 'we done it'
# DEBUG=true MINUTE_RANGES="0...10 30...40" ./clock echo 'we done it'
main() {
local ranges
bf4 / jdbc_sample.rb
Created Apr 18, 2018 — forked from rwjblue/jdbc_sample.rb
Convert JDBC ResultSet into Ruby Hash with JRuby
View jdbc_sample.rb
require './lib/adsjdbc-'
java_import java.sql.Driver
java_import java.sql.DriverManager
java_import 'com.extendedsystems.jdbc.advantage.ADSDriver'
class AdsAdapter
def initialize(connect_string)
@connect_string = connect_string
View test_schema_jsonapi.json
"$schema": "",
"description": "JSON:API Schema",
"type": "object",
"properties": {
"link": { "$ref": "file://schemata/link.json#" },
"meta": { "$ref": "file://schemata/meta.json#" }

A collection of Linux commands and concepts I tend to forget