Skip to content

Instantly share code, notes, and snippets.

@rplevy
rplevy / qq.clj
Created April 24, 2012 17:25
string that can contain quotes (for reader-valid content only)
(defmacro qq [& body]
`(->>
(map (fn [s#]
(if (string? s#)
(format "\"%s\"" s#) (str s#)))
(quote ~body))
(interpose " ")
(apply str)))
(defn myfn "docstring \"the normal way\" sort of a pain" [] )
@rplevy
rplevy / furcula_use.clj
Created May 1, 2012 13:26
furcula example
(apply
format
"%d-%02d-%02d %02d:%02d:%02d"
(-< (doto (Calendar/getInstance)
(.setTime (Date. 112 4 17 14 15 0))
(.add Calendar/MINUTE (* 15 offset)))
(.get Calendar/YEAR)
(.get Calendar/MONTH)
(.get Calendar/DAY_OF_MONTH)
(.get Calendar/HOUR)
@rplevy
rplevy / vinepeek.clj
Last active December 11, 2015 21:19
A non-browser-based imitation of http://vinepeek.com (play random videos from http://vine.co) in 50 lines of Clojure in the REPL. Another way in which this is different from vinepeek.com is that it doesn't repeat videos that have already been viewed (unless you restart the process). Make sure to set video-player to a video-player application tha…
(require '[cemerick.pomegranate :refer [add-dependencies]])
(add-dependencies
:coordinates '[[clj-http "0.6.3"]
[swiss-arrows "0.5.1"]]
:repositories {"clojars" "http://clojars.org/repo"})
(require '[clj-http.client :as client]
'[swiss-arrows.core :refer [-<>]]
'[clojure.string :as str]
'[clojure.java.shell :refer [sh]])
Verifying that +rplevy is my blockchain ID. https://onename.com/rplevy
@rplevy
rplevy / example.clj
Last active June 11, 2016 05:13
temporal higher-order contract with clojure.spec
(require '[clojure.spec :as s])
(defn enforce [spec data-value]
(let [r (s/conform spec data-value)]
(if (= r :clojure.spec/invalid)
(throw (ex-info (str r) (s/explain-data spec data-value)))
data-value)))
(defn call-with-temporal-contract [f g contract-on-g]
(let [function-calls (atom [])]
@rplevy
rplevy / aero-env.clj
Created June 15, 2016 00:47
integrate environ with aero
(defn keywordize [s]
(-> (str/lower-case s)
(str/replace "_" "-")
(str/replace "." "-")
(keyword)))
(defmethod aero/reader 'env
[opts tag value]
(get env (keywordize (str value))))
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
I verify that I am rplevy on mastodon.social
-----BEGIN PGP SIGNATURE-----
Version: Keybase OpenPGP v2.0.68
Comment: https://keybase.io/crypto
wsFcBAABCgAGBQJY4xcwAAoJEHPFfFFJo8mQ7LoQANVwr+sfT8tzZWCuyNsdLpsc
hPK3SmUTCLRYa/8Olvq2MO/ZWTyuHfhDiRWqmksSIdAoR5oyiz0RC4fCpuZY4QeZ
# in my .bashrc
xmlclj() { planck -D funcool/tubax:0.2.0 -e "(require '[tubax.core :as tubax]) (require '[planck.core :refer [slurp]]) (require '[cljs.pprint :refer [pprint]])"'(pprint (tubax/xml->clj (slurp "'$1'")))'; }
# example: xmlclj /tmp/foo.xml
@rplevy
rplevy / xml->clj-region.el
Last active August 18, 2017 23:45
elisp wrapper on cljs script
(defun xml->clj-region (beg end)
(interactive "r")
(shell-command-on-region beg end
"xmlclj"
(current-buffer)
t))
@rplevy
rplevy / htm2clj-region.el
Last active August 21, 2017 20:58
tool for generating (usually valid, or close to valid) sablono markup from raw html
(defun htm2clj-region (beg end)
(interactive "r")
(shell-command-on-region beg end
"html2clj"
(current-buffer)
t))