Skip to content

Instantly share code, notes, and snippets.

@clifford
clifford / gist:2479116
Created April 24, 2012 12:03 — forked from stuarthalloway/gist:1980351
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])
@clifford
clifford / ants.clj
Created April 25, 2012 18:20 — forked from jjcomer/ants.clj
Ant Simulation -- From Clojure Concurrency Presentation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;As shown in the presentation: http://blip.tv/clojure/clojure-concurrency-819147
@clifford
clifford / gist:2723694
Created May 18, 2012 07:00 — forked from swannodette/gist:2719676
unify_datums.clj
(ns datomic-play.core
(:use [datomic.api :only [db q] :as d])
(:require [clojure.core.logic :as l]
[clojure.pprint :as pp]))
(def uri "datomic:dev://localhost:4334/hello")
(defprotocol IUnifyWithDatum
(unify-with-datum [u v s]))
@clifford
clifford / accounts.clj
Created May 18, 2012 14:32 — forked from pelle/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))
@clifford
clifford / gist:3135721
Created July 18, 2012 11:36 — forked from stuarthalloway/gist:2645453
Datomic queries against Clojure collections
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
@clifford
clifford / gist:3213301
Created July 31, 2012 03:35 — forked from swannodette/gist:3213107
sudoku.clj
(defn distincto [s]
(if (seq s)
(all
(distinctfd (first s))
(distincto (next s)))
s#))
(defn all-infd [xs d]
(if (seq xs)
(all
@clifford
clifford / sud4-ckanren.clj
Created July 31, 2012 05:50 — forked from martintrojer/sud4-ckanren.clj
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
@clifford
clifford / gist:3218713
Created July 31, 2012 17:25 — forked from swannodette/gist:3217582
sudoku_compact.clj
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [grid x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in grid [x y])))
(defn init [grid [pos value]]
@clifford
clifford / upsert-auto.clj
Created August 4, 2012 08:17 — forked from terjesb/upsert-auto.clj
Upserting in Datomic
(use '[datomic.api :only (q db) :as d])
(def initial-data
[{:sku "1" :price 0.95M :qty 1}
{:sku "2" :price 1.99M :qty 0}
{:sku "3" :price 1.99M :qty 0}
{:sku "4" :price 5.99M :qty 3}
{:sku "5" :price 9.99M :qty 2}
{:sku "6" :price 2.99M :qty 3}
{:sku "7" :price 2.99M :qty 2}])
@clifford
clifford / gist:3486272
Created August 27, 2012 06:34 — forked from swannodette/gist:3217582
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))