Skip to content

Instantly share code, notes, and snippets.


Shannon Skipper havenwood

View GitHub Profile
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 transducers.rb
map = -> f {
-> rf {
-> acc, elem {
rf[acc, f[elem]]
square = -> n { n**2 }
add = -> acc, n { acc + n }
smarr /
Last active May 14, 2021
Truffle: Languages and Material
jhass /
Last active Jun 10, 2021
My Ruby setup on Archlinux

Ruby on Archlinux

I thought I would document my setup, since it's somewhat non-standard but working quite well for me.

What this does

  • Install major Ruby versions at their latest patch release
  • Allow to switch between them seamlessly
  • Use chruby
  • Encourage bundler usage
View gvl_release.rb
require 'fiddle'
class GVL
handle = Fiddle::Handle::DEFAULT
address = handle['rb_thread_blocking_region']
func = address, [Fiddle::TYPE_VOIDP,
havenwood /
Last active Dec 12, 2015
Entirely Unscientific Benchmark of Primes in Various Ruby Implementations

Unscientific Benchmark

The Benchmark

def is_prime? n
  (2...n).all? { |i| n % i != 0 }

def sexy_primes n
View tmux_cheatsheet.markdown

tmux cheatsheet

As configured in my dotfiles.

start new:


start new with session name:

View gist:3436258

How to use Ruby like PHP

If you're like me, you often want to stick a script on your web server and have it run. For that, PHP's pretty much your only option... right?


Here's a little trick I did today that I'd like to share. I'll assume you're running Apache.

Add the following to a .htaccess file in your document root:

ordinaryzelig /
Last active Sep 22, 2020
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
havenwood / xday.rb
Created Dec 1, 2011
Yesterday, Today, Tomorrow
View xday.rb
#!/usr/bin/env ruby
class Time
WEEKDAYS = %w[ Sunday Monday Tuesday Wednesday Thursday Friday Saturday ]
def day_before_yesterday
xday -2
def yesterday