Skip to content

Instantly share code, notes, and snippets.

View bsteuber's full-sized avatar

Benjamin Teuber bsteuber

View GitHub Profile
(defn rec-find [pred x]
(cond
(pred x) true
(sequential? x) (some #(rec-find pred %)
x)
(map? x) (some #(rec-find pred %)
(vals x))))
(defn fullhouse3 [hand]
(let [index (->> hand
(group-by :rank)
vals
(sort-by (fn [same] [(count same)
(:rank (first same))]
>)))
[fst snd] index]
(when (and (= (count fst) 3)
(>= (count snd) 2))
(defun clojurescript-repl ()
(interactive)
(run-lisp "lein1 trampoline cljsbuild repl-listen")
(paredit-mode +1))
(defn replace-pred-once [pred replacement list]
(let [[bef
[elt & aft]] (split-with (complement pred)
list)]
(concat bef [replacement] aft)))
(comment (replace-pred-once #{5} :foo [1 2 3 4 5 6 7 8 5 3])
=> (1 2 3 4 :foo 6 7 8 5 3)
@bsteuber
bsteuber / gist:0421e6bdb5243d3c7e27
Created July 12, 2014 12:41
Change function printing behavior of cljs
(extend-type js/Function
IPrintWithWriter
(-pr-writer [a writer opts]
(-write writer "#<Fn>")))
;; will give a warning, but work...
;; no assumtion of outer state/events
;; more setup work, more flexibility and straightforward testing
(defn my-component [model event-channel]
[:div.blah
(for [blub @model]
[:div.blub {:on-click #(>! event-channel [:blub-click (:id blub)])}
(:text blub)])])
;; uses global app-state and global event-queue
(def weak-minor-5
[:and
[:length-range 9]
:minor
[:gcp-range 0 14]])
(def weak-major-4
[:and
[:length-range 8]
:major
(ns tools.blitz-test
(:require [cljs.test :refer-macros [is testing]]
[devcards.core :refer-macros [defcard-rg deftest]]
[clojure.string :as str]))
(def group-a
{:players [["Lena" 1 "Trix"]
["Klaus" 1 "GoKlaus"]
["Christoph" 2 "Coreon"]
["Martin" 2 "LDD99"]