Skip to content

Instantly share code, notes, and snippets.

@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
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 / 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 / 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 / anti_patterns.clj
Last active August 16, 2021 11:39
Some Clojure anti-patterns
;; Anti patterns
;; Implicit data manipulation anti-pattern
;;
;; Having nested calls manipulating data, instead of explicitly stating
;; what changes are performed to the data
(def h
[z]
;; ...
@tgk
tgk / gist:5947386
Created July 8, 2013 09:14
Iterate over filenames and execute command in bash
for f in ~/dir/*.txt; do bin/do_thing $f; done
@tgk
tgk / README.md
Last active December 19, 2015 20:19
Projection of all British outbound postcodes

Projection of all British outbound postcodes (also known as "the bit before the space")

@tgk
tgk / README.md
Created July 17, 2013 11:46
Voronoi diagram for British outbound postcodes

Voronoi diagram for British outbound postcodes. The voronoi function breaks when the data points close to each other are not removed.

@tgk
tgk / README.md
Created July 20, 2013 07:56
Demographic treemap with tooltip

Demographics treemap with population distribution and revenue obtained from that demographic associated with each node. The (fictitious) demographics data is loaded from a CSV file, whereas the revenue data is randomly generated.

@tgk
tgk / README.md
Last active April 19, 2019 18:31
Add and remove nodes

Click to add nodes! Nodes near the cursor will be linked to the new node. Clicking an existing node will remove it.

This is an extension of this example, adding the capability of removing nodes by clicking them. This means that dragging is no longer supported.