Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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: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 / 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)))
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)
module Minesweeper
import Data.Fin
import Data.Vect
data Board : Type where
MkBoard : (rows : Nat) ->
(cols : Nat) ->
(mines : List (Fin rows, Fin cols)) ->
Board
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
TypeResolver
(resolve-types [_]))
(extend-protocol TypeResolver
clojure.lang.Keyword
(resolve-types [type]
(when-let [spec (spark.spec-tacular/get-spec type)]
(resolve-types spec)))
clojure.lang.Var
(resolve-types [var]
@dball
dball / datomic-txn-fns.clj
Created January 12, 2016 21:16
Trouble with datomic transaction fns
(deftxnfn increase-book-quality
[db eid attr quality]
(do
(assert (= :book/quality attr))
(if (q '[:find ?eid .
:in $ ?ords ?eid ?quality'
:where
[?eid :book/quality ?quality-eid]
[?quality-eid :db/ident ?quality]
[(get ?ords ?quality' -1) ?ord']