Skip to content

Instantly share code, notes, and snippets.


David Butler dwbutler

View GitHub Profile
dwbutler / heroku_slug_cleanup.rake
Created Aug 23, 2018
Automatically clean up Heroku slug
View heroku_slug_cleanup.rake
CLEANUP_THRESHOLD = 250 * 1_024_000 # 250 megabytes
# See
desc "Clean up the Heroku repo to reduce compiled slug size"
task cleanup: :set_app do
force = ENV.fetch('FORCE_CLEANUP', false)
if force || slug_size > CLEANUP_THRESHOLD
puts "Heroku compiled slug size exceeds 250 MB. Cleaning up the Heroku repo."
_execute heroku_command("repo:gc")
dwbutler /
Created May 18, 2018
Downtime Post Mortem
  • Downtime window: 4:41 PM EST - 4:55 PM EST
  • Total downtime: 14 minutes

"Bob" (backend engineer) was the developer on call during this incident. All names have been changed to protect the innocent. :)


Bad code which prevented server startup was deployed to production. It had not been manually tested in a dev environment, but had passed all unit and

dwbutler /
Created May 18, 2018
Postgres Downtime Post Mortem

Written by David. Much thanks to Lukasz for technical and moral support, and helping me grep the Papertrail logs.

All times are in EST.

  • Downtime window: 8:00 AM - 8:25 AM
  • Total downtime: 25 minutes


Heroku PGBackups was running during a database migration, and was unexpectedly holding a lock. Postgres stopped serving any queries until the backup was canceled.

dwbutler / sync.rake
Last active May 8, 2018
Sync Heroku prod data to another environment
View sync.rake
namespace :sync do
desc "Run production sync"
task run: [
dwbutler / 1. Running logstash
Last active Apr 29, 2017
LogStashLogger TCP downage error handling
View 1. Running logstash
$ logstash -f samples/tcp.conf
Settings: Default pipeline workers: 8
Pipeline main started
dwbutler / constant.rb
Created Jan 4, 2017
Check where a constant got changed
View constant.rb
class Config
def CONSTANT=(val)
config =
config.CONSTANT = 2
dwbutler / overwritten.rb
Last active Jan 4, 2017
Find where a variable is overwritten with a different value
View overwritten.rb
class Config
attr_accessor :thing
def thing=(val)
raise ArgumentError if defined?(@thing)
@thing = val
config =
dwbutler / appcanary.rb
Last active Dec 14, 2015
Appcanary gem interface
View appcanary.rb
require 'appcanary'
Appcanary.configure do |config|
config.api_key = ENV['APPCANARY_API_KEY']
# Explicitly specify language and file
Appcanary.check(language: :ruby, file: 'Gemfile.lock')
# Autodetect Ruby as the language and Gemfile.lock as the file
View gist:e7d6aaa64cbaa792402b
# Tested with ActiveRecord 4.0.5
# Run using:
# BUNDLE_GEMFILE=gemfiles/rails_4.0.gemfile bundle console
require 'sqlite3'
require 'active_record'
require 'groupify/adapter/active_record'
# => "4.0.5"
dwbutler / iso8601.rb
Last active Aug 29, 2015
Parsing ISO8601 Time format with Ruby
View iso8601.rb
require 'time'
require 'benchmark'
time =
# => "2014-05-26T23:26:08.628-07:00" do |x|'parse') { 100_000.times { Time.parse(time).gmtime } }'iso8601') { 100_000.times { Time.iso8601(time).gmtime } }