Skip to content

Instantly share code, notes, and snippets.

View pda's full-sized avatar
💾
Formatting…

Paul Annesley pda

💾
Formatting…
View GitHub Profile
@pda
pda / poorman
Last active February 16, 2024 00:00
poorman: a Procfile runner for tmux, in terrible bash
#!/bin/bash
set -e -o pipefail -u
# Launches each Procfile service as a tmux pane in a background window.
# The window is created if it doesn't already exist.
# Panes are created on demand, and existing panes are restarted if stopped.
WINDOW_NAME="poorman"
if [[ ${1:-} == "stop" ]]; then
@pda
pda / hash_search.rb
Created September 15, 2022 11:32
Ruby recursive Hash search
haystack = {
action: "greeting",
scope: "world",
things: [
{ x: "city" },
{ x: "country" },
{ x: "world" },
]
}
@pda
pda / goreman-tmux
Created December 14, 2021 09:34
Idempotently launches each Procfile service as a tmux pane in a background window. Cursed dense bash hacks 🐉
#!/bin/bash
set -e -o pipefail -u
# Launches each Procfile service as a tmux pane in a background window.
# The window is created if it doesn't already exist.
# Panes are created on demand, and existing panes are restarted if stopped.
WINDOW_NAME="goreman"
tmux new-window -adS -n $WINDOW_NAME
@pda
pda / inline_file.rb
Last active September 14, 2020 04:01
A basic !InlineFile YAML tag/function resolver for inlining Lambda into CloudFormation; assumes two-space indentation
PATTERN = %r{
^
(?<indent>\s*)
(?<key>\S+):
\s*
!InlineFile
\s*
(?<file>.*)
$
}x
@pda
pda / README.md
Last active November 12, 2018 13:25
Demonstrate that queue time is not included in Unicorn's request timeout

Unicorn timeout test

Demonstrate that queue time is not included in Unicorn's timeout

Output

$ ruby unicorn_timeout_test.rb
starting unicorn {:worker_processes=>2, :timeout=>3}
[client] concurrently requesting /sleep/6, /sleep/4, /sleep/2, /sleep/0
@pda
pda / Gemfile
Created January 23, 2017 03:52
Sidekiq::Web v4.2 (no longer on Sinatra) with GitHub OAuth
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"
@pda
pda / rack_header_renamer.rb
Created May 25, 2016 06:44
RackHeaderRenamer middleware for Rack; copy a request header to a different name before Rails etc sees it. e.g. config.middleware.insert(0, RackHeaderRenamer, "X-Varnish-Proto" => "X-Forwarded-Proto")
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)
require "bcrypt"
module GoTipping
class UserAuthenticator
def initialize(organisation, username, finder)
@organisation = organisation
@username = username
@finder = finder
end
@pda
pda / keybase.md
Last active March 15, 2017 01:59
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:

@pda
pda / race.rb
Created November 18, 2014 01:53
thumbor_aws async/blocking debugging.
#!/usr/bin/env ruby
require "open-uri"
require "benchmark"
def main
urls = ARGV
results = Queue.new