Skip to content

Instantly share code, notes, and snippets.

View JonathonMA's full-sized avatar

Jonathon M. Abbott JonathonMA

  • Brisbane, Australia
View GitHub Profile
class Foo
def bar
puts "bar"
end
end
require "did_you_mean"
class LuckyProxy < SimpleDelegator
ReallyNoMethodError = Class.new(StandardError)
# https://github.com/ruby/ruby/blob/202bbda2bf5f25343e286099140fb9282880ecba/lib/uri/generic.rb#L1397
# https://github.com/ruby/ruby/blob/6219b68fb53a77a221f615d47dde83fea0a7e7c8/lib/uri/common.rb#L19
# + Marshal
# = :(
require 'uri'
url = URI("https://example.com")
deserialized = Marshal.load Marshal.dump(url)
require 'money'
class Apples
def initialize(count)
@count = count
end
def zero?
@count.zero?
end
#!/bin/bash
cat > Dockerfile << EOF
FROM debian:jessie
ENV APPDIR=/srv/app
VOLUME \$APPDIR
WORKDIR \$APPDIR
RUN \
module ExponentialBackoffStrategyModule
module_function def call(exponent, value)
value ** exponent
end
end
class ExponentialBackoffStrategyClass
def initialize(exponent)
@exponent = exponent
end

We have a set of serialized tasks that occasionally fail. When this happens we usually retry from the start. The failures are usually transient, so the second attempt will usually succeed. However, we start again from the beginning, so we pay the cost of redoing all the tasks. Because the errors are transient, if we could retry in-line these transient errors would not abort the entire pipeline.

Let's try introducing retry(1) to allow us to specify a managed execution.

var events = require('events');
var simpleBus = new events.EventEmitter();
var strictlyOrderedBus = {};
strictlyOrderedBus.bus = simpleBus;
strictlyOrderedBus.emit = function(evt) { setImmediate(this.bus.emit.bind(this.bus), evt); }
strictlyOrderedBus.on = simpleBus.on
var globalBus;
#!/bin/bash
# ansible-vault-git-diff -- show what changed in a vaulted file at a specific commit
commit="$1"
file="$2"
if [ -z "$2" ]; then
echo "Usage: $0 <commit> <file>"
exit 1
fi
require 'fruity'
def bench(desc)
puts desc
Fruity.compare do
time_now { Time.now; nil }
time_now_utc { Time.now.utc; nil }
end
end
#!/bin/sh
# get-freaky -- FREAK toolkit
set -e
usage() {
echo "`basename $0` scan [host:port] [host2:port2] ..."
echo "`basename $0` cipher [host:port] [host2:port2] ..."
}