Compare commits

..

No commits in common. '11e45f8f39663d13c90dca8cec801a0b574a8ae3' and 'e7e66065451e9172ae8ce538ec691df7fa0b0a8a' have entirely different histories.

@ -1,12 +1,9 @@
#+TITLE: DarkLimericks #+TITLE: RhymeStorm™
https://darklimericks.com * WGU Evaluator Notes
The world's largest metal limericks archive on the Web. See [[file:web/README_WGU.org][the WGU Readme]].
This is just meant to be a live demo of a Clojure phonetics library (https://github.com/eihli/phonetics) and a Hidden Markov Model use-case for a Tightly-packed Trie (https://github.com/eihli/clj-tightly-packed-trie).
I also borrowed some functionality from a NLP/rhyme-related codebase that is not yet ready for release (https://github.com/eihli/prhyme).
* How To Initialize Development Environment * How To Initialize Development Environment
@ -21,7 +18,8 @@ I also borrowed some functionality from a NLP/rhyme-related codebase that is not
1. Run ~./db/run.sh && ./kv/run.sh~ to start the docker containers for the database and key-value store. 1. Run ~./db/run.sh && ./kv/run.sh~ to start the docker containers for the database and key-value store.
a. The ~run.sh~ scripts only need to run once. They initialize development data containers. Subsequent development can continue with ~docker start db && docker start kv~. a. The ~run.sh~ scripts only need to run once. They initialize development data containers. Subsequent development can continue with ~docker start db && docker start kv~.
2. Start a Clojure REPL in Emacs, evaluate the ~dev/user.clj~ namespace, and run ~(init)~ 2. Start a Clojure REPL in Emacs, evaluate the ~dev/user.clj~ namespace, and run ~(init)~
3. Visit ~http://localhost:8000~ 3. Visit ~http://localhost:8000/wgu~
* How To Run Software Locally * How To Run Software Locally
@ -34,29 +32,21 @@ I also borrowed some functionality from a NLP/rhyme-related codebase that is not
1. Run ~./db/run.sh && ./kv/run.sh~ to start the docker containers for the database and key-value store. 1. Run ~./db/run.sh && ./kv/run.sh~ to start the docker containers for the database and key-value store.
a. The ~run.sh~ scripts only need to run once. They initialize development data containers. Subsequent development can continue with ~docker start db && docker start kv~. a. The ~run.sh~ scripts only need to run once. They initialize development data containers. Subsequent development can continue with ~docker start db && docker start kv~.
2. The application's ~jar~ builds with a ~make~ run from the root directory. (See [[file:../Makefile][Makefile]]). 2. The application's ~jar~ builds with a ~make~ run from the root directory. (See [[file:../Makefile][Makefile]]).
3. Navigate to the root directory of this git repo and run ~java -jar web/darklimericks.jar~ 3. Navigate to the root directory of this git repo and run ~java -jar darklimericks.jar~
4. Visit http://localhost:8000 4. Visit http://localhost:8000/wgu
* Development
Requires [[https://github.com/tachyons-css/tachyons/][Tachyons CSS]]. There is a symlink in ~web/resources/public~ to the pre-built ~tachyons.css~ and ~tachyons.min.css~ found in the repo.
Build ~.jar~ with ~clojure -X:depstar uberjar :jar prhyme.jar~.
* Deployment * Development
Since I'm developing this independently, it's not a very robust deployment system.
It's nice to have some parts of the repo available on the server; the db/kv scripts for example.
But obviously the album images and the data in the db/kv are going to be different between local and prod. Requires [[https://github.com/tachyons-css/tachyons/][Tachyons CSS]]. There is a symlink in ~web/resources/public~ to the pre-built ~tachyons.css~ and ~tachyons.min.css~ found in the repo.
You can use ~rsync~ with ~--exclude~ to only sync over the code bits. Build ~.jar~ with ~clojure -X:depstart uberjar :jar prhyme.jar~.
~rsync --exclude '*/data/*' --exclude '*/images/*' -aLP ./ root@darklimericks.com:/root/darklimericks/~ * TODO
Note the ~-L~ to follow symlinks. Locally, I'm symlinking tachyons.css. ** Use tightly packed trie for limerick generation
The other shortcut I'm taking is that images are stored and served relative to the path of the running application. ** Move limerick-specific code into this repo from Prhyme.
That means you need to launch the jar file from the ~web~ directory. Or maybe into its own repo.

@ -9,5 +9,5 @@ docker run \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \ -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-e POSTGRES_USER=$POSTGRES_USER \ -e POSTGRES_USER=$POSTGRES_USER \
-v $PGDATA:/var/lib/postgresql/data \ -v $PGDATA:/var/lib/postgresql/data \
-p 127.0.0.1:5432:5432 \ -p 5432:5432 \
darklimericks-db darklimericks-db

@ -3,6 +3,5 @@
#+begin_src sh #+begin_src sh
certbot certonly -d darklimericks.com --webroot --webroot-path /root/darklimericks/web/resources/public --keep certbot certonly -d darklimericks.com --webroot=/root/darklimericks/web/resources/public
cat /etc/letsencrypt/archive/darklimericks.com/privkey.pem >> /etc/letsencrypt/archive/darklimericks.com/fullchain.pem
#+end_src #+end_src

File diff suppressed because it is too large Load Diff

@ -2,7 +2,7 @@
{:min-level :debug} {:min-level :debug}
:com.darklimericks.server.core/server :com.darklimericks.server.core/server
{:port 8008 :handler #ig/ref :com.darklimericks.server.handlers/handler} {:port 8000 :handler #ig/ref :com.darklimericks.server.handlers/handler}
:com.darklimericks.server.worker/limerick-gen :com.darklimericks.server.worker/limerick-gen
{:kv #ig/ref :com.darklimericks.kv.core/connection {:kv #ig/ref :com.darklimericks.kv.core/connection

@ -147,7 +147,7 @@
(:template (:template
(reitit/match-by-path (reitit/match-by-path
(-> state/system :com.darklimericks.server.router/router) (-> state/system :com.darklimericks.server.router/router)
"/rhymestorm/foo.html")) "/wgu/foo.html"))
) )

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 B

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 91 KiB

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 65 KiB

@ -452,7 +452,7 @@
(sort-by (comp - second)) (sort-by (comp - second))
first))) first)))
(defn rhymestorm-lyric-suggestions (defn wgu-lyric-suggestions
"Returns lyrics rhyming with a seed phrase. "Returns lyrics rhyming with a seed phrase.
Groups rhymes by quality then orders each grouping by frequency. Groups rhymes by quality then orders each grouping by frequency.
@ -493,7 +493,7 @@
(comp - last second second)))))) (comp - last second second))))))
(comment (comment
(take 5 (lyric-suggestions "technology")) (take 5 (wgu-lyric-suggestions "technology"))
(phrase->quality-of-rhyme "boss hog" "brain fog") (phrase->quality-of-rhyme "boss hog" "brain fog")

@ -48,8 +48,8 @@
artists-by-album))}))) artists-by-album))})))
(def resource-handler (ring/create-resource-handler {:allow-symlinks? true})) (def resource-handler (ring/create-resource-handler {:allow-symlinks? true}))
(def file-handler (ring/create-file-handler {:allow-symlinks? true (def file-handler (ring/create-resource-handler {:allow-symlinks? true
:root "resources/public"})) :root "public"}))
(defn limerick-generation-post-handler (defn limerick-generation-post-handler
[db cache] [db cache]
@ -256,7 +256,7 @@
{} {}
(views/submit-limericks request []))}))) (views/submit-limericks request []))})))
(defn rhymestorm [db cache] (defn wgu [db cache]
(fn [request] (fn [request]
{:status 200 {:status 200
:headers {"Content-Type" "text/html; charset=utf-8"} :headers {"Content-Type" "text/html; charset=utf-8"}
@ -264,7 +264,7 @@
{:db db {:db db
:request request :request request
:opts {}} :opts {}}
(views/rhymestorm request {}))})) (views/wgu request {}))}))
(defn rhyming-lyric [db cache] (defn rhyming-lyric [db cache]
(fn [request] (fn [request]
@ -329,4 +329,4 @@
:opts {}} :opts {}}
(views/lyrics-from-seed (views/lyrics-from-seed
request request
(linguistics/rhymestorm-lyric-suggestions target)))}))) (linguistics/wgu-lyric-suggestions target)))})))

