Skip to content

Instantly share code, notes, and snippets.

@tgk
tgk / gist:5803480
Created June 18, 2013 08:03
Simple aggregator macro
(defmacro aggregate
"Simple aggregation. Iterates over seq, binding values to
seq-bind. agg-bind is initially initial-val, but is bound to the value
of body after each iteration, and returned as the final value."
[agg-bind initial-val
[seq-bind seq]
& body]
`(reduce
(fn [~agg-bind ~seq-bind]
(do ~@body))
@tgk
tgk / gist:5796601
Created June 17, 2013 12:48
Generate splits over a sequence in Clojure on lazy sequences. Drops last split at the moment.
(defn splits
[s]
(take-while
(comp seq second)
(iterate
(fn [[prefix suffix]]
[(conj prefix (first suffix))
(rest suffix)])
[[] s])))
@tgk
tgk / README.md
Last active December 18, 2015 07:09
String histogram

This graphic illustrates string frequency over a period of time. Press left and right arrow keys to cycle through the data. A hash code adapted from Java is used to determine the color of the strings and the bars. log-scales are used to allow for visibility of small sample sizes at early time.

@tgk
tgk / README.md
Last active December 18, 2015 07:09
Circular buttons

The circular buttons use callback to update which of the two is selected.

@tgk
tgk / README.md
Last active December 18, 2015 07:09 — forked from mbostock/.block
Test of gist viewer

Mouseover to repel nodes. Weee, nodes!

@tgk
tgk / README.md
Last active October 13, 2015 03:58

Example of how rolling deploys might have been easy on Datomic databases, had Datomic supported change of schema in db snapshots. The example will not work, but illustrates how easy it would have been to operate on a new schema on an old database by performing migration in-memory when needed.

@tgk
tgk / gist:4124077
Created November 21, 2012 10:01
Adding schema to database (not connection)
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://schema-test")
(d/delete-database uri)
(d/create-database uri)
(def conn (d/connect uri))
(def schema-tx
@tgk
tgk / Car.java
Created October 5, 2012 13:21
Boilerplate example
import java.util.Arrays;
public class Car {
private int maxSpeed;
private Wheel[] wheels;
public Car(int maxSpeed, Wheel[] wheels) {
this.maxSpeed = maxSpeed;
this.wheels = wheels;
@tgk
tgk / Vagrantfile
Created August 14, 2012 05:57
Test suite
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.host_name = "apache"
config.vm.network :hostonly, "192.168.0.101"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.add_recipe "apache2"
@tgk
tgk / README.md
Last active October 6, 2015 19:28
Dots in tables

Experiments with very small pie charts and tables with dots whose size represents a quantity.