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 divide-coll | |
"Divide collection of block heights into regions where water will be blocked. | |
ex. | |
[1 2 0 1 3 2 1 0 3] -> [[3 2 1 0 3] [2 0 1 3]]" | |
[c] | |
(let [regions (reduce (fn [coll i] | |
(cond | |
(seq coll) (let [[x & xs] coll | |
from (first x) | |
new-x (conj (vec x) i)] |
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
;; Match with guard function | |
(match [{:a 2} {:b 3}] | |
[{:a (_ :guard even?)} _] 1) | |
;; Match-with-fn example for same | |
(match [{:a 2} {:b 3}] | |
[{:a even?} _] 1) |
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 publish | |
([a & ch-vals] | |
(let [key-vals (mapcat (fn [[channel val]] | |
[channel {:val val | |
:id (java.util.UUID/randomUUID)}]) | |
(partition 2 ch-vals))] | |
(apply swap! a assoc key-vals)))) | |
(defn subscribe |
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 find-surviver* | |
[in] | |
(loop [[f s & coll] in] | |
(if (and f s) | |
(recur (concat coll [f])) | |
f))) | |
(defn find-surviver | |
[population] |
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
## | |
# Prints terminal codes. | |
# | |
# Thanks to: http://github.com/wayneeseguin/rvm/blob/master/scripts/color | |
# | |
# @param [String] terminal code keyword (usually a color) | |
bput() { | |
case "$1" in | |
# regular colors | |
black) tput setaf 0 ;; |
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
(remove-hook 'clojure-mode-hook 'clojure-test-maybe-enable) | |
(defun clojure-in-tests-p () | |
(or (string-match-p "test\." (clojure-find-ns)) | |
(string-match-p "/test" (buffer-file-name)))) | |
(defun midje-test-for (namespace) | |
(let* ((namespace (clojure-underscores-for-hyphens namespace)) | |
(segments (split-string namespace "\\.")) |
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/sh | |
# A pre-commit hook for js | |
# It runs jshint on js files. | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
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/sh | |
# A pre-commit hook for js and clojure | |
# It runs jshint on js files. | |
# and runs lein2 midje. | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else |
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
(require 'flymake) | |
(defun flymake-php-init () | |
"Use php to check the syntax of the current file." | |
(let* ((temp (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) | |
(local (file-relative-name temp (file-name-directory buffer-file-name)))) | |
(list "php" (list "-f" local "-l")))) | |
(add-to-list 'flymake-err-line-patterns | |
'("\\(Parse\\|Fatal\\) error: +\\(.*?\\) in \\(.*?\\) on line \\([0-9]+\\)$" 3 4 nil 2)) |