Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
--- src/clj/cljs/analyzer.clj 2012-11-17 01:01:55.712323358 -0500
+++ src/cljs/cljs/analyzer.cljs 2012-11-17 11:51:47.030558150 -0500
@@ -6,14 +6,23 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-(set! *warn-on-reflection* true)
+;; (set! *warn-on-reflection* true)
(ns cljs.analyzer
@swannodette
swannodette / gist:4004143
Created November 2, 2012 20:32 — forked from lynaghk/1-rewrite_usage.clj
Questions about fancy map rewriting via core.logic
;;I'd like to use core.logic to rewrite "colloquial" plot specifications into full, correct specs from which the C2PO compiler can generate graphics.
;;A full C2PO plot spec looks like:
{:data [...] ;;A seq of maps
:group :identity
:stat :identity
:mapping {} ;;A map from a geom's aesthetic to a key in the data maps, e.g., {:x :weight, :y :miles-per-gallon}
:geom :point
:scales {} ;;A map of aesthetic keywords to scales, e.g., {:x :linear}
}
@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 {}}
@dvanhorn
dvanhorn / delta-0cfa.rkt
Created October 6, 2012 02:31
Store delta 0CFA
#lang racket
;; 0CFA in the AAM style on some hairy Church numeral churning
;; + compilation phase
;; + lazy non-determinism
;; + specialized step & iterator 0m34.248s vs 0m16.339s
;; + compute store ∆s 0m16.339s vs 0m1.065s (!!!)
;; An Exp is one of:
@Pet3ris
Pet3ris / cond.pl
Created October 5, 2012 22:42
rejection sampling conditioner in prolog
% Two dices are thrown and the results added up.
% We sample when the sum is conditioned on the first dice landing on 2.
output(S) :-
randvar(a, dice(X), X),
dice(Y),
S is X + Y.
dice(X) :-
X is random(6) + 1.
@ninjudd
ninjudd / gist:3491702
Created August 27, 2012 19:46
Lein with Decaf
fallout:~ master$ time lein version
Leiningen 2.0.0-SNAPSHOT on Java 1.6.0_29 Java HotSpot(TM) 64-Bit Server VM
real 0m2.041s
user 0m5.020s
sys 0m0.189s
fallout:~ master$ time LEIN_JAVA_CMD=decaf lein version
Leiningen 2.0.0-SNAPSHOT on Java 1.6.0_29 Java HotSpot(TM) 64-Bit Server VM
@dvanhorn
dvanhorn / memo-dyn.txt
Created August 24, 2012 17:53
Memoization vs dynamic programming
Memoization is fundamentally a top-down computation and dynamic
programming is fundamentally bottom-up. In memoization, we observe
that a computational *tree* can actually be represented as a
computational *DAG* (the single most underrated data structure in
computer science); we then use a black-box to turn the tree into a
DAG. But it allows the top-down description of the problem to remain
unchanged.
In dynamic programming, we make the same observation, but construct
the DAG from the bottom-up. That means we have to rewrite the
@swannodette
swannodette / fbound.clj
Created August 10, 2012 13:55 — forked from frenchy64/fbound.clj
F-bounded Polymorphism in Typed Clojure
; y has upper bound x, z has upper bound (Seqable y)
typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]]
[x y z -> Any]))
[typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))]
typed.core=> (declare foo)
#'typed.core/foo
;cf = check-form
typed.core=> (cf (foo 2 2 [2]))
Any
@martintrojer
martintrojer / sud4-ckanren.clj
Created July 27, 2012 18:36
Sudoku core.logic
(defne all-distinctfd [l]
([()])
([[h . t]]
(distinctfd h)
(all-distinctfd t)))
(run 1 [q]
(fresh [a1 a2 a3 a4
b1 b2 b3 b4
c1 c2 c3 c4
@terjesb
terjesb / logicrels-lucene.clj
Created July 26, 2012 08:39 — forked from jsmorph/logicrels-lucene.clj
Lucenalog: Datalog interface to Lucene in 10 lines
(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
Use
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation