Skip to content

Instantly share code, notes, and snippets.

Nuttanart Pornprasitsakul visibletrap

View GitHub Profile
@visibletrap
visibletrap / light.clj
Last active Mar 12, 2019
deps.edn + ring + compojure as a single executable shell script file. Inspired by https://gist.github.com/ericnormand/6bb4562c4bc578ef223182e3bb1e72c5
View light.clj
#!/bin/sh
#_(
DEPS='
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
ring/ring-core {:mvn/version "1.7.1"}
ring/ring-jetty-adapter {:mvn/version "1.7.1"}
compojure {:mvn/version "1.6.1"}}}
'
@visibletrap
visibletrap / deps.edn
Created Mar 12, 2019
deps.edn + ring + compojure
View deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
ring/ring-core {:mvn/version "1.7.1"}
ring/ring-jetty-adapter {:mvn/version "1.7.1"}
compojure {:mvn/version "1.6.1"}}}
View reactive-hangman.repl
(require '[cognitect.transcriptor :refer (check!)])
(require '[hangman.reactive-hangman :refer :all])
(comment "win case")
(-> (init-game-data "bigbear" 7)
(prefill-letters ["a"])
(handle-new-event [:guess "b"])
(handle-new-event [:guess "o"])
View hangman.clj
(defn hangman [secret-words letters]
(->> secret-words
(map str)
(every? (set letters))))
@visibletrap
visibletrap / group_address.clj
Last active May 7, 2018
Input: [{:province :a, :district :b, :amphoe :c}, {:province :a, :district :k, :amphoe :g}], Output: {:a {:c [:b], :g [:k]}}
View group_address.clj
(defn group-amphoes [locations]
(->> locations
(group-by :amphoe)
(map (juxt first (comp #(mapv :district %) second)))
(into {})))
(defn group-provinces [locations]
(->> locations
(group-by :province)
(map (juxt first (comp group-amphoes second)))
@visibletrap
visibletrap / swap-group.clj
Last active May 3, 2018
Given input: {1 [:a :b], 2 [:a], 3 [:b], 4 [:b :c], 5 [:a], 6 [:a :c :e]}. Expected output: {:a [1 2 5 6], :b [1 3 4], :c [4 6], :e [6]}
View swap-group.clj
(->> {1 [:a :b], 2 [:a], 3 [:b], 4 [:b :c], 5 [:a], 6 [:a :c :e]}
(map (fn [[k v]] (zipmap v (repeat [k]))))
(apply merge-with into))
;=> {:a [1 2 5 6], :b [1 3 4], :c [4 6], :e [6]}
View transducer-walkthrough.clj
(ns playground.transducer)
(def f1 (comp #(map str %) #(filter even? %) #(map inc %))) ; right -> left
(def nums [4 7 8 9 5 3])
(f1 nums)
(defn f2 [x]
(map str (filter even? (map inc x))))
@visibletrap
visibletrap / deps.edn
Last active Feb 25, 2018
clj -Sdeps '{:deps {gist-visibletrap/git-6c21d7956211bcd30fc0a83ccea89455 {:git/url "https://gist.github.com/visibletrap/6c21d7956211bcd30fc0a83ccea89455" :sha "ac630e7d1d2f8e4174cc011386f66cecee4377d7"}}}' -m cljs.main -re node -m hello-cljs
View deps.edn
{:paths ["."]
:deps {org.clojure/clojurescript
{:git/url "https://github.com/clojure/clojurescript"
:sha "3f4084efcb5cd92cceb8ca30765144691d8cfd7e"}}}
@visibletrap
visibletrap / deps.edn
Last active Feb 23, 2018
$ clojure -Sdeps '{:deps {gist-test {:git/url "https://gist.github.com/vi…/af6ba33c6a44bf97b7b013cd7441fbce" :sha "0adfc540f25ec7a9c7fc7972935025e10b5238ac"}}}' -m gist-test
View deps.edn
{:paths ["."]
:deps {org.clojure/math.combinatorics {:mvn/version "0.1.4"}}}
View color-shades.edn
{"white" #{"anti-flash" "antique" "beige" "blond" "cornsilk" "cosmic latte" "cream" "eggshell"
"floral" "ghost" "honeydew" "isabelline" "ivory" "lavender blush" "lemon chiffon"
"linen" "magnolia" "mint cream" "navajo" "old lace" "papaya whip" "peach" "pearl"
"seashell" "snow" "splashed" "vanilla" "white" "smoke"}
"yellow" #{"amber" "apricot" "arylide" "aureolin" "beige" "buff" "chartreuse" "citrine" "cream"
"dark goldenrod" "ecru" "flax" "gold" "gold (metallic)" "goldenrod" "harvest gold"
"jasmine" "jonquil" "khaki" "lemon chiffon" "lion" "maize" "mikado" "mustard" "naples"
"navajo white" "old gold" "olive" "papaya whip" "saffron" "school bus" "selective"
"stil de grain" "straw" "sunglow" "vanilla" "yellow"}
"gray" #{"ash" "battleship" "black" "blue-gray" "cadet" "charcoal" "cool" "davy's" "gray"
You can’t perform that action at this time.