Skip to content

Instantly share code, notes, and snippets.

@abp
abp / gist:4115467
Created November 20, 2012 01:55
fnk with qualified symbols
(macroexpand '(fnk [a/b] (+ 1 a/b))) ; =>
(clojure.core/with-meta
(clojure.core/fn [{:or {}, a$b2238 :a/b}] (+ 1 a$b2238))
{:req-deps [:a/b], :opt-deps []})
(defn write-output [out-file coll]
(spit out-file
(clojure.string/join
(map
#(str (:email %) \newline
" ~ " (:question %) \newline)
coll))))
;; A basic Ring handler
(defn handler [request]
{:status 200
:headers {}
:body "Hello World"})
;; Which can also be written:
(def handler
@abp
abp / gist:3690541
Created September 10, 2012 11:58 — forked from Chouser/gist:3687532
Lazy seq as event subscription mechanism
;; Here is a spike of a lightweight in-process pubsub mechanism that allows pure ;; functional consumers, both blocking and asynchronous.
;; This defines the event stream, in this case just a series of numbers,
;; a new one produced each second
(defn timer []
(lazy-seq
(do
(Thread/sleep 1000)
(cons (System/nanoTime) (timer)))))
@abp
abp / lang.clj
Created September 10, 2012 08:45 — forked from fogus/lang.clj
(use '[datomic.api :only [db q] :as d])
(def schema
[{:db/doc "A programming language"
:db/id (d/tempid :db.part/db)
:db/ident :lang
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
@abp
abp / anarchy.clj
Created September 7, 2012 06:48 — forked from fogus/anarchy.clj
Simple system for plural dispatch
(ns dj.plurality)
(defmacro defplural-body [pluralfn-name arg-list & resolver-body]
`(def ~pluralfn-name (let [implementations# ~(if (resolve pluralfn-name)
`(atom (or @(:dj.plurality/implementations (meta ~pluralfn-name))
[]))
`(atom []))]
(with-meta (fn ~pluralfn-name ~(into [] (rest arg-list))
(let [~(first arg-list) @implementations#]
~@resolver-body))
@abp
abp / markov.clj
Created September 6, 2012 11:36 — forked from kelsey-sorrels/markov.clj
Overtone Internal Sequencer with Markov chains
(ns overtone.examples.internal-sequencer
(:use [overtone.live]))
;; A fully server-side sample sequencer.
;; =====================================
;; This example demonstrates some of the benefits of moving all synth
;; triggers inside the server itself. For example, it allows you to
;; modify the synthesis with *immediate* effect (rather than waiting for
;; the next bar/chunk to be scheduled) and you can use a global pulse to
@abp
abp / accounts.clj
Created August 29, 2012 13:11 — forked from terjesb/accounts.clj
Using database functions in Datomic transactions and annotating transaction history
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://accounts")
;; create database
(d/create-database uri)
;; connect to database
(def conn (d/connect uri))
@abp
abp / gist:3339422
Created August 13, 2012 10:57 — forked from lynaghk/gist:3335154
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 %))
@abp
abp / family-trees.txt
Created August 2, 2012 07:48 — forked from zerokarmaleft/family-trees.txt
Game of Thrones Challenge #65
AA = Rickard Stark (M) AB = Eddard Stark (M) AC = Catelyn Tully (F)
AD = Brandon Stark (M) AE = Benjen Stark (M) AF = Jon Snow (M)
AG = Robb Stark (M) AH = Sansa Stark (F) AI = Arya Stark (F)
AJ = Bran Stark (M) AK = Rickon Stark (M) AL = Hoster Tully (M)
AM = Minisa Whent (F) AN = Edmure Tully (M) AO = Lysa Tully (F)
AP = Jon Arryn (M) AQ = Robert Arryn (M) AR = Tytos Lannister (M)
AS = Tywin Lannister (M) AT = Joanna Lannister (F) AU = Kevan Lannister (M)
AV = Cersei Lannister (F) AW = Jamie Lannister (M) AX = Tyrion Lannister (M)
AY = Robert Baratheon (M) AZ = Joffrey Baratheon (M) BA = Myrcella Baratheon (F)
BB = Tommen Baratheon (M) BC = Lancel Lannister (M) BD = Steffon Baratheon (M)