Skip to content

Instantly share code, notes, and snippets.

View stevenharman's full-sized avatar

Steven Harman stevenharman

View GitHub Profile
@stevenharman
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:
# http://lostechies.com/keithdahlby/2011/08/13/allowing-a-windows-service-to-interact-with-desktop-without-localsystem/
#
# 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 http://www.codeproject.com/KB/install/cswindowsservicedesktop.aspx
$newType = $svcKey.GetValue('Type') -bor 0x100
@stevenharman
stevenharman / 00_Heroku-Release-Phase-Review-Apps-Rails_README.md
Last active March 11, 2024 04:11
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
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
RED='\033[0;31m'
GREEN='\033[0;32m'
NO_COLOR='\033[0m'
CLEAR_LINE='\r\033[K'
@stevenharman
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
OTHER_ENV_VAR=
@stevenharman
stevenharman / _dev_badge.html.slim
Created October 17, 2012 18:45
A simple badge that shows your Rails environment.
/ In app/views/shared/
#dev-badge
span= Rails.env
span It ain't production!
@stevenharman
stevenharman / fork_db.sh
Last active July 6, 2023 15:07
Fork and promote one Heroku app's Postgres Database to another app.
#!/bin/sh
set -e
app=${1}
staging_app=staging-${app}
db_type=${2:-crane}
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
stevenharman / zsh_startup_files.sh
Created January 29, 2012 18:03
zshell startup files, in order. (because I always forget)
/etc/zshenv
~/.zshenv
# if login shell
/etc/zprofile
~/.zprofile
#if interactive shell
/etc/zshrc
~/.zshrc
@stevenharman
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'
end
def call(env)
if env[:method] == :post
body = env[:body]
first_key = body.keys.first
@stevenharman
stevenharman / pre-commit.sh
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
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NO_COLOR='\033[0m'
CLEAR_LINE='\r\033[K'
@stevenharman
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
#!/bin/sh
# This file is `.git/hooks/format-ruby` and it has been `chmod +x`'d
# Assumption: https://github.com/testdouble/standard 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