Skip to content

Instantly share code, notes, and snippets.

View dwbutler's full-sized avatar

David Butler dwbutler

View GitHub Profile
@dwbutler
dwbutler / heroku_slug_cleanup.rake
Created August 23, 2018 16:27
Automatically clean up Heroku slug
CLEANUP_THRESHOLD = 250 * 1_024_000 # 250 megabytes
# See https://robots.thoughtbot.com/how-to-reduce-a-large-heroku-compiled-slug-size
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."
install_heroku_plugin('heroku-repo')
_execute heroku_command("repo:gc")
@dwbutler
dwbutler / post_mortem.md
Created May 18, 2018 05:25
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. :)

Summary

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
dwbutler / post_mortem.md
Created May 18, 2018 05:15
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

TL;DR

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
dwbutler / sync.rake
Last active May 8, 2018 20:54
Sync Heroku prod data to another environment
namespace :sync do
desc "Run production sync"
task run: [
:set_app,
:maint_on,
:scale_down,
:cancel_backup,
:delete_database,
:create_production_fork,
:migrate,
@dwbutler
dwbutler / 1. Running logstash
Last active April 29, 2017 06:05
LogStashLogger TCP downage error handling
$ logstash -f samples/tcp.conf
Settings: Default pipeline workers: 8
Pipeline main started
{"message":"\"2017-04-28T22:44:30.424-07:00\"","@timestamp":"2017-04-29T05:44:30.424Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.528-07:00\"","@timestamp":"2017-04-29T05:44:30.528Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.633-07:00\"","@timestamp":"2017-04-29T05:44:30.633Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.737-07:00\"","@timestamp":"2017-04-29T05:44:30.737Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.842-07:00\"","@timestamp":"2017-04-29T05:44:30.842Z","@version":"1","severity":"INFO","host":"Davids-MacBook-Pro-6.local","port":62671}
{"message":"\"2017-04-28T22:44:30.947-07:00\"","@timestamp":"2017-04-29T05:44:30.9
@dwbutler
dwbutler / constant.rb
Created January 4, 2017 15:37
Check where a constant got changed
class Config
CONSTANT = 1
def CONSTANT=(val)
fail
end
end
config = Config.new
config.CONSTANT = 2
@dwbutler
dwbutler / overwritten.rb
Last active January 4, 2017 04:52
Find where a variable is overwritten with a different value
class Config
attr_accessor :thing
def thing=(val)
raise ArgumentError if defined?(@thing)
@thing = val
end
end
config = Config.new
@dwbutler
dwbutler / appcanary.rb
Last active December 14, 2015 23:17
Appcanary gem interface
require 'appcanary'
Appcanary.configure do |config|
config.api_key = ENV['APPCANARY_API_KEY']
end
# Explicitly specify language and file
Appcanary.check(language: :ruby, file: 'Gemfile.lock')
# Autodetect Ruby as the language and Gemfile.lock as the file
# 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'
ActiveSupport::VERSION::STRING
# => "4.0.5"
@dwbutler
dwbutler / iso8601.rb
Last active July 7, 2024 06:33
Parsing ISO8601 Time format with Ruby
require 'time'
require 'benchmark'
time = Time.now.iso8601(3)
# => "2014-05-26T23:26:08.628-07:00"
Benchmark.bm do |x|
x.report('parse') { 100_000.times { Time.parse(time).gmtime } }
x.report('iso8601') { 100_000.times { Time.iso8601(time).gmtime } }
end