Skip to content

Instantly share code, notes, and snippets.


Shannon Skipper havenwood

Block or report user

Report or block havenwood

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
havenwood / sig.rb
Created Oct 1, 2019
An example for Nathanael7 on #ruby IRC
View sig.rb
def sig(method_name)
meth = method(method_name)
parameters = do |type, name|
case type
when :req
when :rest
when :opt
# Unknown default argument.
havenwood / spike.rb
Created Sep 29, 2019
A spike showing compiling IR binaries for all gems
View spike.rb
# frozen_string_literal: true
require 'fileutils'
require 'find'
require 'zlib'
binaries_dir = File.join Gem.dir, 'binaries'
gems_dir = File.join Gem.dir, 'gems'
Dir['*/', base: gems_dir].each do |gem|
havenwood / heater.rb
Created Sep 26, 2019
Response to nima_m on #ruby IRC asking how to implement this state machine in Ruby:
View heater.rb
# frozen_string_literal: true
class Heater
s1: {heater: false, cooler: false},
s2: {heater: false, cooler: true},
s3: {heater: true, cooler: false}
attr_reader :state
havenwood / user_agents.rb
Created Sep 20, 2019
Sample a popular User-Agent based on its likelihood according to Sept 20, 2019 data from
View user_agents.rb
require 'psych'
module UserAgent
USER_AGENTS = Psych.load_file 'user_agents.yml'
def sample
target = rand
havenwood / autovivicious.rb
Created Sep 10, 2019
An example of an autovivifying Hash refinement in Ruby.
View autovivicious.rb
module Vivification
refine Hash.singleton_class do
def new(*args, autovivify: false, &block)
return if autovivify
super(*args, &block)
havenwood / missing_extensions.rb
Created Aug 22, 2019
Response to IRC question
View missing_extensions.rb
require 'bundler'
def lockfile
Bundler.read_file Bundler.default_lockfile
def lockfile_gems do |spec|
[, spec.version ]
havenwood / keyword_curry.rb
Created Aug 20, 2019
A little spike on implementing currying for keyword arguments after reading:
View keyword_curry.rb
# frozen_string_literal: true
module KeywordCurry
refine Method do
def curry(curry_arity = nil)
refine Proc do
havenwood / enumerable.rb
Created Jul 31, 2019
Enumerable and Enumerator examples for Technodrome on IRC
View enumerable.rb
class Technodrome
include Enumerable
def each
yield :fee
yield :fi
yield :fo
yield :fum
havenwood / ascii_art_png.rb
Created Jul 4, 2019
A quick spike to turn ascii art into a png
View ascii_art_png.rb
# frozen_string_literal: true
require 'chunky_png'
ascii = <<~ASCII
@@@@@@ @@@@@@
@@@@@@@@@@ @@@@@@@@@@
@@@@@@@@@@@@@@ @@@@@@@@@@@@@@
havenwood / base58.rb
Created Jun 28, 2019
Example Base58 Implementation (showing haxx0r> on #ruby irc)
View base58.rb
module Base58
CHARACTERS = [*?1..?9, *?a..?k, *?m..?z, *?A..?H, *?J..?N, *?P..?Z].freeze
def encode(n)
chars = []
while n >= 58
chars.unshift BASE58_CHARACTERS[n % 58]
You can’t perform that action at this time.