This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun copy-for-stackoverflow (start end) | |
(interactive "r") | |
(let ((oldbuf (current-buffer))) | |
(with-current-buffer (generate-new-buffer "so-paste") | |
(insert-buffer-substring oldbuf start end) | |
(indent-rigidly (point-min) (point-max) 4) | |
(kill-ring-save (point-min) (point-max)) | |
(kill-buffer)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [coll [[:a :b :c] [:d] [:e :f]]] | |
(into {} (for [[idx xs] (map-indexed vector coll), | |
x xs] | |
[x idx]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useful.seq=> (glue conj [] #(< (peek %1) %2) (constantly false) | |
[1 2 3 0 9 1 5 6]) | |
([1 2 3] [0 9] [1 5 6]) | |
useful.seq=> (apply max-key count *1) | |
[1 5 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [currency-values [[:hundreds 10000] | |
[:fifties 5000] | |
[:twenties 2000] | |
[:tens 1000] | |
[:fives 500] | |
[:ones 100] | |
[:quarters 25] | |
[:dimes 10] | |
[:nickels 5] | |
[:pennies 1]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [q (atom {:contents #queue [], :ret nil})] | |
{:take (fn [] | |
(:ret (swap! q (fn [{:keys [contents]}] | |
{:contents (pop contents) | |
:ret (peek contents)})))) | |
:put (fn [x] | |
(swap! q update-in :contents conj x))}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
(def N (count charset)) | |
(defn valueFor [x] | |
(.indexOf charset (str x))) | |
(defn charFor [x] | |
(nth charset x)) | |
(defn combiner [o] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(when (window-system) | |
(global-unset-key "\C-z") | |
(dolist (key (list (kbd "C-x C-c") (kbd "s-q"))) | |
(global-set-key key (lambda () | |
(interactive) | |
(message "Why would you ever leave?"))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(letfn [(remove-once [x coll] | |
(lazy-seq | |
(let [y (first coll)] | |
(if (= x y) | |
(rest coll) | |
(cons y (remove-once x (rest coll)))))))] | |
(defn permute [coll] | |
(lazy-seq | |
(if-let [coll (seq coll)] | |
(for [x coll, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fight-one-round [[a b :as fighters]] | |
(let [ticks (apply min (map :cooldown-remaining fighters)) | |
damage-dealt (fn [fighter] | |
(if (= ticks (:cooldown-remaining fighter)) | |
(:dmg fighter) | |
0)) | |
tick (fn [fighter] | |
(update-in fighter [:cooldown-remaining] | |
(fn [cdr] | |
(if (= cdr ticks) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn carry-over [coll] | |
(reductions (fn [[x :as xs] ys] | |
(update-in ys [0] (fn [y] | |
(or (not-empty y) x)))) | |
coll)) | |
user> (carry-over '(["fresh" :hello :world] ["" :foo :bar] ["" :bar :baz] ["cool" :qux :qex] ["" :etc :etc])) | |
(["fresh" :hello :world] ["fresh" :foo :bar] ["fresh" :bar :baz] ["cool" :qux :qex] ["cool" :etc :etc]) |