Skip to content

Instantly share code, notes, and snippets.

@ah45
ah45 / defmethods.clj
Created March 18, 2015 15:48
defmethods macro
(defmacro defmethods
"A convenience over writing lots of short `defmethod` statements that
use the same arguments:
(defmulti mm (fn [o x y] o))
(defmethods mm [_ x y]
'+ (+ x y)
'- (- x y)
'* (* x y)
'/ (/ x y))
@ah45
ah45 / nested_map_zipper.clj
Created March 6, 2015 13:04
Editing Nested Maps from the bottom up with Clojure Zippers
(ns nested-map-zipper
(:require [clojure.zip :as zip]
[clojure.data :refer [diff]]))
(defmacro recur-if
([expr]
`(recur-if ~expr nil))
([expr else]
`(let [temp# ~expr]
(if temp# (recur temp#) ~else))))
@ah45
ah45 / gist:59051b1a1fa5d1de74f1
Created October 9, 2014 11:47
ActiveDirectory objectGUID decoding
(ns active-directory.guid.util
(:require [clojure.string :as str]
[clojure.data.codec.base64 :as b64]))
(defn decode
"Decodes a Base64 encoded string into a sequence of bytes"
[b64s]
(b64/decode (.getBytes b64s)))
(defn byte->hex
@ah45
ah45 / user-data
Created September 26, 2014 14:45
CoreOS user-data file for a cluster running Progrium's service discovery tools (consul, registrator, and ambassadord)
#cloud-config
coreos:
etcd:
# generate a new token for each unique cluster from https://discovery.etcd.io/new
# WARNING: replace each time you 'vagrant destroy'
discovery: https://discovery.etcd.io/new
addr: $public_ipv4:4001
peer-addr: $public_ipv4:7001
fleet:
@ah45
ah45 / .profile
Last active August 29, 2015 14:01 — forked from blowmage/.profile
ohmygems
# configure the Ruby Gems environment
export RUBYOPT=rubygems
export GEM_HOME="$HOME/.gem"
export GEM_PATH="$HOME/.gem"
export PATH="$HOME/.gem/bin:$PATH"
source ~/bin/ohmygems