Skip to content

Instantly share code, notes, and snippets.

@abp
abp / README.md
Created July 31, 2013 11:51 — forked from bodil/README.md

core.async example thing

To run:

  • checkout https://github.com/clojure/core.async and install it using lein install
  • make a project directory for this code
  • put omgcoreasync.cljs in a src subdirectory, project.clj and index.html in the root
  • go lein cljsbuild once to build
  • load index.html in a browser and watch it go
@abp
abp / gist:4118735
Created November 20, 2012 15:50 — forked from lynaghk/gist:4116442
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]
@abp
abp / codeq-examples.clj
Created November 20, 2012 02:36 — forked from richhickey/codeq-examples.clj
codeq examples used in conj talk
(require '[datomic.api :as d])
(require '[clojure.pprint :refer [pprint]])
(def uri "datomic:free://localhost:4334/git")
(def conn (d/connect uri))
(def db (d/db conn))
;; committers
(d/q '[:find ?email
:where
[_ :commit/committer ?u]
;; 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 %))