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 / irc_example.rb
Last active Dec 14, 2019
An example for IRC
View irc_example.rb
chars = str
.map(&:chars) { |char| }
havenwood / object.rb
Created Dec 6, 2019
Examples of defining methods and getting and setting instance variables on objects
View object.rb
foo =
def foo.value
#=> 42
bar =
havenwood / optional.rb
Created Dec 1, 2019
Playing with chaining #then on a Swift-like Optional
View optional.rb
# frozen_string_literal: true
class Optional
attr_reader :value
def initialize(value)
@value = value
def then(&block)
havenwood / async.rb
Created Nov 16, 2019
Example Async equivalent to code naftilos76's code that phaul is helping with on #ruby IRC:
View async.rb
require 'async'
condition =
Async do
task_one = Async do
loop do
puts 'task one before waiting'
havenwood / node.rb
Last active Nov 13, 2019
Playing with Enumerator.produce from Ruby 2.7
View node.rb
# frozen_string_literal: true
class Node
attr_reader :value
attr_reader :parent
def initialize(value:, parent: nil)
@value = value
@parent = parent
havenwood / erb.rb
Created Nov 12, 2019
Example YAML template for Net on #ruby channel IRC
View erb.rb
require 'erb'
require 'psych'
topic = :users
users = %w[wombat fox poodle]
template = <<~END, trim_mode: '-'
:<%= topic %>:
<%- users.each do |user| %>
havenwood / make_it_work.rb
Created Nov 7, 2019
An answer to crella133's question in #ruby IRC
View make_it_work.rb
class Foo
def initialize(a, b, c:)
puts 'Foo!'
class MakeItWork < Foo
def initialize(*args, **kwargs, &block)
parameters = method(__method__).super_method.parameters
View response_enumerator.rb
class ResponseEnumerator < Enumerator
attr_accessor :per_page
def initialize(square, http_verb:, path:, data:,
fields:, parameters: {}, memoize: true, per_page: nil)
@per_page = per_page || DEFAULT_PER_PAGE
@memoized_responses = []
@params = parameters.fetch :params
havenwood / cipher.rb
Created Nov 5, 2019
Ruby Example of AES-256 in CBC Mode for consti on #ruby IRC
View cipher.rb
secret = 'cicada'
key = 'wombat'
cipher = :CBC
salt = OpenSSL::Random.random_bytes 16
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1 key, salt, 20000, 32
iv = cipher.random_iv
havenwood / delegate_class.rb
Last active Oct 20, 2019
An example using DelegateClass with core Classes. For the why, see:
View delegate_class.rb
class FerretString < String
def to_s
'Successfully overrode ...'
class WombatString < DelegateClass(String)
def initialize
You can’t perform that action at this time.