Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/bash
filename="$1"
wait="🕜"
# test 🕜🕜🕜🕜pausing
function keystroke-delay {
delay=`bc <<END
scale=2
@cemerick
cemerick / an-preview.png
Last active June 27, 2017 21:12
"Ancap News" greasemonkey script; go to https://github.com/cemerick/ancap-news
an-preview.png
@cemerick
cemerick / gist:00e9e8d1da6461d9daaddd0232943411
Created June 5, 2017 15:11
optional alternative :filespec destination path
; e.g. usage
:filespecs [{:type :path :path "source/directory" :root "destination/directory/"}]
; at the end of project.clj
(require 'leiningen.jar)
(in-ns 'leiningen.jar)
(defmethod copy-to-jar :path [project jar-os acc spec]
(let [root-file (io/file (:path spec))
@cemerick
cemerick / user.clj
Last active April 27, 2017 13:39
reduce-for: easier-to-understand nested reductions
; a toy example of a nested reduction; especially when function bodies are nontrivial, or when the nesting
; gets much deeper than 2 levels, it's easy to lose track of which values are being reduced over at each
; level, etc
(let [x {:a [1 2 3] :b [4 5 6]}]
(reduce
(fn [x [k vs]]
(reduce
(fn [x v] (update x :sum (fnil + 0) v))
x
@cemerick
cemerick / sorted_set_bench.clj
Created March 22, 2017 04:15
benchmarking Clojure/Java sorted set impls
;; benchmarking different sorted-set implementations
;; /ht https://gist.github.com/tonsky/c5605058f29c620242eb7e0130234a8c
;;
;; results after the code...
;; TODO
;; * some impls provide specialized ctors for pre-sorted and/or distinct initial members
;; *
(ns cemerick.sorted-set-bench
@cemerick
cemerick / foo.clj
Last active March 9, 2017 12:20
slightly saner printing for Clojure fns
(defn delegate-printing-for
"Registers the necessary methods to delegate printing of instances of [class] to [fn]."
[class fn]
#?@(:clj [(defmethod print-method class
[x writer]
(.write ^java.io.Writer writer (fn x)))
(defmethod print-dup class
[x writer]
(print-method x writer))
(#'clojure.pprint/use-method
### Keybase proof
I hereby claim:
* I am cemerick on github.
* I am cemerick (https://keybase.io/cemerick) on keybase.
* I have a public key whose fingerprint is B7DA 0140 4D66 4907 EBDF 1398 C926 963F B974 E677
To claim this, I am signing this object:
@cemerick
cemerick / sets.clj
Last active October 28, 2016 13:11
Name that set operation!
; I'm hoping to find a common name for a particular operation over sets that I've
; been thinking of as a "join" of sorts.
;
; It's _not_ a relational join -- the values involved aren't relations (for me
; at the moment, they're actually graphs essentially representing
; disjoint recursive sets, but I think that's probably irrelevant
; detail) -- but it feels like it's in the spirit of a full outer join
;
; Given N sets, recursively produce all unions of those sets that are disjoint.
@cemerick
cemerick / strint.clj
Created August 9, 2016 13:12
BSD-licensed string interpolation for clojure
;;; strint.clj -- String interpolation for Clojure
;; originally proposed/published at http://cemerick.com/2009/12/04/string-interpolation-in-clojure/
;; Copyright (c) 2009, 2016 Chas Emerick <chas@cemerick.com>
;;
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
(def percentage-spec (s/conformer #(or (some-> (re-matches #"(-?\d+(\.\d+)?)%" %) (nth 1) Double/parseDouble)
::s/invalid)
#(str % "%")))
(s/def ::absolute-coordinate number?)
(s/def ::pct-coordinate percentage-spec)
(s/def ::coordinate (s/or :abs ::absolute-coordinate
:pct ::pct-coordinate))
(def specrec (s/cat :lx ::coordinate