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 everyo [pred coll] | |
(if (empty? coll) | |
s# | |
(all | |
(pred (first coll)) | |
(everyo pred (rest 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
(def timing | |
(for [seq-len [100 10000 1000000] | |
:let [v (vec (range seq-len))] | |
[name [f combine]] {:map [map reduce] | |
:r/map [r/map r/reduce] | |
:fold [r/map r/fold]} | |
num-layers [0 2 5 10 25]] | |
{:f name, | |
:len seq-len, | |
:layers num-layers, |
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 users [{:name "Brian" :age 22} {:name "Ben" :age 19}]) | |
;; Takes a "path", returns a function that takes an "object" and | |
;; returns a "costate" | |
(defn lens [p] | |
(fn [o] | |
{:get (get-in o p) | |
:set #(assoc-in o p %1)})) | |
(def myAgeLens (lens [0 :age])) |
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
// based off of http://labs.unwieldy.net/moocirclepack/ | |
org.polymaps.packer = function() { | |
var packer = {}, | |
nodes = [], | |
elements = [], | |
timesToPack = 50; | |
packer.elements = function(e) { | |
if (!arguments.length) { | |
return elements; |
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 [{user "MONGO_USER" pass "MONGO_PASS"} (System/getenv)] | |
(authenticate conn user pass) | |
(set-connection! conn)) |
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 validates-credentials [username password] | |
(let [uc (count username) | |
pc (count password)] | |
(match [username uc password pc] | |
[(:or nil "") _ _ _] {:error "No username given" :field "name"} | |
[_ _ (:or nil "") _] {:error "No password given" :field "pass"} | |
[_ (_ :guard #(< % 3)) _ _] {:error "Username less than 3 characters" :field "pass"} | |
[_ _ _ (_ :guard #(< % 4))] {:error "Password less than 4 characters" :field "pass"} | |
[#"^([a-z0-9-_]+)$" _ _ _] {:error "Username contains invalid characters" :field "name"} | |
:else true))) |
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 mist.logic.datalog | |
(:use clojure.core.logic | |
[clojure.set :only [union, difference]]) | |
(:require clojure.walk)) | |
(defne allo [goal args] | |
([_ ()]) | |
([_ [arg . rest]] | |
(goal arg) | |
(allo goal rest))) |
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 anything-org-todo-list (arg) | |
(interactive "P") | |
(org-compile-prefix-format 'todo) | |
(org-set-sorting-strategy 'todo) | |
;;(org-prepare-agenda "TODO") | |
(if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil)) | |
(let* ((today (time-to-days (current-time))) | |
(date (calendar-gregorian-from-absolute today)) | |
(kwds org-todo-keywords-for-agenda) | |
(completion-ignore-case t) |
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 remove-curlied | |
[^String text] | |
(let [sb (StringBuilder.) | |
end (int (count text))] | |
(loop [state (int 0) | |
pos (int 0)] | |
(cond | |
(= pos end) (.toString sb) | |
(= (int (.charAt text pos)) (int \{)) (recur (inc state) (inc pos)) | |
(= (int (.charAt text pos)) (int \})) (recur (dec state) (inc pos)) |
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 pretty-lambdas () | |
"Show glyph for lower-case Greek lambda (λ) wherever 'lambda' appears." | |
(font-lock-add-keywords | |
nil | |
`(("(\\(lambda\\>\\)" | |
(0 | |
(progn | |
(compose-region | |
(match-beginning 1) | |
(match-end 1) |