Skip to content

Instantly share code, notes, and snippets.

View cch1's full-sized avatar

Chris Hapgood cch1

  • Sun Tribe Trading
  • Center of the Universe
View GitHub Profile
@cch1
cch1 / pick-and-rename.clj
Created July 30, 2012 17:07 — forked from edw/pick-and-rename.clj
Let-Over-Lambda
(let [undefined-value (atom :undefined-value)]
(defn pick-and-rename [col pick-map]
(apply assoc
{}
(flatten
(filter (fn [[k v]]
(not (= v undefined-value)))
(map (fn [[k v]]
[v (get col k undefined-value)])
pick-map))))))
@cch1
cch1 / test_helpers.clj
Last active December 31, 2015 00:09
feedback streams
(ns test-helpers
(:import [java.io InputStream OutputStream IOException])
(:require [clojure.java.io :as io]))
(defn- swap-!
"Atomically swaps the value of atom to be:
(apply f current-value-of-atom args). Note that f may be called
multiple times, and thus should be free of side effects. Returns
the value prior to the update."
[a f & args]
@cch1
cch1 / template.clj
Created June 23, 2021 19:57
An example of a simple templating capability that heavily leverages built-in features of clojure.
(ns template
(:require [clojure.edn :as edn]
[clojure.string :as string]))
;; Tagged literals do not need to be limited to being represented by a single string. Here we represent a value with a tuple of `magic` and `value`.
(defn read-magic [[magic value]]
(case magic
:c (string/capitalize value)
:l (string/lower-case value)
:u (string/upper-case value)))