Skip to content

Instantly share code, notes, and snippets.

View stuarthalloway's full-sized avatar

Stuart Halloway stuarthalloway

View GitHub Profile
@stuarthalloway
stuarthalloway / gist:1493247
Created December 18, 2011 12:24
Ant test failure on clean build of JRuby?
ant test
Buildfile: /Users/stu/tmp/jruby/build.xml
init:
prepare-bin-jruby:
jar:
init:
@stuarthalloway
stuarthalloway / gist:1493277
Created December 18, 2011 12:40
JRuby "ant test" on Ubuntu
Buildfile: build.xml
init:
prepare-bin-jruby:
jar:
init:
@stuarthalloway
stuarthalloway / gist:1626694
Created January 17, 2012 13:56
seqs are not mutable
(require '[clojure.string :as str])
(def data "Bob,Dobbs,bob@dobbs.com,25.00
Rocket J.,Squirrel,rocky@frostbite.com,0.00
Bullwinkle,Moose,bull@frostbite.com,0.25
Vim,Wibner,vim32@goomail.com,25.00")
(def lines (str/split data #"\n"))
(def registrants (map #(zipmap [:first :last :email :payment]
@stuarthalloway
stuarthalloway / gist:1980351
Created March 5, 2012 18:56
frinj unit conversion running inside a Datomic datalog query
;; lein settings
(defproject foo "1.0.0-SNAPSHOT"
:description "Test App"
:dependencies [[com.datomic/datomic "0.1.2678"]
[frinj "0.1.2" :exclusions [org.clojure/clojure]]])
;; load libs
(use 'frinj.core 'frinj.calc)
(frinj-init!)
(use '[datomic.api :only (q db) :as d])
@stuarthalloway
stuarthalloway / gist:2002582
Created March 8, 2012 18:39
Datomic extent query
;; Datomic example code
;;
;; The extent of entity ?x is all datoms that are about ?x.
;; Drop this into your rules.
;;
;; Demonstrates
;;
;; 1. recursive query (extent calls itself)
;; 2. disjunction (different extent bodies are ORed)
;; 3. component attributes (e.g. your arm is a component, your brother isn't)
@stuarthalloway
stuarthalloway / gist:2029409
Created March 13, 2012 15:28
Print Schema from Java
/**
* Datomic example code
*/
import datomic.Connection;
import datomic.Database;
import datomic.Entity;
import java.util.Collection;
import java.util.Iterator;
@stuarthalloway
stuarthalloway / gist:2158138
Created March 22, 2012 12:54
Many to Many Datomic example
;; Datomic example code
;; make in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://matches")
(d/create-database uri)
(def conn (d/connect uri))
;; add the match attribute
(d/transact
@stuarthalloway
stuarthalloway / gist:2321773
Created April 6, 2012 18:15
Datomic schema query, constrained by attribute namespace
;; Datomic sample code
;; schema query for attribute types in specified namespaces
(q '[:find ?attr
:in $ [?include-ns ...] ;; bind ?include-ns once for each item in collection
:where
[?e :db/valueType] ;; all schema types (must have a valueType)
[?e :db/ident ?attr] ;; schema type name
[(datomic.Util/namespace ?attr) ?ns] ;; namespace of name
[(= ?ns ?include-ns)]] ;; must match one of the ?include-ns
@stuarthalloway
stuarthalloway / gist:2519604
Created April 28, 2012 14:50
Add database functions and bytes value types to Datomic
;; Builds of Datomic with revision numbers higher than 0.1.3057 have
;; support for :db.type/fn, :db.type/bytes, and :db/fn.
;; To add these types to a database created using with a pre-0.1.3057
;; build, simply run the database with a newer version of Datomic, and
;; execute the two transactions below.
[{:db/id #db/id [:db.part/db]
:db/ident :db.type/bytes
:fressian/tag :bytes
@stuarthalloway
stuarthalloway / gist:2559635
Created April 30, 2012 16:11
Using data functions on both peer and transactor side
;; this code valid as of build 3084
;; in-memory example database
(use '[datomic.api :only (db q) :as d])
(def uri "datomic:mem://test")
(d/create-database uri)
(def conn (d/connect uri))
;; example schema
(d/transact conn [{:db.install/_attribute :db.part/db,