Skip to content

Instantly share code, notes, and snippets.

View d11wtq's full-sized avatar

Chris Corbyn d11wtq

  • Melbourne, Australia
View GitHub Profile
; Returns a lambda, which for each invocation gives the next Fibbonnaci number
fib := { a := 0
b := 1
{ n := a
c := a + b
a = b
b = c
n } }
seq := fib:
class QueryParser < Whittle::Parser
rule(:wsp => /\s+/).skip!
rule("(")
rule(")")
rule("AND") % :left ^ 1
rule("OR") % :left ^ 1
rule(">") % :left ^ 2
class QueryParser < Whittle::Parser
rule(:wsp => /\s+/).skip!
rule("(")
rule(")")
rule("AND") % :left
rule("OR") % :left
rule(">") % :left ^ 1
@d11wtq
d11wtq / gist:1413222
Created December 1, 2011 03:19
Complex number representation of a decimal should be considered a real number, but is not.
[1] pry(main)> Complex("2.5")
=> (2.5+0i)
[2] pry(main)> Rational("2.5")
=> (5/2)
[3] pry(main)> Complex("2.5") == Rational("2.5")
=> true
[4] pry(main)> Complex("2.5").real?
=> false
[5] pry(main)> Rational("2.5").real?
=> true
require 'whittle'
class Parser < Whittle::Parser
class StringParser < Whittle::Parser
rule('"')
rule(:esc => /\\./).as { |esc| eval('"' + esc + '"') }
rule(:chars => /[^\\"]+/)
require 'whittle'
class Parser < Whittle::Parser
rule("class")
rule("(")
rule(")")
rule("{")
rule("}")
require "parslet"
class MiniP < Parslet::Parser
rule(:wsp) { match("\\s").repeat(1) }
rule(:wsp?) { wsp.maybe }
rule(:t_int) { match("[0-9]").repeat(1).as(:int) }
# this is causing Stack Level Too Deep
rule(:sum) { expr.as(:left) >> wsp? >> str("+") >> wsp? >> expr.as(:right) }
Failures:
1) Acquisto::ReflectiveRoutes with a model containing a 1:n relationship generates a route to fetch the child collection
Failure/Error: model.finalize
NameError:
Cannot find the child_model Invoice for Customer in invoices
# ./spec/unit/reflective_routes_spec.rb:11:in `block (2 levels) in <top (required)>'
context "given a simple model" do
let(:model) do
Class.new do
def self.name
"Customer"
end
include DataMapper::Resource
property :id, DataMapper::Property::Serial
context "given a simple model" do
let(:model) do
Class.new do
def self.name
"Customer"
end
include DataMapper::Resource
property :id, DataMapper::Property::Serial