Skip to content

Instantly share code, notes, and snippets.

View stevenharman's full-sized avatar

Steven Harman stevenharman

View GitHub Profile
stevenharman /
Last active May 23, 2024 04:43
Heroku Release Phase script for managing Rails DB migrations, and playing nice with Review Apps and postdeploy scripts

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.

stevenharman /
Last active May 17, 2024 21:20
Fork and promote one Heroku app's Postgres Database to another app.
set -e
old_db=`heroku config -a ${staging_app} | grep ^HEROKU_POSTGRESQL | cut -d : -f 1 | sed s/_URL//`
heroku addons:add heroku-postgresql:${db_type} --fork `heroku config -a ${app} | grep ^DATABASE_URL | cut -d : -f 2-5` -a ${staging_app}
stevenharman / jenkins-service-with-interactive.ps1
Created February 1, 2012 18:10
Allow a Windows service to interact with the desktop without being LocalSystem
# stolen from:
# NOTE: Be sure to run as Admin and restart to take effect.
$svcName = Get-Service -DisplayName *jenkins* | select -Exp Name
$svcKey = Get-Item HKLM:\SYSTEM\CurrentControlSet\Services\$svcName
# Set 9th bit, from
$newType = $svcKey.GetValue('Type') -bor 0x100
stevenharman / gemfresh
Last active December 29, 2023 16:05
gemfresh: A handy script for determining the freshness of dependencies in a Ruby code base. Leverages bundler and libyear-bundler.
#!/usr/bin/env bash
# shellcheck disable=SC2059
set -euo pipefail
stevenharman / .env
Last active September 7, 2023 15:56
Bug with ENV loading in Heroku CLI (dotenv, .env, .env.local, etc…)
BASE_ENV_VAR="value for base"
# Set a value specific to you in your .env.local
stevenharman / _dev_badge.html.slim
Created October 17, 2012 18:45
A simple badge that shows your Rails environment.
/ In app/views/shared/
span= Rails.env
span It ain't production!
stevenharman /
Created January 29, 2012 18:03
zshell startup files, in order. (because I always forget)
# if login shell
#if interactive shell
stevenharman / faraday-request-xml.rb
Created August 20, 2013 23:46
An example of a Request middleware to send the body as XML
module FaradayMiddleware
class XmlRequest < Faraday::Middleware
dependency do
require 'active_support/all'
def call(env)
if env[:method] == :post
body = env[:body]
first_key = body.keys.first
stevenharman /
Last active February 22, 2023 12:49
A Git Pre-Commit hook to run the Rubocop static code analyzer. I'm not saying this is a Good Idea™. In fact, it's a Bad Idea™; integrate linting/formatting with your editor/IDE instead. Use at your own risk. If it breaks, feel free to keep both pieces.
#!/usr/bin/env bash
set -eu
stevenharman / format-ruby
Created March 19, 2020 15:05
Run `standardrb --fix` as a git pre-commit hook. NOTE: this assumes `gem "standard"` is in your Gemfile
# This file is `.git/hooks/format-ruby` and it has been `chmod +x`'d
# Assumption: is in your Gemfile
set -e
rubyfiles=$(git diff --cached --name-only --diff-filter=ACM "*.rb" "*.rake" "Gemfile" "Rakefile" | tr '\n' ' ')
[ -z "$rubyfiles" ] && exit 0
# Standardize all ruby files