From 64dde95f82e8e48e1a50389b31f8ec4f9e169b14 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 22 Sep 2021 23:40:12 +0200 Subject: [PATCH 001/208] Update links --- CHANGELOG.md | 2 +- bb.edn | 14 ++++++++++++-- doc/dev.md | 8 ++++---- resources/public/html/cljs-ajax.html | 4 ++-- resources/public/html/export.html | 2 +- resources/public/html/reagent.html | 4 ++-- resources/public/index.html | 2 +- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc7199..a92a013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v0.0.3 +## v0.0.4 - Fixes for `try/catch` diff --git a/bb.edn b/bb.edn index 85cfff1..1eef13f 100644 --- a/bb.edn +++ b/bb.edn @@ -1,6 +1,7 @@ {:tasks {:requires ([babashka.fs :as fs] - [cheshire.core :as json]) + [cheshire.core :as json] + [babashka.process :as p :refer [process]]) clean {:doc "Start from clean slate." :task (do (run! fs/delete (fs/list-dir (fs/file "resources" "public" "js") "**.*")) @@ -33,4 +34,13 @@ (shell "npm publish"))} gh-pages {:doc "Updates Github pages with new release build." - :task (shell "script/release.clj")}}} + :task (shell "script/release.clj")} + + replace-version {:doc "Ported from bash one-liners. Expects two versions. TODO: port to Clojure." + :task + (let [[prev next] *command-line-args*] + (-> (process ["bash" "-c" + (format "rg %s --files-with-matches | xargs sed -i '' 's/%s/%s/g'" + prev prev next)] + {:inherit true}) + p/check))}}} diff --git a/doc/dev.md b/doc/dev.md index f4a4b68..f9a35de 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -47,13 +47,13 @@ To create a new release: To upgrade examples: ``` -rg '0.0.1' --files-with-matches | xargs sed -i '' 's/0.0.1/0.0.3/g' +rg '0.0.1' --files-with-matches | xargs sed -i '' 's/0.0.1/0.0.4/g' bb release cd gh-pages -git checkout -b v0.0.3 -git push --set-upstream origin v0.0.3 +git checkout -b v0.0.4 +git push --set-upstream origin v0.0.4 git checkout gh-pages cd .. ``` -Then make a new release on Github with the `v0.0.3` tag. +Then make a new release on Github with the `v0.0.4` tag. diff --git a/resources/public/html/cljs-ajax.html b/resources/public/html/cljs-ajax.html index dd5f627..b4f09f0 100644 --- a/resources/public/html/cljs-ajax.html +++ b/resources/public/html/cljs-ajax.html @@ -1,7 +1,7 @@ - - + + + + - + + - + diff --git a/resources/public/cljs/bookmarklet.cljs b/resources/public/cljs/bookmarklet.cljs index 79b0585..0f9eb15 100644 --- a/resources/public/cljs/bookmarklet.cljs +++ b/resources/public/cljs/bookmarklet.cljs @@ -41,7 +41,7 @@ } };" "if(typeof scittle === 'undefined'){" - (append-tag :script {:src "https://borkdude.github.io/scittle/js/scittle.js" + (append-tag :script {:src "https://babashka.github.io/scittle/js/scittle.js" :onerror "function(){alert('Error loading ' + this.src)}" :onload "runCode"}) "} else { diff --git a/resources/public/index.html b/resources/public/index.html index d4fb915..6533776 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -60,21 +60,21 @@
-
+

Scittle

What is this?

-

This project exposes the Small Clojure Interpreter in the +

This project exposes the Small Clojure Interpreter in the browser in such a way that you can use it with the script tag.

Project status

This project is still experimental and breaking changes may happen. Feedback is welcome - on Github.

+ on Github.

To use scittle on your own site, it is recommended to use the links published to - the releases + the releases page.

From 728cd304aa0c2f8a48913d71c84483dd55d319d9 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Mon, 7 Feb 2022 18:23:16 +0100 Subject: [PATCH 004/208] Add wordle by oxalorg --- resources/public/cljs/wordle.cljs | 106 ++++++++++++++++++++++++++++++ resources/public/index.html | 1 + resources/public/wordle.html | 39 +++++++++++ script/release.clj | 3 + 4 files changed, 149 insertions(+) create mode 100644 resources/public/cljs/wordle.cljs create mode 100644 resources/public/wordle.html diff --git a/resources/public/cljs/wordle.cljs b/resources/public/cljs/wordle.cljs new file mode 100644 index 0000000..5c1f0a9 --- /dev/null +++ b/resources/public/cljs/wordle.cljs @@ -0,0 +1,106 @@ +;; taken from https://github.com/oxalorg/wordle-clojurescript +(ns wordle.core2) + +(def board-state (atom [])) +(def counter (atom 0)) +(def attempt (atom 0)) +(def word-of-the-day (atom "hello")) + +(defn write-letter [cell letter] + (set! (.-textContent cell) letter)) + +(defn make-cell [] + (let [cell (js/document.createElement "div")] + (set! (.-className cell) "cell") + cell)) + +(defn make-board [n] + (let [board (js/document.createElement "div")] + (set! (.-className board) "board") + ;; adding cells + (doseq [_ (range n)] + (let [cell (make-cell)] + (swap! board-state conj cell) + (.appendChild board cell))) + board)) + +(defn get-letter [cell] + (.-textContent cell)) + +(defn color-cell [idx cell] + (let [color (fn [el color] + (set! (-> el .-style .-backgroundColor) + color)) + letter (get-letter cell)] + (cond + (= letter (nth @word-of-the-day idx)) + (color cell "green") + + (contains? (set @word-of-the-day) letter) + (color cell "aqua") + + :else + (color cell "#333333")))) + +(defn check-solution [cells] + (doseq [[idx cell] (map-indexed vector cells)] + (color-cell idx cell)) + (= (mapv get-letter cells) + (vec @word-of-the-day))) + +(defn user-input [key] + (let [start (* 5 @attempt) + end (* 5 (inc @attempt))] + (cond + (and (re-matches #"[a-z]" key) + (< @counter end)) + (do + (write-letter (nth @board-state @counter) key) + (swap! counter inc)) + + (and (= key "backspace") + (> @counter start)) + (do + (swap! counter dec) + (write-letter (nth @board-state @counter) "")) + + (and (= key "enter") + (zero? (mod @counter 5))) + (do + (when (check-solution (subvec @board-state start end)) + (js/alert "You won")) + (swap! attempt inc)) + + ))) + +(defonce listener (atom nil)) + +(defn ^:dev/before-load unmount [] + (js/document.removeEventListener "keydown" @listener) + (let [app (js/document.getElementById "app")] + (set! (.-innerHTML app) ""))) + +(defn mount [] + (let [app (js/document.getElementById "app") + board (make-board 30) + input-listener + (fn [e] + (user-input (.toLowerCase(.-key e))))] + (.appendChild app board) + (js/console.log board) + (reset! listener input-listener) + (js/document.addEventListener + "keydown" + input-listener))) + +(mount) + +(js/console.log "mounted!") + +(comment + (do + (def sim ["a" "a" "a" "a" "a" "enter" + "e" "h" "o" "l" "o" + "backspace" "k" "enter" + "h" "e" "l" "l" "o" "enter"]) + (run! user-input sim))) diff --git a/resources/public/index.html b/resources/public/index.html index 6533776..ad40432 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -129,6 +129,7 @@