Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Teuber bsteuber

View GitHub Profile
View gist:1077871
(defn rec-find [pred x]
(cond
(pred x) true
(sequential? x) (some #(rec-find pred %)
x)
(map? x) (some #(rec-find pred %)
(vals x))))
View gist:1547828
(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))
View gist:2036624
(defun clojurescript-repl ()
(interactive)
(run-lisp "lein1 trampoline cljsbuild repl-listen")
(paredit-mode +1))
View gist:2165263
(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 Jul 12, 2014
Change function printing behavior of cljs
View gist:0421e6bdb5243d3c7e27
(extend-type js/Function
IPrintWithWriter
(-pr-writer [a writer opts]
(-write writer "#<Fn>")))
;; will give a warning, but work...
View gist:3ebab902294a05c01d01
;; 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
View schachcafe.clj
(def weak-minor-5
[:and
[:length-range 9]
:minor
[:gcp-range 0 14]])
(def weak-major-4
[:and
[:length-range 8]
:major
View blitz.cljs
(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"]
You can’t perform that action at this time.