Skip to content

Instantly share code, notes, and snippets.

@kriyative
kriyative / extmap.clj
Created May 9, 2012 07:03
Extending Clojure Map with `deftype` and `defprotocol`
(ns extmap
(:import
[clojure.lang ILookup Associative]))
;; ----------------------------------------------------------------
;; TrackableMap is a persistent map which keeps track of the number of
;; times `get` was called on it.
(defprotocol Trackable
(getStats [self]))
@kriyative
kriyative / progress.clj
Created May 10, 2012 23:30
First cut implementation of `with-progress` and `report!`
(def ^{:dynamic true} *print-progress* true)
(defmacro with-progress
"Bind a `reportfn` function, and evaluate `body` wherein
calling (report!) will invoke the report function with the current
state of the iteration."
[reportfn & body]
`(let [iter# (atom 0)
reporter# ~reportfn]
(letfn [(~'report! []
(defn uuid []
"Return an RFC1422 ver.4 compliant UUID"
(let [format "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
hex "0123456789abcdef"
gen #(case %
\x (get hex (rand-int 16))
\y (get hex (bit-or 0x8 (bit-and 0x3 (rand-int 16))))
%)]
(apply str (map gen format))))
@kriyative
kriyative / x-set-inputs.el
Created February 1, 2019 05:28
An emacs lisp package for enabling/disabling X inputs by symbolic reference
(defun set-inputs-parse-devices ()
(let ((dev-re (concat
"^[^A-Za-z]*\\([A-Za-z][-A-Za-z0-9/:,_ ]+"
"[-A-Za-z0-9/:,_]\\)"
"[ \t]*id=\\([0-9]+\\)"
"[ \t]*\\[\\(\\w+\\)"
"[ \t]*\\(\\w+\\)"))
devices)
(with-temp-buffer
(call-process "xinput" nil t)

Keybase proof

I hereby claim:

  • I am kriyative on github.
  • I am kriyative (https://keybase.io/kriyative) on keybase.
  • I have a public key ASDVywUMRecXvN790Ek_OwvexKhPQXoVZyVGsq7Z5g5inwo

To claim this, I am signing this object: