Skip to content

Instantly share code, notes, and snippets.

@visibletrap
visibletrap / deps.edn
Last active February 23, 2018 09:53
$ clojure -Sdeps '{:deps {gist-test {:git/url "https://gist.github.com/vi…/af6ba33c6a44bf97b7b013cd7441fbce" :sha "0adfc540f25ec7a9c7fc7972935025e10b5238ac"}}}' -m gist-test
{:paths ["."]
:deps {org.clojure/math.combinatorics {:mvn/version "0.1.4"}}}
{"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"
(defn collify [x-or-coll]
(if (coll? x-or-coll)
x-or-coll
[x-or-coll]))
(defn keyword->symbol [k]
(symbol (name k)))
(defmacro expand-set-values
[attributes]
(ns sof.async
(:require [ring.adapter.jetty :as jetty]
[clj-http.client :as client]
[ring.middleware.json :refer [wrap-json-response]]
[ring.util.response :refer [response]]))
(defn handler [request respond raise]
(client/get "http://example.com"
{:async? true}
(fn [response] (respond {:body "something"}))
@visibletrap
visibletrap / model.clj
Created September 19, 2017 16:21
ui/run-game
(ns clojure-playground.tap.model)
(def empty-board
[[:_ :_ :_]
[:_ :_ :_]
[:_ :_ :_]])
(def win-patterns
[[[0 0] [1 0] [2 0]]
[[0 1] [1 1] [2 1]]
@visibletrap
visibletrap / one-two-three.clj
Last active December 7, 2017 05:32
Input is a file contains html of comment section of this post https://www.facebook.com/roofimon.class/posts/10154689730497047
; :dependencies [[hickory "0.7.1"]]
(require '[clojure.pprint :refer [print-table]]
'[clojure.string :as string]
'[hickory.core :refer [as-hickory parse]]
'[hickory.select :as s])
(def choices #{"1 2 3" "2 3 1" "3 1 2" "1 3 2" "3 2 1" "2 1 3"})
(def meanings
(ns indent-tree.core
(:require [clojure.string :as string]))
(defn resolve-insert-path [full-tree level]
(:path
(reduce (fn [{:keys [path tree] :as current} n]
(let [after-last-child-pos (count (second tree))]
(if (= n 1)
(-> current
(update :path into [1 after-last-child-pos])
(ns notebook.core
(:require [clj-http.client :as http]
[clojure.data.json :as json]
[clojure.string :as string]))
(set! *print-length* -1)
(def notebooks (json/read-str (:body (http/get "https://notebookspec.com/api/notebook"))
:key-fn keyword))
(ns codebattle101
(:require [clojure.math.combinatorics :as math]))
(defn find-better [target best [a b] input-list]
(let [ab (* a b)]
(loop [[current-min-diff :as current-best] best
l 0
r (count input-list)]
(let [pos (quot (+ l r) 2)
c (get input-list pos)
@visibletrap
visibletrap / ext.clj
Last active June 2, 2017 10:18
Thanks to @seancorfield: "We wrote our own `condp->` and `condp->>` macros that thread through the predicate as well as the expression." -- https://clojurians-log.clojureverse.org/clojure/2017-06-01.html#inst-2017-06-01T04:38:05.966147Z
(defmacro condp->
"Takes an expression and a set of predicate/form pairs. Threads expr (via ->)
through each form for which the corresponding predicate is true of expr.
Note that, unlike cond branching, condp-> threading does not short circuit
after the first true test expression."
[expr & clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[pred step]] `(if (~pred ~g) (-> ~g ~step) ~g))]
`(let [~g ~expr