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 tree-seq-depth | |
| "Returns a lazy sequence of vectors of the nodes in a tree and their | |
| depth as [node depth], via a depth-first walk. branch? must be a fn | |
| of one arg that returns true if passed a node that can have | |
| children (but may not). children must be a fn of one arg that | |
| returns a sequence of the children. Will only be called on nodes for | |
| which branch? returns true. Root is the root node of the tree." | |
| [branch? children root] | |
| (let [walk (fn walk [depth node] | |
| (lazy-seq |
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
| # List of all the valid pdf URLs ever posted to the #Clojure IRC channel. | |
| # | |
| # Many of them are interesting CS papers others are not that useful. What I've done: | |
| # | |
| # 1. crawled an IRC history archive for the channel | |
| # 2. extract pdf list in a file with: grep -riIohE 'https?://[^[:space:]]+pdf' * > pdf-links.txt | |
| # 3. remove dupes: cat pdf-links.txt | sort | uniq > pdf-links-uniq.txt | |
| # 4. filter only HTTP 200: cat pdf-links-uniq.txt | xargs curl -o /dev/null --connect-timeout 2 --silent --head --write-out '%{http_code} %{url_effective}\n' | grep "^200" > valid-pdf-links.txt | |
| # | |
| # Now your choice to download them all or not. If you want, use: cat valid-pdf-links.txt | awk '{print $2}' | xargs wget |
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 double-map [f] | |
| (let [^clojure.lang.IFn$DD f f] | |
| (fn [f1] | |
| (if (instance? clojure.lang.IFn$DDD f1) | |
| (let [^clojure.lang.IFn$DDD f1 f1] | |
| (fn | |
| ([] (f1)) | |
| (^double [^double result] (.invokePrim ^clojure.lang.IFn$DD f1 result)) | |
| (^double [^double result ^double input] | |
| (.invokePrim f1 result (.invokePrim f input))) |
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
| (ns weighted-rand | |
| (:import clojure.lang.PersistentQueue)) | |
| (defprotocol Rand | |
| (nextr [_ rng])) | |
| ;; Vose's alias method | |
| ;; http://www.keithschwarz.com/darts-dice-coins/ | |
| (deftype Vose [n ^ints alias ^doubles prob] |
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
| (require '[clojure.core.async :as a]) | |
| (def xform (comp (map inc) | |
| (filter even?) | |
| (dedupe) | |
| (flatmap range) | |
| (partition-all 3) | |
| (partition-by #(< (apply + %) 7)) | |
| (flatmap flatten) | |
| (random-sample 1.0) |
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
| (in-ns 'eclj.core) | |
| (defprotocol Fn | |
| :on-interface clojure.lang.Fn | |
| "Marker interface indicating invokeables that are explictly functions") | |
| (defprotocol IFn | |
| :on-interface clojure.lang.IFn | |
| (^{:on :invoke} -invoke | |
| [this] |
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
| (ns schema->gen | |
| "Functions for generating test data from schemas." | |
| (:require [four.stateful :as four] | |
| [re-rand :refer [re-rand]] | |
| [schema.core :as sch] | |
| [simple-check.generators :as gen])) | |
| (defn ^:private re-randify-regex | |
| "schema requires ^$ while re-rand forbids them" | |
| [re] |
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
| ;; I wrote this in the Eurostar on my way back from the last lambdanext.eu clojure course. | |
| (ns comprehensions | |
| (:refer-clojure :exclude [for doseq]) | |
| (:require [clojure.core.reducers :as r])) | |
| ;; borrowed from clojure.core | |
| (defmacro ^{:private true} assert-args | |
| [& pairs] | |
| `(do (when-not ~(first pairs) |
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
| ; Stumbling towards Y (Clojure Version) | |
| ; | |
| ; (this tutorial can be cut & pasted into your IDE / editor) | |
| ; | |
| ; The applicative-order Y combinator is a function that allows one to create a | |
| ; recursive function without using define. | |
| ; This may seem strange, because usually a recursive function has to call | |
| ; itself, and thus relies on itself having been defined. | |
| ; | |
| ; Regardless, here we will stumble towards the implementation of the Y combinator. |
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
| (ns net.cgrand.decay | |
| "Exponentially decaying lists. See http://awelonblue.wordpress.com/2013/01/24/exponential-decay-of-history-improved/ | |
| for background and http://clj-me.cgrand.net/2013/02/12/decaying-lists-log-scale-for-lists/ for documentation") | |
| ;; PRNG, formulas straight from java.util.Random javadoc | |
| (defn- seed ^long [^long n] | |
| (bit-and (unchecked-multiply n 0x5DEECE66D) | |
| (unchecked-dec (bit-shift-left 1 48)))) | |
| (defn- next-seed ^long [^long seed] |