diff --git a/assets/notes-example.png b/assets/notes-example.png deleted file mode 100644 index 4434ef35..00000000 Binary files a/assets/notes-example.png and /dev/null differ diff --git a/examples/README.md b/examples/README.md index f6a41862..8e1698ff 100644 --- a/examples/README.md +++ b/examples/README.md @@ -249,8 +249,6 @@ is a variation on the [http-server](https://github.com/borkdude/babashka/#tiny-http-server) example. If you get prompted with a login, use `admin`/`admin`. - - ## which The `which` command re-implemented in Clojure. See @@ -317,10 +315,22 @@ See [examples/vim.clj](examples/vim.clj). This script uses [djblue/portal](https://github.com/djblue/portal/) for inspecting EDN, JSON, XML or YAML files. -Examples usage: +Example usage: ``` shell $ examples/portal.clj ~/git/clojure/pom.xml ``` See [portal.clj](portal.clj). + +### Image viewer + +Opens browser window and lets user navigate through images of all sub-directories. + +Example usage: + +``` shell +$ examples/image_viewer.clj +``` + +See [image_viewer.clj](image_viewer.clj). diff --git a/examples/image_viewer.clj b/examples/image_viewer.clj new file mode 100755 index 00000000..5af2c489 --- /dev/null +++ b/examples/image_viewer.clj @@ -0,0 +1,68 @@ +#!/usr/bin/env bb + +(ns image-viewer + (:require [clojure.java.browse :as browse] + [clojure.java.io :as io] + [clojure.string :as str] + [org.httpkit.server :as server]) + (:import [java.net URLDecoder URLEncoder])) + +(def images + (filter #(and (.isFile %) + (let [name (.getName %) + ext (some-> (str/split name #"\.") + last + str/lower-case)] + (contains? #{"jpg" "jpeg" "png" "gif" "svg"} ext))) + (file-seq (io/file ".")))) + +(def image-count (count images)) + +(defn page [n] + (let [prev (max 0 (dec n)) + next (min (inc n) (dec image-count)) + file-path (.getCanonicalPath (nth images n)) + encoded-file-path (URLEncoder/encode file-path)] + {:body (format " + + + + + + + +Navigation: use left/right arrow keys +

%s

+
+ +
+
+
+ + +" prev next file-path encoded-file-path)})) + +(server/run-server + (fn [{:keys [:uri]}] + (if (str/starts-with? uri "/assets") + ;; serve the file + (let [f (io/file (-> (str/replace uri "assets" "") + (URLDecoder/decode)))] + {:body f}) + ;; serve html + (let [n (-> (str/replace uri "/" "") + (Integer/parseInt))] + (page n))))) + +(browse/browse-url "http://localhost:8090/0") + +@(promise) diff --git a/process b/process index 98056d87..249ddcfd 160000 --- a/process +++ b/process @@ -1 +1 @@ -Subproject commit 98056d87e34a9bf56fcc11ca23ae19c69783455f +Subproject commit 249ddcfd1a5825f33adacc9cfde72a0c3823bdc9