Skip to content

Instantly share code, notes, and snippets.

@benolee
benolee / method_lambda_proc_returns.rb
Last active December 11, 2015 04:18
method_lambda_proc_returns.rb
DATA.instance_eval { truncate pos.tap { reopen __FILE__, "a+" } }
$stdout = DATA
opts = [nil, nil, nil, trace_instruction: false]
puts "-----> returning from a compiled method"
puts RubyVM::InstructionSequence.new("def _return() return end", *opts).disasm
puts
puts "-----> returning from a lambda"
puts RubyVM::InstructionSequence.new("-> { return }", *opts).disasm
puts
@benolee
benolee / assignment_gotchas.rb
Created January 19, 2013 10:25
assignment gotchas
@counter = 0
def big_calculation
@counter += 1
end
private :big_calculation
heading "before local variable assignment, with implicit receiver"
item "big_calculation"
puts big_calculation
@benolee
benolee / rake_in_30_lines.rb
Created January 23, 2013 17:04
rake_in_30_lines.rb
require "set"
module RakeTask
CALLED = Set.new
NAMESPACES = []
TASKS = Hash.new { |h, k| h[k] = Struct.new(:blocks, :deps).new([], []) }
class << self
def call(name)
return if CALLED.include?(name)
@benolee
benolee / systemu.txt
Created January 28, 2013 21:21
systemu return type differences
$ cat Gemfile
source :rubygems
gem 'systemu'
$ cat wat.rb
require 'systemu'
p systemu 'ls', 'stdout' => '', 'stderr' => ''
$ rbenv shell jruby-1.6.7
$ bundle exec ruby wat.rb
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@benolee
benolee / _.md
Created February 25, 2013 20:56
General Update Pattern, III
# slide 77 from waza talk
# method definition with static scope, class eval'd in a string
# Environment
class Foo
hello = "world!"
define_method("foo") { hello }
class_eval "def bar; hello; end"
@benolee
benolee / readme.md
Created April 14, 2013 02:01 — forked from liluo/readme.md

init

mkdir proj
cd proj
git init

config

git config user.name 'username'
#!/usr/bin/env PeanutButterJellyTime
# -----------------------------------------------------------------------------
# keyword => C equiv (description)
# -----------------------------------------------------------------------------
# peanut => ++*ptr (increase value of cell)
# PEANUT => ++ptr (move to next cell)
# butter => --*ptr (decrease value of cell)
# BUTTER => --ptr (move to previous cell)
# jelly => putchar(*ptr) (print character value of cell)
# JELLY => *ptr=getchar() (store numeric value of char input in cell)
.DS_Store
tmp/