Skip to content

Instantly share code, notes, and snippets.


Shannon Skipper havenwood

View GitHub Profile
havenwood / oh_dear.rb
Created Jan 13, 2021
An, ahem, answer, of sorts for how to change default IRB colors (irc question)
View oh_dear.rb
changes = {IRB::Color::BLUE => IRB::Color::YELLOW}
IRB::Color.const_get(:TOKEN_SEQ_EXPRS).tap do |token_seq_exprs|
changes.each do |old_color, new_color|
token_seq_exprs.filter_map do |type, ((color, _), _)|
color == old_color && type
end.each do |matching_type|
token_seq_exprs.dig(matching_type, 0)[0] = new_color
havenwood / fetch.rb
Last active Dec 24, 2020
My little script to download Ruby source files in parallel with Async
View fetch.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'async'
require 'async/barrier'
require 'async/http/client'
require 'async/http/endpoint'
require 'async/logger'
require 'optionparser'
havenwood / blocks.rb
Created Dec 4, 2020
Examples to illustrate what `yield` does in Ruby
View blocks.rb
# Examples without block arguments
def example_without_block(function) + 'ay'
example_without_block ->{ 'ok' }
#=> "okay"
def example_explicit_block(&block) + 'ay'
View paint
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
require 'optionparser'
KEYWORDS = %i[color metadata glow_in_the_dark coats].freeze
DEFAULTS = {coats: 3, glow_in_the_dark: true}.freeze
View cistercian.rb
# frozen_string_literal: true
module Cistercian
LINE = %w[ ].freeze
CENTER_DOT = ' ■ '
[' ',
' ',
' '],
View gross_weight.rb
class GrossWeight
include Comparable
attr_reader :value
def initialize(value)
@value = value
def <=>(other)
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
View async_fetch.rb
require 'async'
require 'async/barrier'
require 'open-uri'
def async_fetch(*urls)
barrier =
Async do do |url|
barrier.async { url, &:read }
havenwood / .pryrc
Created Sep 17, 2020
My `~/.pryrc` file
View .pryrc
Pry.config.prompt = Pry::Prompt[:simple]
Pry.config.pager = false
# Support refinements at top level in Pry.
Pry.hooks.add_hook :when_started, :context_switch do |_output, _binding, pry|
pry.binding_stack = [TOPLEVEL_BINDING]
havenwood /
Created Nov 27, 2012
On Debian, Ubuntu, or Mint: install Ruby with chruby and ruby-build
# Install apt-get packages:
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
# Install chruby:
tar -xzvf chruby-0.2.3.tar.gz
cd chruby-0.2.3
sudo make install