Skip to content

Instantly share code, notes, and snippets.

(ns rules-to-pred)
(def products
[{:id 1
:department "bedding"
:category "pillow"
:color "white"}
{:id 2
:department "cloth"
:category "shirt"
(ns correct-tags.use-parser
(:require [instaparse.core :as insta]))
; Additional dependencies
; [instaparse "1.4.10"]]
; https://github.com/Engelberg/instaparse
(def annot-parser
(insta/parser
"LINE = ('|' GROUP)+ '|'
@visibletrap
visibletrap / light.clj
Last active March 12, 2019 15:30
deps.edn + ring + compojure as a single executable shell script file. Inspired by https://gist.github.com/ericnormand/6bb4562c4bc578ef223182e3bb1e72c5
#!/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 March 12, 2019 14:56
deps.edn + ring + compojure
{: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"}}}
(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"])
(defn hangman [secret-words letters]
(->> secret-words
(map str)
(every? (set letters))))
@visibletrap
visibletrap / group_address.clj
Last active May 7, 2018 08:29
Input: [{:province :a, :district :b, :amphoe :c}, {:province :a, :district :k, :amphoe :g}], Output: {:a {:c [:b], :g [:k]}}
(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 06:06
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]}
(->> {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]}
(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 February 25, 2018 18:48
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
{:paths ["."]
:deps {org.clojure/clojurescript
{:git/url "https://github.com/clojure/clojurescript"
:sha "3f4084efcb5cd92cceb8ca30765144691d8cfd7e"}}}