Skip to content

Instantly share code, notes, and snippets.

type Point a = (a, a)
type PointFn a = ((a -> a), (a -> a))
data Board a = Board { boardMin :: Point a,
boardMax :: Point a }
deriving (Show)
makeBoard :: (Enum a, Ord a) => Point Int -> Board a
makeBoard (x, y) = Board (z, z) (toEnum x, toEnum y)
where z = toEnum 0
module Minesweeper
import Data.Fin
import Data.Vect
data Board : Type where
MkBoard : (rows : Nat) ->
(cols : Nat) ->
(mines : List (Fin rows, Fin cols)) ->
Board
@dball
dball / gist:3880743
Created October 12, 2012 18:39
Patch Geokit to work with SQL Server
module Geokit::ActsAsMappable::ClassMethods
# Distance is selected as an aliased expression, and we want to be able to
# use the alias in our order clause. SQL Server has no problem with that
# normally, but when the adapter rewrites the query in order to support
# pagination, it tries to use the alias. Unfortunately, the alias is invalid
# in the rewritten query; we need to use the expression.
#
# https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/198
#
# This extension overrides the order method on the relation to inline
@dball
dball / gist:2434109
Created April 21, 2012 04:58
Time Zone Madness

BROKEN

(rdb:1) value.getutc.iso8601(3)
ArgumentError Exception: wrong number of arguments (1 for 0)
(rdb:1) value
Sun, 18 Nov 2007 03:56:07 EST -05:00
(rdb:1) value.class.ancestors
[ActiveSupport::TimeWithZone, Comparable, Object, Metaclass::ObjectMethods, Mocha::ObjectMethods, PP::ObjectMixin, MiniTest::Expectations, FactoryGirl::Syntax::Vintage, Rake::DeprecatedObjectDSL, JSON::Ext::Generator::GeneratorMethods::Object, ActiveSupport::Dependencies::Loadable, Base64::Deprecated, Base64, Kernel]
(rdb:1) value.class
ActiveSupport::TimeWithZone
module Minesweeper
-- row, col
Point : Type
Point = (Nat, Nat)
-- rows, cols, mines (should be a set; should be constrained to rows/columns)
Board : Type
Board = (Nat, Nat, List Point)
def xml_equal?(*args)
return nil if args.empty?
docs = args.map do |xml|
Nokogiri.XML(xml) { |config| config.strict }
end
signatures = docs.map do |doc|
Lorax::Signature.new(doc.root).signature
end
signatures.uniq.length == 1
end
ruby-1.9.2-p136 :004 > URI.parse(value)
URI::InvalidURIError: bad URI(is not URI?): data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7
from /Users/dball/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/uri/common.rb:156:in `split'
from /Users/dball/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/uri/common.rb:174:in `parse'
from /Users/dball/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/uri/common.rb:628:in `parse'
from (irb):4
from /Users/dball/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `<main>'
ruby-1.9.2-p136 :005 > ^D
class Deal
attr_accessor :clubs
def initialize
@players = (1..4)
@clubs = Array.new(13, @players.first)
end
def succ!
require File.dirname(__FILE__) + '/spades'
require 'minitest/autorun'
describe Deal do
before do
@deal = Deal.new
end
it "should default to 13 clubs dealt to the first player" do
Factory.define(:passing_inspection_estimate, :parent => :estimate_with_items) do |f|
f.after_create do |e|
e.items << Factory(:estimate_item, :estimate => e, :inspection => true, :op => Factory(:inspection_op, :dealer => e.dealer)).tap do |item|
inspection = item.inspections.first
location = inspection.locations.first
outcome = inspection.failures.detect { |outcome| outcome.performed }
location.create_data!(:inspection_failure_id => outcome.id, :created_by => 'factory')
end
end
end