This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn tie-knot-round | |
[current-list knot-lengths skip-size offset] | |
(if (empty? knot-lengths) | |
{:result current-list :skip-size skip-size :offset offset} | |
(let [cycle-list (cycle current-list) | |
knot-length (first knot-lengths) | |
non-knot-length (- (count current-list) knot-length) | |
new-offset (mod (+ knot-length skip-size offset) (count current-list)) | |
reversed-list (reverse (take knot-length cycle-list)) | |
rest-of-list (take non-knot-length (drop knot-length cycle-list)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn ^:export marshall-object [perms] | |
(->> | |
(js->clj perms) | |
(map (juxt (fn [p] (get-in p ["modules" 0])) (fn [p] [(identity p)]))) | |
(map (partial apply hash-map)) | |
(apply merge-with into) | |
(clj->js))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<div id="app"> | |
</div> | |
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> | |
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn mouse | |
([board] | |
(let [raw-board | |
(for | |
[x (range (-> board first count)) | |
y (range (count board)) | |
:let [mouse? (= \M (get-in board [y x])) | |
cheese? (= \C (get-in board [y x]))]] | |
{:x x :y y :mouse mouse? :cheese cheese?}) | |
[cheese-location mouse-location] (->> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn find-subcoll-of-equal-int-nonint [coll] | |
(let [partition-even (if (even? (count coll)) (count coll) (dec (count coll))) | |
coll-sizes (range partition-even 0 -2) | |
candidates (reduce concat (map #(partition % 1 coll) coll-sizes)) | |
candidates-group (map (juxt identity (partial group-by integer?)) candidates) | |
match (some | |
(fn [[candidate count-map]] | |
(and (= (count (count-map false)) (count (count-map true))) candidate)) candidates-group)] | |
match)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns testnut.components.watcher | |
(:require [com.stuartsierra.component :as component] | |
[suspendable.core :refer [Suspendable]] | |
[hawk.core :as hawk] | |
[clojure.java.shell :as shell])) | |
(defrecord Watcher [watcher] | |
component/Lifecycle | |
(start [component] | |
(let [watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while inotifywait --format '%f' --exclude '.git' --exclude ".#" -r -q -e modify -e move -e create -e delete .; do | |
echo '(reset)' | lein repl :connect `cat .nrepl-port` | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrecord FigwheelSystem [system] | |
component/Lifecycle | |
(start [this] | |
(if-not (:system-running this) | |
(do | |
(swap! system component/start) | |
(assoc this :system-running true)) | |
this)) | |
(stop [this] | |
(if (:system-running this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script> | |
var args = { | |
headers: new Headers({ | |
'Content-Type': 'text/plain' | |
})}; | |
async function useAwaits() { | |
try { | |
let resp = await fetch("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&origin=*&search=stack&limit=10", args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn hiccup-zip | |
"Returns a zipper for hiccup vectors" | |
[root] | |
(clojure.zip/zipper #(or (vector? %) (seq? %)) | |
seq | |
(fn [node children] | |
(if (keyword? (first children)) | |
(with-meta (vec children) (meta node)) | |
(with-meta children (meta node)))) | |
root)) |