Skip to content

Instantly share code, notes, and snippets.

View blambeau's full-sized avatar

Bernard Lambeau blambeau

View GitHub Profile
describe 'with an array with non bytes', ->
arg = [2, 4, -12]
subject =
try
type.dress(arg)
catch e
e
it 'should raise an error', ->
@blambeau
blambeau / gist:2960784
Created June 20, 2012 16:28
Path coercible
def source_text(arg)
case arg
when IO then arg.read
when Path then Path(arg).read
else
raise "Unable to find source text for `#{arg}`"
end
end
@blambeau
blambeau / gist:1612013
Created January 14, 2012 16:51
epath test failures under mingw
Run options: exclude {:fails_on=>#<Proc:./spec/spec_helper.rb:32>, :unix=>false, :symlink=>false, :ruby=>#<Proc:./spec/spec_helper.rb:27>}
........FF...........................F.F.....F..FF...........F.....F......F...............................................
Failures:
1) Path implementation realpath
Failure/Error: not_exist.make_symlink('not-exist-target')
NotImplementedError:
symlink() function is unimplemented on this machine
# ./lib/epath/file.rb:65:in `symlink'
@blambeau
blambeau / Gemfile
Created January 13, 2012 13:54
Temple uninitialized constant Temple::Mixins::CompiledDispatcher
source :rubygems
gem "temple"
@blambeau
blambeau / Gemfile
Created January 13, 2012 13:22
Inheritance with multiple Citrus grammars
source :rubygems
gem "citrus"
gem "rspec"
@blambeau
blambeau / Gemfile
Created December 14, 2011 10:54
jquery-sinatra-streaming
source "http://rubygems.org/"
gem "sinatra", "~> 1.3.0"
gem "thin"
@blambeau
blambeau / client.rb
Created November 22, 2011 09:15
Thin test
require 'http'
NB = 5
times = []
threads = (0..NB).map do |i|
Thread.new(i) {|nb|
t1 = Time.now
puts Http.get("http://127.0.0.1:3000")
t2 = Time.now
times[nb] = (t2-t1)
@blambeau
blambeau / destr.rb
Created November 22, 2011 09:00
Fun destructuring in Ruby 1.9
class Hash
def with(&block)
block.call *block.parameters.map{|x| self[x.last]}
end
end
# Example
h = {:name => "blambeau", :hobby => "ruby"}
@blambeau
blambeau / Gemfile
Created October 18, 2011 17:39
Auto-update ruby script
gem "grit", :git => "git@github.com:blambeau/grit.git"
@blambeau
blambeau / gist:1269769
Created October 7, 2011 08:28
Wlang dialect
require 'wlang'
$vars = []
dialect = WLang::dialect do
rule "#" do |parser, offset|
varname, reached = parser.parse(offset)
$vars << varname
["#{varname}", reached]