Skip to content

Instantly share code, notes, and snippets.

View haileys's full-sized avatar

Hailey Somerville haileys

View GitHub Profile
# Method instrumentation decorator with Ruby 2.1's new "method definition returns method name" feature
class Module
def instrument(notification_name, mid)
meth = instance_method(mid)
define_method(mid) { |*args, &bk|
ActiveSupport::Notifications.instrument(notification_name) do
meth.bind(self).call(*args, &bk)
end
}
@haileys
haileys / Makefile
Created September 25, 2013 05:21 — forked from steveklabnik/Makefile
all: rust-for-rubyists.epub site
rust-for-rubyists.epub:
pandoc --toc -S -s --epub-metadata=book/metadata.xml -o rust-for-rubyists.epub book/title.txt book/preamble.md book/chapter-*.md
site:
pandoc -S -s book/preamble.md book/chapter-*.md -o book/book.html --include-before-body=book/header.html --include-after-body=book/footer.html
pandoc -S -s book/chapter-01.md -o book/chapter-01.html --include-before-body=book/header.html --include-after-body=book/footer.html
pandoc -S -s book/chapter-02.md -o book/chapter-02.html --include-before-body=book/header.html --include-after-body=book/footer.html
pandoc -S -s book/chapter-03.md -o book/chapter-03.html --include-before-body=book/header.html --include-after-body=book/footer.html
@haileys
haileys / eval.c
Created September 11, 2013 00:32
/************************************************
eval.c -
$Author: matz $
$Date: 1996/12/25 08:54:45 $
created at: Thu Jun 10 14:22:17 JST 1993
Copyright (C) 1993-1997 Yukihiro Matsumoto
class Module
def dispatch(*klasses, last)
last_klass, mid = last.first
klasses << last_klass
__dispatch_list << [klasses, instance_method(mid)]
define_method(mid, __dispatch_proc(__dispatch_list))
end
def __dispatch_list
@__dispatch_list ||= []
#include <ruby.h>
typedef struct {
int foo;
}
my_data_t;
static void
my_data_mark(void* ptr)
{
/************************************************
eval.c -
$Author: matz $
$Date: 1996/12/25 08:54:45 $
created at: Thu Jun 10 14:22:17 JST 1993
Copyright (C) 1993-1997 Yukihiro Matsumoto
def load_yaml_properly(yaml)
YAML.load yaml
rescue ArgumentError => e
raise e unless e.message =~ /undefined class\/module (.*)/
$1.constantize
retry
end
chan = Channel.new
4.times do |i|
go 4.times { |j|
chan <- "#{i} #{j}"
}
end
16.times do
puts <-chan
def filter_output!
r, w = IO.pipe
fork do
w.close
until r.eof?
line = r.gets
next if line =~ /^Started GET/
puts line
end
end
@haileys
haileys / trololol.rb
Last active December 21, 2015 06:29 — forked from tenderlove/trololol.rb
module Kernel
def int(mid)
meth = instance_method(mid)
define_method(mid) { |*args, &bk|
val = meth.bind(self).call(*args, &bk)
raise TypeError, "#{mid} did not return an Integer" unless val.is_a? Integer
val
}
mid
end