Skip to content

Instantly share code, notes, and snippets.

module Minesweeper
import Data.Fin
import Data.Vect
data Board : Type where
MkBoard : (rows : Nat) ->
(cols : Nat) ->
(mines : List (Fin rows, Fin cols)) ->
Board
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)
@dball
dball / gist:7ab19a5b3c348db6949c
Last active August 29, 2015 14:10
Panicky pipeline
(ns transduction
(:require [clojure.core.async :as async]))
(defn panicky
[pipeline-fn n to xf from]
(let [errors (atom #{})
ex-handler (fn [ex]
(async/close! from)
(swap! errors conj ex))
rf (remove (fn [_] (seq @errors)))
@dball
dball / gist:2cebfd9e7a815f813eff
Created August 2, 2014 15:19
core.async flow limiter
(ns dball.util.async
(:require [clojure.core.async :refer [go-loop >! <! timeout close! chan dropping-buffer >!! alts!]]
[clojure.tools.logging :as log])
(:import [java.util.concurrent Executors ScheduledExecutorService TimeUnit]))
(defn ^ScheduledExecutorService scheduler
[]
(Executors/newSingleThreadScheduledExecutor))
(defn ticker-chan
@dball
dball / debounce.clj
Last active December 19, 2015 03:19 — forked from swannodette/debounce.clj
(defn debounce [c ms]
(let [c' (chan)]
(go
(loop [t nil]
(let [loc (<! c)
now (js/Date.)]
(if (or
(nil? t)
(>= (- now t) ms))
(do
@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
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
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