Skip to content

Instantly share code, notes, and snippets.


Eric Hodel drbrain

Block or report user

Report or block drbrain

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
drbrain / Many runs
Last active May 17, 2019
benchmark/ips can mislead you
View Many runs
Warming up --------------------------------------
range 60.821k i/100ms
args 63.056k i/100ms
Calculating -------------------------------------
range 774.236k (± 7.5%) i/s - 3.893M in 5.057747s
args 797.590k (± 6.0%) i/s - 3.973M in 5.000220s
Warming up --------------------------------------
range 64.468k i/100ms
args 65.528k i/100ms
Calculating -------------------------------------
View nesting.rb
module A
module B
puts "module B inside module A nesting: #{Module.nesting}"
def show_nesting
puts "show_nesting nesting: #{Module.nesting}"
drbrain / Z̤̯̤͈̲̠͋͟A̷̞͌̍̆̓L̺̙͖G̜̣̱̃̍́ͮO̤͙̫͔̔́̏͐̇͡.rb
Created Dec 1, 2017
color Z̤̯̤͈̲̠͋͟A̷̞͌̍̆̓L̺̙͖G̜̣̱̃̍́ͮO̤͙̫͔̔́̏͐̇͡
View Z̤̯̤͈̲̠͋͟A̷̞͌̍̆̓L̺̙͖G̜̣̱̃̍́ͮO̤͙̫͔̔́̏͐̇͡.rb
def color(i)
color = 16 + (i * 13) % 216
5.times { puts }
zalgo = "Z̤̯̤͈̲̠͋͟A̷̞͌̍̆̓L̺̙͖G̜̣̱̃̍́ͮO̤͙̫͔̔́̏͐̇͡!̷͙͉͖̋ͩ̓̇̿"
drbrain / ugh.rb
Last active Nov 9, 2017
You can't use `enum_for __method__` with inheritance 😢
View ugh.rb
class A
def m(&block)
#return enum_for __method__ unless block_given?
# The above calls the B implementation of #m so instead we have to create
# our own Enumerator that's bound to this class' method so we can run the
# with-block version of this method
unless block_given? then
enum = do |yielder|
method = A.instance_method(__method__).bind self
drbrain / run
Created Nov 2, 2017
Don't convert hash keys, it's slower than using the "natural" key of the input data
View run
$ ruby -v t.rb
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17]
Warming up --------------------------------------
Symbol Hash, Symbol Key
259.197k i/100ms
String Hash, String Key
231.953k i/100ms
Symbol Hash, String Key
203.959k i/100ms
#!/usr/bin/env bash
set -e
[ -n "$DEBUG" ] && set -x
banner() { printf -- "-----> $*\n"; }
banner "Restarting VMware networking"
banner "Stopping networking"
sudo /Applications/VMware\ --stop
View cross.rake
require 'rake/tasklib'
require 'rake/clean'
# Creates a cross-compiled library that mruby-cli can use to link with
# each cross-built command.
# "curl" do |cross|
# cross.release_name = "curl-7.28.0"
# cross.url = "https://curl.example/download/#{cross.release}.tar.gz"
drbrain / include_module.rb
Created Jul 29, 2016
Two ways of testing modules with Minitest
View include_module.rb
class TestMyModule < Minitest::Test
include MyModule
def test_method_from_my_module
actual = method_from_my_module input_data
assert_equal 'something', actual
View foo.rb
#!/usr/bin/env ruby
numbers = (1..100).to_a
numbers.each do |n|
div_5 = n.divmod(5)
div_7 = n.divmod(7)
message =
if div_5 and div_7 then
drbrain / Rakefile
Created Jun 9, 2016
Rake sh capabilities
View Rakefile
task default: %w[shellmode shellmode_ENV direct io]
task :shellmode do
sh "echo hello world"
task :shellmode_ENV do
env = {
'MESSAGE' => 'hello world',
You can’t perform that action at this time.