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 [a (atom 1)] | |
(defn generate-unique-id | |
"Returns the next value of a thread-safe incrementing variable." | |
[] | |
(swap! | |
a | |
#(inc %)))) | |
;; if we use (def) instead of (defn), we can move the atom variable inside the | |
;; (def) form. We just have to make sure that the atom is only created once, at |
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
(-> | |
(get "/foos/new") | |
(should-see "Create your foo") | |
(submit-form-with {:name "Tommy"}) | |
(follow-redirect) | |
(should-see "Foo created!") | |
(should-see "Tommy")) |
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 probability-of-taking-this-transition | |
[tid incoming-variations transitions payment-rule] | |
(let [this-trans | |
(first | |
(filter #(= tid (:id %)) transitions)), | |
this-variations (this-trans :variations), | |
this-feasibility (this-trans payment-rule), | |
change-points | |
(distinct | |
(for [feas (map payment-rule transitions), |
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
(for [ob j] | |
(for [property (:properties ob)] | |
(merge property (dissoc ob :properties)))) |
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
;; this should let you do something like | |
;; | |
;; (defn foobar | |
;; [x y z] | |
;; (with-defaults | |
;; [x (even? x) 1881 | |
;; y (odd? y) 823] | |
;; (+ x y z))) | |
;; |
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
(reduce | |
(fn [[amount-left coins] denom] | |
(let [{:keys [mod dividend]} (calc-coins amount-left denom)] | |
(if (pos? dividend) | |
[mod (assoc coins denom dividend)] | |
[amount-left coins]))) | |
[amount {}] | |
denoms) |
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
; user=> (flat [[[[[4 55] 6] [6 6 [5 4]]]]]) | |
; [4 55 6 6 6 5 4] | |
(defn flat | |
[coll] | |
(loop [res [], coll coll, stack ()] | |
(if (empty? coll) | |
(if (empty? stack) | |
res | |
(recur res (first stack) (rest stack))) |
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
describe 'VisitCalendarView', -> | |
tr_for = (service_name) -> | |
# This commented version is more direct but jquery seems to bug out on it. | |
# Boo jquery! | |
# $("tr.line-item-view:has(td:first-child:contains(#{service_name}))") | |
$("tr.line-item-view td:first-child:contains(#{service_name})").parent() | |
beforeEach -> | |
ServerMocker.mock_model(ServiceRequest, 'abc123', Fixtures.service_request) |
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 static-field-map | |
[class] | |
(->> | |
class | |
(.getFields) | |
(seq) | |
(map (juxt #(-> % .getName .toLowerCase (.replaceAll "_" "-") keyword) | |
#(.get % class))) | |
(into {}))) |
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
foo.rb:1: syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END | |
foo.rb:1: syntax error, unexpected tIN... |