Skip to content

Instantly share code, notes, and snippets.

# trust google cloud load balancer ips
config.action_dispatch.trusted_proxies = %w( { |proxy| }
branch = `git rev-parse --abbrev-ref HEAD`.strip rescue ENV.fetch("RAILS_DATABASE_SUFFIX", "master")
branch = branch.underscore.gsub(/[\.\/\-]/, '_')
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
host: <%= ENV.fetch("RAILS_DATABASE_HOST", "") %>
mattes / main.go
Created February 12, 2021 07:59
Quick HTTPS debug server
package main
import (
mattes /
Created February 10, 2021 23:20
Allow non-root binary to bind port 80 and 443
sudo setcap CAP_NET_BIND_SERVICE=+eip /path/to/binary
mattes / resque.rb
Created October 30, 2020 08:02
Resque in distroless docker container
# config/initializers/resque.rb
module Resque
class Worker
# Monkey patch linux_worker_pids because the original function tries to shell out.
# Since we run distroless in production, there is no shell.
def linux_worker_pids
mattes /
Last active June 7, 2024 08:56
My own Heroku in 30 mins

Deploy Rails apps to Google Cloud Compute Engine

  • Zero Downtime
  • Graceful shutdowns
  • Via Github Actions
  • Zero infrastructure management overhead


The general idea is to have Github Actions test, build and deploy a Rails app to Google Cloud Compute Engine.

docker system prune -a
docker rm $(docker ps -a -f status=exited -q)
mattes /
Created September 10, 2020 23:21
Get access token via curl for default service account on Google Cloud Compute Engine
ACCESS_TOKEN=$(curl -H 'Metadata-Flavor: Google' $SVC_ACCT/token | cut -d'"' -f 4)
gcloud config configurations list
gcloud config configurations activate MY_OLD_CONFIG
gcloud_switch xxx