Skip to content

Instantly share code, notes, and snippets.

View JonathonMA's full-sized avatar

Jonathon M. Abbott JonathonMA

  • Brisbane, Australia
View GitHub Profile
time_range = Time.now .. Time.now
number_range = 1.0 .. 10.0
p time_range.cover? Time.now
p number_range.cover? 5.0
begin
time_range.to_a
rescue
puts "time_range is unenumerable"
module IPoint
attr_accessor :x, :y
end
module IReadonlyPoint
attr_reader :x, :y
end
module IReadonlyLine
attr_reader :source, :destination
class Evaluator
def evaluate &block
instance_eval &block
end
def upcase bar
bar.upcase
end
end
class Foo
class << self
def hello
"hello"
end
end
end
def singleton &block
singleton_class.class_eval &block
#!/usr/bin/env ruby
# pingpongninja_expected_results -- simulate a series of games on pingpongninja
#
# algorithm extracted from
# https://github.com/jdennes/pingpongapp/blob/master/pingpong/rankings.py
def new_ranks(rank1, rank2, points1, points2)
decay_factor = 10
game_ranking_points = (rank1 + rank2) / 2
ranking_change1 = game_ranking_points + (points1 - points2) * 100 / [points1, points2].max
ranking_change2 = game_ranking_points + (points2 - points1) * 100 / [points1, points2].max
#!/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] ..."
}
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/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
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;

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.