Skip to content

Instantly share code, notes, and snippets.

@lynaghk
lynaghk / gist:3335154
Created August 12, 2012 22:56
content-based pubsub via core.match. Faster than I expected!
(ns crossfilter.busses
(:use-macros [c2.util :only [p pp]]
[clojure.core.match.js :only [match]]
[crossfilter.macros :only [subscribe!]])
(:require [clojure.string :as str]
[goog.pubsub.PubSub :as goog.pubsub.PubSub]
[goog.object :as gobj]))
(set! *print-fn* #(.log js/console %))
@lynaghk
lynaghk / 0-update.md
Last active July 5, 2022 13:33
Angular.js from ClojureScript
@lynaghk
lynaghk / 1-rewrite_usage.clj
Created November 2, 2012 20:30
Questions about fancy map rewriting via core.logic
(rewrite-layer
{:mapping {:y :mpg}
:stat (stat/quantiles)})
;; =>
{:mapping {:upper :q75, :min :min, :lower :q25, :max :max, :middle :q50, :y :mpg}
:stat #com.keminglabs/c2po$stat$quantiles {:dimension :mpg}
:geom #com.keminglabs/c2po$geom$boxplot {}}
@lynaghk
lynaghk / gist:4116442
Created November 20, 2012 06:46
Possible syntaxes for flexible unifier w/ multi-lvar constraints
;;Support for simple constraints on lvars during unification was added in 76fd4d7c:
;;
;; https://github.com/clojure/core.logic/commit/76fd4d7c155161d74ad5cd8d87955148eece1fe0
;;
;;but these constraints apply to a single lvar only.
;;The unifier could support more general constraints if it accepted an explicit predicate function.
;;For instance, given this `data-numeric?` predicate and `spec` data:
(defn data-numeric? [data dimension]
@lynaghk
lynaghk / 0-build-opencv.sh
Created December 2, 2012 20:30
OpenCV in Clojure?
#Build OpenCV and the new Java JNI interface described here: https://github.com/emchristiansen/opencv/commit/0d323087fadaf931dbaf4120b69f0839b745b888
git clone git://github.com/Itseez/opencv.git
cd opencv
cmake -DBUILD_opencv_java=ON
ant jar
@lynaghk
lynaghk / gist:4210677
Created December 5, 2012 00:28
Metaprogramming EDN in ruby
#Idiomatic record constructors in Ruby
#My C2PO grammar of graphics uses records (typed maps, basically) to represent pieces of the grammar.
#E.g., in Clojure you can specify a linear scale via a constructor function:
#
# (scale/linear :domain [0 10] :label "The X Axis")
#
#returns the appropriate scale.linear record with the two key/value pairs given above.
@lynaghk
lynaghk / gist:4711249
Created February 5, 2013 01:07
EDN v. JSON deserialization speed (including JSON 'tagged literals')
(ns scratch.main
(:use-macros [c2.util :only [p pp]]
[serialization :only [test-data]])
(:require [cljs.reader :refer [read-string]]
[goog.date.DateTime :as DateTime]
[clojure.string :as str]))
(defn parse-tagged-string
"Parse a tagged string within JSON.
Assumes string begins with a throwaway first character and there is a single space between the tag and its data."
@lynaghk
lynaghk / gist:5174289
Created March 16, 2013 00:30
Hacky "tagged literals" in JSON.
;;5-minute sketch of tagged literals in JSON via the little known second argument to the browser's JSON.parse.
;;It's no EDN, but it's still a hell of a lot nicer than the usual JSON-deserialization state of affairs.
(ns shim.json
(:require [goog.date.DateTime :as DateTime]))
(defn parse-tagged-string
"Parse a tagged string within JSON.
Assumes string begins with a throwaway first character and there is a single space between the tag and its data."
@lynaghk
lynaghk / gist:5374327
Created April 12, 2013 19:06
Cheshire encode-map bug.
(ns cheshire-test ;;this is cheshire 5.1.0
(:require [cheshire
[core :as json]
[generate :refer [add-encoder encode-map]]]))
(json/generate-string {:x (java.util.Date.)}) ;;works fine: {"x":"2013-04-12T19:05:54Z"}
;;I want to print out dates as {"#inst":"2013-04-12T19:05:54Z"}
(add-encoder java.util.Date
(fn [date json-generator]
@lynaghk
lynaghk / gist:5694320
Created June 2, 2013 18:06
Puzzle agent + core.logic.
(defn sublisto
"The sequence x appears in y."
[x y]
(fresh [a b c]
(appendo a x b)
(appendo b c y)))
(->> (run* [q]
(sublisto [:b :r :r :c] q)
(sublisto [:r :c :c :b] q)