Instantly share code, notes, and snippets.

View Gemfile
source "https://rubygems.org"
# ruby web server; run Sidekiq::Web with e.g. `puma --port=80`
# https://github.com/puma/puma
gem "puma"
# provides Sidekiq::Web monitoring UI
# https://github.com/mperham/sidekiq/wiki/Monitoring
gem "sidekiq", "~> 4.2"
View rack_header_renamer.rb
class RackHeaderRenamer
# mapping example, sets/overwrites second header with first:
# {"X-Varnish-Proto" => "X-Forwarded-Proto"}
def initialize(app, mapping)
@app = app
@mapping = mapping
end
def call(env)
View code.rb
require "bcrypt"
module GoTipping
class UserAuthenticator
def initialize(organisation, username, finder)
@organisation = organisation
@username = username
@finder = finder
end
View keybase.md

Keybase proof

I hereby claim:

  • I am pda on github.
  • I am pda (https://keybase.io/pda) on keybase.
  • I have a public key whose fingerprint is C01A 62C6 7093 CE6A 2C34 299A C902 25CE B876 8E7B

To claim this, I am signing this object:

View race.rb
#!/usr/bin/env ruby
require "open-uri"
require "benchmark"
def main
urls = ARGV
results = Queue.new
View ec2-lvm.sh
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
set -x
DEVICE_B="/dev/xvdb"
DEVICE_C="/dev/xvdc"
VG_NAME="ephemeral"
LV_NAME="ephemeral"
DEVICE_LV="/dev/$VG_NAME/$LV_NAME"
View base_script.rb
# A base class for implementing CLI scripts.
# ARGV and in/out IO's are injected, so can be mocked & tested.
# Basic signal handling by calling exit_on_signals inside work loops etc.
# Requires Ruby 2.0.0+ for keyword args etc.
class BaseScript
EXIT_SUCCESS = 0
INDENT = " "
def initialize(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr)
View git-push-as
#!/bin/bash -e
# Push local changes on the current branch as a new branch, then
# reset the local branch back to its remote tracking branch.
#
# This enables a fast workflow:
# 10 `git commit` one or more changes to master.
# 20 `git push-as -p new-feature`
# 30 goto 10
View docker-mysql-initialize.sh
#!/bin/bash
# Initialize MySQL database.
# ADD this file into the container via Dockerfile.
# Assuming you specify a VOLUME ["/var/lib/mysql"] or `-v /var/lib/mysql` on the `docker run` command…
# Once built, do e.g. `docker run your_image /path/to/docker-mysql-initialize.sh`
# Again, make sure MySQL is persisting data outside the container for this to have any effect.
set -e
set -x
View args.sh
#!/bin/bash
A=("$@")
X="$@"
echo; echo '"$@": <-- correct'
for arg in "$@"; do echo "$arg"; done
echo; echo '"${A[@]}": <-- correct'
for arg in "${A[@]}"; do echo "$arg"; done