This file contains 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
(ns ezducerdemo) | |
;; | |
;; 1st take | |
;; | |
(defn ezducer [constructor] | |
(fn [reducer] | |
(let [steps (fn [a vs] | |
;; Use loop/recur instead of reduce to avoid reduce's |
This file contains 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
(ns xflib) | |
(defn demultiplex [n] | |
(if (= n 1) | |
identity | |
(let [expected-result-calls* (atom n) | |
shared-reducer* (atom nil) | |
reduced-value* (atom nil)] | |
(fn [r] | |
(if-let [shared-reducer @shared-reducer*] |
This file contains 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
(ns squarespec | |
(:require [clojure.spec :as s] | |
[clojure.spec.gen :as sgen] | |
[clojure.spec.test :as stest])) | |
;; Implementation | |
(defn square | |
"Define a square path given an origin and length." | |
[[x1 y1 :as origin] length] | |
(let [x2 (+ x1 length) |
This file contains 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
(ns deftype+ | |
"Augmented deftype sporting a new :delegate option.") | |
;; code to get the methods of interfaces and protocols | |
(defmulti get-methods | |
"Return a map of all method names to their arity." | |
class) | |
(defmethod get-methods clojure.lang.PersistentArrayMap | |
[protocol] |
This file contains 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 sparkline [values] | |
(let [low (apply min values) | |
high (apply max values) | |
bars "▁▂▃▄▅▆▇█" | |
step (/ (- high low) (dec (count bars))) | |
scale #(nth bars (int (/ (- % low) step)))] | |
(apply str (map scale values)))) |
This file contains 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
#!/bin/bash -e | |
status_icon_000="/usr/share/icons/Humanity/apps/48/stock_delete-bookmark.svg" | |
status_icon_100="/usr/share/icons/Humanity/apps/48/stock_bookmark.svg" | |
function context_loop() { | |
declare time_task | |
while time_task=$(context_switch_dialog $*) | |
do | |
set $time_task # reference using positional args |
This file contains 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 conjoin [& preds] | |
(fn [& args] | |
(let2 | |
% (apply juxt preds) | |
% (map % args) | |
% (flatten %) | |
% (every? identity %)))) | |
(defn disjoin [& preds] | |
(fn [& args] |
This file contains 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
(defmacro let2 | |
"Alternate let block that doesn't have a body, just bindings. The last binding is returned." | |
([] nil) | |
([& bindings] | |
`(let [~@bindings] ~(first (take-last 2 bindings))) ) ) |
This file contains 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
#!/bin/bash -e | |
new_status() | |
{ | |
gajim-remote change_status "$@" | |
} | |
lock_screen() | |
{ | |
gnome-screensaver-command --lock |
This file contains 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
(defmacro topic | |
([t] nil) | |
([t form] form) | |
([t form & more] | |
`(let [~t ~form] (topic ~t ~@more))) ) | |
(def topic-ex1 | |
(topic % 1 | |
(+ 1 %) | |
(/ % 2) ) ) |
NewerOlder