Skip to content

Instantly share code, notes, and snippets.

@jimweirich
jimweirich / mycmd.rb
Last active December 14, 2015 01:49
How Rake runs its top level.
# Sample custom rake-like command supporting three options.
#
# mycmd start
# mycmd stop
# mycmd restart
require 'rake'
Rake.application.init('mycmd')
@jimweirich
jimweirich / bad_triangle_matcher.rb
Created February 21, 2013 18:49
RSpec Bad Triangle Matcher
module RSpec::Matchers
matcher :be_a_bad_triangle do |expected|
match do |sides|
begin
TriangleClassifier.new.classify(*sides)
false
rescue ArgumentError => ex
true
end
end
# My take on Mike's source_for method.
# (see http://pragmaticstudio.com/blog/2013/2/13/view-source-ruby-methods)
#
# (1) I named it 'src' rather than source_for (ok, I'm a lazy typer).
# (2) The edit function was broken out as a separate function.
# (3) The edit function is for emacs
# (4) If the method is not defined on the object, and the object
# is a class, then see if it is an instance method on the class.
#
# The fourth point allows my to say:
@jimweirich
jimweirich / output.txt
Created January 29, 2013 17:56
Exploring several alternatives to iterating over a Then block.
$ rspec -fd thing_spec.rb
thing
matches thing a
Then { subject.should include thing }
matches thing b
Then { subject.should include thing }
matches thing c
Then { subject.should include thing }
matches thing d
@jimweirich
jimweirich / Rakefile
Last active December 11, 2015 05:18
I wanted to share this, but it's not quite ready to be a project yet. This is a Rake library to build Digispark applications. Currently this only supports DigiSpark arduinos, but when I find my Arduino starter kit, I want to make it work for that as well. Patches and suggestions are welcome.
# Sample Rakefile for the Digispark/Arduino build script
require './arduino'
# Create an arduino builder
Avr = Rake::Arduino.new do |cfg|
# There are lots of configuration options, but I don't know
# yet what ones will survive. At the very least you must
# specify the location of the of the Arduino IDE application
# that comes with the special DigiSpark support.
@jimweirich
jimweirich / approximately.rb
Last active December 10, 2015 21:29
Evidently I'm rusty on my Ruby coercion rules, because the following surprised me.
class ApproximateNumber
attr_reader :number, :delta
def initialize(number, delta)
@number = number
@delta = delta
end
def ==(value)
(number-value).abs <= delta
@jimweirich
jimweirich / output
Created December 27, 2012 14:55
Experimental version of RSpec/Given that handles should-less assertions (i.e. plain Ruby conditions).
1) Natural Assertions
Failure/Error: Then { foo + bar == 2 }
Then expression failed at /Users/jim/working/git/rspec-given/examples/failing/sample_spec.rb:6
expected: 3
to equal: 2
false <- foo + bar == 2
3 <- foo + bar
1 <- foo
2 <- bar
# ./lib/rspec/given/extensions.rb:64:in `_rg_evaluate'
@jimweirich
jimweirich / flog_stack.txt
Created December 19, 2012 17:02
Flog Stack Trace
/Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/ruby_parser-3.0.4/lib/ruby_parser_extras.rb:1292:in `process': wrong number of arguments (3 for 2) (ArgumentError)
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/flog-3.2.0/lib/flog.rb:296:in `flog_ruby!'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/flog-3.2.0/lib/flog.rb:266:in `flog_ruby'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/flog-3.2.0/lib/flog.rb:256:in `block in flog'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/flog-3.2.0/lib/flog.rb:253:in `each'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/flog-3.2.0/lib/flog.rb:253:in `flog'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/gems/flog-3.2.0/bin/flog:13:in `<top (required)>'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/bin/flog:19:in `load'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/bin/flog:19:in `<main>'
from /Users/jim/.rvm/gems/ruby-1.9.3-p286@visibill/bin/ruby_noexec_wrapper:14:in `eval'
@jimweirich
jimweirich / soap.txt
Created November 22, 2012 09:17
Results of an Informal Twitter Survey on the State of the Art for Ruby SOAP Clients
Today I ran a quick twitter poll asking: "What is the state of the art
in Ruby SOAP clients".
Savon (http://savonrb.com/) was by far the big winner with 29
recommendations.
Surprisingly Soap4r actually got 6 votes, but most were accompanied by
comments like "the last time I used SOAP". It was also the only entry
that got negative votes (3) with comments like "soap4r is broken and
crap by the way".
@jimweirich
jimweirich / gist:4052321
Created November 10, 2012 20:07
Rubinius - current head - Crash in Rake Thread Tests
Rubinius Crash Report #rbxcrashreport
Error: signal SIGILL
[[Backtrace]]
0 ruby 0x00000001021056d0 _ZN8rubiniusL12segv_handlerEi + 544
1 libsystem_c.dylib 0x00007fff912818ea _sigtramp + 26
2 ??? 0x0000000000000006 0x0 + 6
3 ruby 0x0000000102109848 _ZN8rubinius3bugEPKc + 72
4 ruby 0x00000001022481bc _ZN8rubinius6Object2idEPNS_5StateE + 94