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 \
#!/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
module ExponentialBackoffStrategyModule
module_function def call(exponent, value)
value ** exponent
end
end
class ExponentialBackoffStrategyClass
def initialize(exponent)
@exponent = exponent
end
#!/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

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.

@JonathonMA
JonathonMA / i18n_fallbacks.rb
Created January 21, 2014 23:39
Rails I18n fallback experiment
require "i18n/backend/fallbacks"
I18n::Backend::Simple.send :include, I18n::Backend::Fallbacks
I18n.backend.store_translations :en, test: {
no_translations: {
specific: "en specific",
generic: "en generic",
},
only_generic_translations: {
source 'https://rubygems.org'
gem 'fruity', '~> 0.2.0'
gem 'rubyzip', '1.1.0'
gem 'zippo', '0.2.0'