Compare commits

..

10 Commits

@ -1,9 +1,12 @@
#+TITLE: RhymeStorm™ #+TITLE: DarkLimericks
* WGU Evaluator Notes https://darklimericks.com
See [[file:web/README_WGU.org][the WGU Readme]]. The world's largest metal limericks archive on the Web.
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
@ -18,8 +21,7 @@ See [[file:web/README_WGU.org][the WGU Readme]].
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/wgu~ 3. Visit ~http://localhost:8000~
* How To Run Software Locally * How To Run Software Locally
@ -32,21 +34,29 @@ See [[file:web/README_WGU.org][the WGU Readme]].
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 darklimericks.jar~ 3. Navigate to the root directory of this git repo and run ~java -jar web/darklimericks.jar~
4. Visit http://localhost:8000/wgu 4. Visit http://localhost:8000
* Development * 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. 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:depstart uberjar :jar prhyme.jar~. Build ~.jar~ with ~clojure -X:depstar uberjar :jar prhyme.jar~.
* Deployment
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.
You can use ~rsync~ with ~--exclude~ to only sync over the code bits.
* TODO ~rsync --exclude '*/data/*' --exclude '*/images/*' -aLP ./ root@darklimericks.com:/root/darklimericks/~
** Use tightly packed trie for limerick generation Note the ~-L~ to follow symlinks. Locally, I'm symlinking tachyons.css.
** Move limerick-specific code into this repo from Prhyme. The other shortcut I'm taking is that images are stored and served relative to the path of the running application.
Or maybe into its own repo. That means you need to launch the jar file from the ~web~ directory.

@ -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 5432:5432 \ -p 127.0.0.1:5432:5432 \
darklimericks-db darklimericks-db

@ -3,5 +3,6 @@
#+begin_src sh #+begin_src sh
certbot certonly -d darklimericks.com --webroot=/root/darklimericks/web/resources/public certbot certonly -d darklimericks.com --webroot --webroot-path /root/darklimericks/web/resources/public --keep
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

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

@ -1,5 +1,5 @@
{ {
"name": "wgu-app", "name": "rhymestorm-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/wgu/" :output-dir "../resources/public/rhymestorm/"
:assets-path "/assets/" :assets-path "/assets/"
:modules {:main {:init-fn wgu.app/init}} :modules {:main {:init-fn rhymestorm.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 wgu.app (ns rhymestorm.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]

@ -2,7 +2,7 @@
{:min-level :debug} {:min-level :debug}
:com.darklimericks.server.core/server :com.darklimericks.server.core/server
{:port 8000 :handler #ig/ref :com.darklimericks.server.handlers/handler} {:port 8008 :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)
"/wgu/foo.html")) "/rhymestorm/foo.html"))
) )

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

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 wgu-lyric-suggestions (defn rhymestorm-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 (wgu-lyric-suggestions "technology")) (take 5 (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-resource-handler {:allow-symlinks? true (def file-handler (ring/create-file-handler {:allow-symlinks? true
:root "public"})) :root "resources/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 wgu [db cache] (defn rhymestorm [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/wgu request {}))})) (views/rhymestorm 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/wgu-lyric-suggestions target)))}))) (linguistics/rhymestorm-lyric-suggestions target)))})))

@ -139,9 +139,10 @@
[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))
(identicon/generate (-> (:album/name album) (let [icon (identicon/generate
string/lower-case (-> (:album/name album)
(string/replace #" " "-")) 128)) string/lower-case
(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]
["/wgu" ["/rhymestorm"
["" [""
{:name ::wgu {:name ::rhymestorm
:get {:handler (handlers/wgu db cache)} :get {:handler (handlers/rhymestorm 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 wgu (defn rhymestorm
[request {:keys [rhymes rhyming-lyrics lyrics-from-seed]}] [request {:keys [rhymes rhyming-lyrics lyrics-from-seed]}]
[:div [:div
[:h1 "WGU Capstone"] [:h1 "RhymeStorm™"]
[: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
(wgu (rhymestorm
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
(wgu (rhymestorm
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))]
(wgu (rhymestorm
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/wgu-lyric-suggestions (let [suggestions (linguistics/rhymestorm-lyric-suggestions
(-> request :params :seed))] (-> request :params :seed))]
(wgu (rhymestorm
request request
{:lyrics-from-seed {:lyrics-from-seed
[:div [:div

@ -106,18 +106,30 @@
(defn generate (defn generate
"Make a new avatar." "Make a new avatar."
[identifier size] [identifier size]
(let (let [tile-size (quot size tiles-per-side)
[tile-size (quot size tiles-per-side) md5 (digest/md5 identifier)
md5 (digest/md5 identifier) icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB)
icon (BufferedImage. size size BufferedImage/TYPE_INT_RGB) [r g b] (get-color (first (to-numbers md5)))
[r g b] (get-color (first (to-numbers md5))) color (Color. r g b)
color (Color. r g b) draw (.createGraphics icon)]
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))

Loading…
Cancel
Save