@ -139,10 +139,9 @@
[artist-id album-id] album-artist [artist-id album-id] album-artist
album (albums/album db album-id)] album (albums/album db album-id)]
(when (:new-album (meta album-artist)) (when (:new-album (meta album-artist))
(let [icon (identicon/generate (identicon/generate (-> (:album/name album)
(-> (:album/name album) string/lower-case
string/lower-case (string/replace #" " "-")) 128))
(string/replace #" " "-")) 128)]))
(db.limericks/insert-user-limerick (db.limericks/insert-user-limerick
db db
session-id session-id

@ -34,10 +34,10 @@
:parameters {:path {:artist-id int?}} :parameters {:path {:artist-id int?}}
:get {:handler (handlers/artist-get-handler db)}}]] :get {:handler (handlers/artist-get-handler db)}}]]
["/assets/*" handlers/file-handler] ["/assets/*" handlers/file-handler]
["/rhymestorm" ["/wgu"
["" [""
{:name ::rhymestorm {:name ::wgu
:get {:handler (handlers/rhymestorm db cache)} :get {:handler (handlers/wgu db cache)}
:post {:handler (handlers/rhyming-lyric db cache)}}] :post {:handler (handlers/rhyming-lyric db cache)}}]
["/rhyme" ["/rhyme"
{:name ::rhyme {:name ::rhyme

@ -280,10 +280,10 @@
(for [line (string/split (:limerick/text limerick) #"\n")] (for [line (string/split (:limerick/text limerick) #"\n")]
[:div line])]]))]) [:div line])]]))])
(defn rhymestorm (defn wgu
[request {:keys [rhymes rhyming-lyrics lyrics-from-seed]}] [request {:keys [rhymes rhyming-lyrics lyrics-from-seed]}]
[:div [:div
[:h1 "RhymeStorm™"] [:h1 "WGU Capstone"]
[:div [:div
[:h2 "Generate Rhyme"] [:h2 "Generate Rhyme"]
@ -371,7 +371,7 @@ prefixes to that rhyming phrase."]
(defn lyric-suggestions (defn lyric-suggestions
[request suggestions] [request suggestions]
[:div [:div
(rhymestorm (wgu
request request
{:rhyming-lyrics {:rhyming-lyrics
[:table {:style "margin: auto;"} [:table {:style "margin: auto;"}
@ -392,7 +392,7 @@ prefixes to that rhyming phrase."]
(defn show-rhyme-suggestion (defn show-rhyme-suggestion
[request suggestions] [request suggestions]
[:div [:div
(rhymestorm (wgu
request request
{:rhymes {:rhymes
(for [[suggestion p1 freq _ p2 quality] suggestions] (for [[suggestion p1 freq _ p2 quality] suggestions]
@ -417,7 +417,7 @@ prefixes to that rhyming phrase."]
(juxt (comp - :rhyme-quality) (juxt (comp - :rhyme-quality)
(comp - :freq)) (comp - :freq))
top-20-by-quality))] top-20-by-quality))]
(rhymestorm (wgu
request request
{:rhymes {:rhymes
[:div [:div
@ -513,9 +513,9 @@ Words may appear twice if they have multiple pronunciations."]
(defn lyrics-from-seed (defn lyrics-from-seed
[request seed] [request seed]
(let [suggestions (linguistics/rhymestorm-lyric-suggestions (let [suggestions (linguistics/wgu-lyric-suggestions
(-> request :params :seed))] (-> request :params :seed))]
(rhymestorm (wgu
request request
{:lyrics-from-seed {:lyrics-from-seed
[:div [:div

@ -106,30 +106,18 @@
(defn generate (defn generate
"Make a new avatar." "Make a new avatar."
[identifier size] [identifier size]
(let [tile-size (quot size tiles-per-side) (let
md5 (digest/md5 identifier) [tile-size (quot size tiles-per-side)
icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB) md5 (digest/md5 identifier)
[r g b] (get-color (first (to-numbers md5))) icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB)
color (Color. r g b) [r g b] (get-color (first (to-numbers md5)))
draw (.createGraphics icon)] color (Color. r g b)
draw (.createGraphics icon)]
(fill-background draw size) (fill-background draw size)
(.setColor draw color) (.setColor draw color)
(draw-it draw tile-size 0 (to-bools md5)) (draw-it draw tile-size 0 (to-bools md5))
(ImageIO/write icon "png" (File. (file-name identifier size))) (ImageIO/write icon "png" (File. (file-name identifier size)))
file-name)) file-name))
(defn generate-sans-write
"Make a new avatar."
[identifier size]
(let [tile-size (quot size tiles-per-side)
md5 (digest/md5 identifier)
icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB)
[r g b] (get-color (first (to-numbers md5)))
color (Color. r g b)
draw (.createGraphics icon)]
(fill-background draw size)
(.setColor draw color)
(draw-it draw tile-size 0 (to-bools md5))))
(comment (comment
(generate "foobar-bazz" 128)) (generate "foobar-bazz" 128))

@ -1,5 +1,5 @@
{ {
"name": "rhymestorm-app", "name": "wgu-app",
"version": "0.0.1", "version": "0.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,

@ -1,5 +1,5 @@
{ {
"name": "rhymestorm-app", "name": "wgu-app",
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"devDependencies": { "devDependencies": {

@ -17,9 +17,9 @@
:builds :builds
{:frontend {:frontend
{:target :browser {:target :browser
:output-dir "../resources/public/rhymestorm/" :output-dir "../resources/public/wgu/"
:assets-path "/assets/" :assets-path "/assets/"
:modules {:main {:init-fn rhymestorm.app/init}} :modules {:main {:init-fn wgu.app/init}}
:devtools {:preloads [day8.re-frame-10x.preload]} :devtools {:preloads [day8.re-frame-10x.preload]}
:dev {:compiler-options :dev {:compiler-options
{:closure-defines {:closure-defines

@ -1,4 +1,4 @@
(ns rhymestorm.app (ns wgu.app
(:require ["chart.js/auto" :as chart] (:require ["chart.js/auto" :as chart]
[oz.core :as oz] [oz.core :as oz]
[reagent.dom :as rdom] [reagent.dom :as rdom]
Loading…
Cancel
Save