Skip to content

Instantly share code, notes, and snippets.

@pcreux
pcreux / clone-heroku-app
Last active December 14, 2023 14:33
Script to clone a heroku app (including buildpacks, users, add-ons, environment variables, lab features)
#!/usr/bin/env ruby
# Copy a heroku app (buildpacks, add-ons, labs, config, users).
# This script is idempotent so it can run against an existing app.
#
# Usage:
# $> clone-heroku-app source-app target-app
require 'json'
@pcreux
pcreux / README.md
Last active October 10, 2020 18:44
Failsafe: degrade user experience and notify when something goes wrong.

Failsafe

When something goes wrong I want to degrade the user experience (instead of returning a 500 - Server Error) And I want to be notified about the failure

Usage

Wrap non mission critical code:

@pcreux
pcreux / circleci-trace
Created November 21, 2019 19:42
Generate a trace of your circleci workflows
#!/usr/local/env ruby
#
# Generate html traces from CircleCI workflows
#
require 'json'
require 'http'
OWNER = 'githubowner'
REPO = 'githubrepo'
@pcreux
pcreux / format_bundle_outdated.rb
Created May 31, 2019 18:30
Format 'bundle outdated' into a CSV file ordered by version delta
#!/usr/bin/env ruby
#
# Run `bundle outdated | format_bundle_outdated`
# to get a CSV file listing the columns below for all outdated gems.
COLUMNS = [ "name", "newest", "installed", "requested", "groups", "delta" ].join(",")
class Version < Struct.new(:major, :minor, :patch, :beta)
def self.build(string)
new(*string.split('.').map(&:to_i))
@pcreux
pcreux / 000 Oh no conditionals!.png
Last active June 6, 2018 19:26
Turning imperative conditionals into declarative rules
000 Oh no conditionals!.png
@pcreux
pcreux / Gemfile
Created April 19, 2018 16:53
Minimal setup to run a static site on Heroku.
# no ruby gems required
@pcreux
pcreux / extract-migration
Created October 6, 2017 20:49
Extract all new migrations from the current branch over to a new branch (suffixed with "-migration")
#!/bin/sh
# Extract all new migrations from the current branch over to a new branch (suffixed with "-migration")
set -ev
export branch=`git rev-parse --abbrev-ref HEAD`
git checkout master
git pull
git checkout -b $branch-migration
git checkout $branch -- db engines/*/db
@pcreux
pcreux / rtt
Last active March 30, 2021 22:27
Run tests for all changed app, lib and test files
#!/usr/bin/env ruby
# Run unit test for all added or changed app, lib and test files.
# Ex:
# * `rtt` will run tests for all files changed since the last commit
# * `rtt master` will run tests for all files different from master
if ARGV[0]
files = `git diff --name-only $(git merge-base HEAD #{ARGV[0]})..$(git rev-parse --abbrev-ref HEAD)`.split("\n")
else
files = `git status -s`.split("\n").map { |f| f.split(' ').last }
@pcreux
pcreux / mktest
Created June 14, 2017 18:26
Generate a test file. `mktest app/models/user.rb` => `test/models/user_test.rb`
#!/usr/bin/env ruby
DESC = "
Generate test file
Example: mktest app/services/user/create.rb will generate test/services/user/create_test.rb
"
@pcreux
pcreux / 000_robust_rails_apps.md
Last active May 14, 2018 04:38
Robust Rails Apps - VanRuby - March 29, 2017

Robust Rails Apps

Philippe Creux - @pcreux

#vanruby - March 29th, 2017