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 f [{:keys [mx acc]} x] | |
{:mx (max mx (+ acc x)) | |
:acc (max 0 (+ acc x))}) | |
(defn max-sum [v] | |
(:mx (reduce f {:mx 0 :acc 0} v))) | |
(max-sum [-1, 5, 6, -2, 20, -50, 4]) ;29 | |
(max-sum [-1, 5, 6, -2, 21, -50, 4, -100, 30, -100, 5, 8, -2, 20, -50, 4]) ;31 | |
(max-sum [-2, 1, -3, 4, -1, 2, 1, -5, 4]) ;6 |
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
; nrepl.el 0.2.0 (Clojure 1.5.1, nREPL 0.2.1) | |
user> (use 'clojail.testers) | |
nil | |
user> (use 'clojail.core) | |
nil | |
user> (def mysb (sandbox secure-tester-without-def)) | |
#'user/mysb | |
user> (mysb '(range 10)) | |
(0 1 2 3 4 5 6 7 8 9) | |
user> (mysb '(range count)) |
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 test29 | |
"Write a function which takes a string and returns a new string | |
containing only the capital letters." | |
[f] | |
[(= (f "HeLlO, WoRlD!") "HLOWRD") | |
(empty? (f "nothing")) | |
(= (f "$#A(*&987Zf") "AZ")]) | |
(test29 identity) |
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
set-window-option -g xterm-keys on |
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
(define-key input-decode-map "\e[1;5A" [C-up]) | |
(define-key input-decode-map "\e[1;5B" [C-down]) | |
(define-key input-decode-map "\e[1;5C" [C-right]) | |
(define-key input-decode-map "\e[1;5D" [C-left]) |
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 long-func-name [x y z] :bar) | |
(defn baz1 [] | |
(long-func-name (some-thing-arg1) | |
(some-thing-arg2) arg3)) | |
(defn baz2 [] | |
(long-func-name (some-thing-arg1) | |
(some-thing-arg2) arg3)) |
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 foo) | |
(defprotocol Foo | |
(alpha [this a]) | |
(beta [this a])) | |
(ns bar | |
(:require [foo :as f])) | |
(defrecord Bar [] |
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
Interval Since Last Panic Report: 4179520 sec | |
Panics Since Last Report: 5 | |
Anonymous UUID: 1120CBDC-7AB8-0506-91A9-C2FD34C0D644 | |
Tue Apr 22 10:56:08 2014 | |
panic(cpu 2 caller 0xffffff8028d26fba): "negative open count (c, 16, 1)"@/SourceCache/xnu/xnu-2050.48.12/bsd/miscfs/specfs/spec_vnops.c:1813 | |
Backtrace (CPU 2), Frame : Return Address | |
0xffffff8233a93be0 : 0xffffff8028c1d636 | |
0xffffff8233a93c50 : 0xffffff8028d26fba | |
0xffffff8233a93c90 : 0xffffff8028d2be46 |
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
;; 1. top-level let | |
(let [state (atom 0)] | |
(defn do-stuff1 [] | |
(swap! state inc)) | |
(defn do-stuff2 [] | |
(swap! state dec))) | |
;; 2. top-level atom | |
(def state (atom 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
;; Don't unroll optional named arguments. | |
;; While it's nice for callers to not have to wrap optional named arguments in a map, | |
;; clearly specified configuration maps are laudable. | |
(release-sharks 2 :laser-beams true) ; good | |
(release-sharks {:laser-beams true} 2) ; better, the configuration is the least variance argument | |
(release-sharks 2 {:laser-beams true}) ; bad |