Skip to content

Instantly share code, notes, and snippets.

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:

@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)
(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 / 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! []
@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 / defmacro2.clj
Created March 17, 2012 08:50
An alternate `defmacro2` definition with compile time semantics
(in-ns 'user)
;; An alternate `defmacro2` definition based on the example from
;; "Macros are Hard" presentation by @david_mcneil. This
;; implementation defines a macro called `name` and a function
;; equivalent called `name+` which still evaluates at compile time as
;; opposed to execution time
(defmacro defmacro2 [name args & body]
`(do
(defmacro ~name ~args ~@body)
@kriyative
kriyative / defmacro2.clj
Created March 17, 2012 08:48
An alternate `defmacro2` definition with compile time semantics
(in-ns 'user)
;; An alternate `defmacro2` definition based on the example from
;; "Macros are Hard" presentation by @david_mcneil. This
;; implementation defines a macro called `name` and a function
;; equivalent called `name+` which still evaluates at compile time as
;; opposed to execution time
(defmacro defmacro2 [name args & body]
`(do
(defmacro ~name ~args ~@body)
@kriyative
kriyative / clj-thrush.lisp
Created March 13, 2012 18:40
Clojure `thrush` operator macro in Common Lisp
(defmacro -> (x &rest args)
"A Common-Lisp implementation of the Clojure `thrush` operator."
(destructuring-bind (form &rest more)
args
(cond
(more `(-> (-> ,x ,form) ,@more))
((and (consp form)
(or (eq (car form) 'lambda)
(eq (car form) 'function)))
`(funcall ,form ,x))
@kriyative
kriyative / bind-2.lisp
Created July 6, 2011 18:25
A lightweight `bind' macro 3
(defmacro bind (clauses &body body)
"This macro combines the behaviour of the forms `let*', `destructuring-bind',
and `multiple-value-bind', permitting the following style of binding form:
(bind (((:values m n) (values 10 20))
((a b &key (c 10)) '(1 2))
(x 5))
(+ x a b c m n))
=> 48
@kriyative
kriyative / bind-1.lisp
Created July 6, 2011 18:24
A lightweight `bind' macro 2
(bind (((x y) point)
((x1 y1 w h) frame)
(x2 (+ x1 w))
(y2 (+ y1 h)))
(and (>= x x1) (<= x x2) (>= y y1) (<= y y2)))