Skip to content

Instantly share code, notes, and snippets.

View benkimball's full-sized avatar

Ben Kimball benkimball

View GitHub Profile
@benkimball
benkimball / exponential_backoff.rb
Created July 12, 2018 19:55
One approach to exponential backoff in Ruby
##
# Call +fn+ up to +retries+ times or until it does not raise a StandardError,
# returning its result. While exceptions are raised, wait an increasing interval
# between attempts. The interval will increase as k^N.
#
# Examples
# myfun = lambda { raise "failed" }
# backoff(myfun) # calls myfun at time = 0, 1, 4, 11, 26, 57s
# backoff(myfun, retries: 2, k: 1) # calls at time 0, 1, 3, 6, 10, 15s
@benkimball
benkimball / production_data_change.rb
Last active March 22, 2018 23:53
This is a (non-original) concept for a utility superclass for performing production data changes that defaults to a "dry_run" mode (though it relies on the subclass implementer to ensure safety).
# frozen_string_literal: true
# Looks for a keyword argument `dry_run`. If it is explicitly set to false,
# then run the actual data change. In all other cases, perform a dry run.
# Both #perform_real and #perform_dry_run are expected to be supplied by
# the subclass.
#
# Use a subclass of ProductionDataChange in this way:
# @example
# ExampleDataChange.new.perform(...)
@benkimball
benkimball / index.html
Last active January 13, 2017 21:21
Circle dragging with snap-to-edge
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Docking Bubbles</title>
<style type="text/css" media="screen">
.bubble {
stroke: steelblue;
stroke-width: 1;
fill: rgba(120, 40, 255, 0.3);
@benkimball
benkimball / .block
Last active June 1, 2016 19:35
Using d3's selection.call()
height: 300