Add code related to rhyming and ssl

main
Eric Ihli 3 years ago
parent 5221ed5f8f
commit 651c003d4e

@ -10,13 +10,17 @@ darklimericks.jar: $(src)
cd web && clj -A:depstar -M:depstar -m hf.depstar.uberjar \
darklimericks.jar -C -m com.darklimericks.server.core
FORCE:
build: FORCE
cd web && clj -A:depstar -M:depstar -m hf.depstar.uberjar \
darklimericks.jar -C -m com.darklimericks.server.core
FORCE:
push: FORCE
rsync -aP web/darklimericks.jar root@165.227.16.47:/root/darklimericks/web/
certs:
ssh root@darklimericks.com \
certbot certonly -d darklimericks.com \
--webroot --webroot-path /root/darklimericks/web/resources/public --keep
# end

@ -0,0 +1,14 @@
defaults
timeout connect 10s
timeout client 30s
timeout server 30s
mode http
frontend http-in
bind :80
bind *:443 ssl crt /etc/ssl/cert.pem
redirect scheme https if !{ ssl_fc }
default_backend app
backend app
server darklimericks darklimericks:8000

@ -0,0 +1,43 @@
#!/bin/sh
KEYSTORE_DOMAIN="${KEYSTORE_DOMAIN:-darklimericks.com}"
KEYSTORE_PASS="${KEYSTORE_PASS:-hunter22}"
# Create keystore
echo "Refreshing '~/ssl/$KEYSTORE_DOMAIN.keystore'"
openssl pkcs12 -export \
-in /etc/letsencrypt/live/$KEYSTORE_DOMAIN/cert.pem \
-inkey /etc/letsencrypt/live/$KEYSTORE_DOMAIN/privkey.pem \
-out /tmp/$KEYSTORE_DOMAIN.p12 \
-name $KEYSTORE_DOMAIN \
-CAfile /etc/letsencrypt/live/$KEYSTORE_DOMAIN/fullchain.pem \
-caname "Let's Encrypt Authority X3" \
-password pass:$KEYSTORE_PASS
keytool -importkeystore \
-deststorepass $KEYSTORE_PASS \
-destkeypass $KEYSTORE_PASS \
-deststoretype pkcs12 \
-srckeystore /tmp/$KEYSTORE_DOMAIN.p12 \
-srcstoretype PKCS12 \
-srcstorepass $KEYSTORE_PASS \
-destkeystore /tmp/$KEYSTORE_DOMAIN.keystore \
-alias $KEYSTORE_DOMAIN
# Move certificates to other servers
echo "Copy '~/ssl/$KEYSTORE_DOMAIN.keystore' to cluster servers"
cp /tmp/$KEYSTORE_DOMAIN.keystore /root/ssl/$KEYSTORE_DOMAIN.keystore
# Create truststore
echo "Refreshing '~/ssl/theirdomain.be.keystore'"
rm theirdomain.be.keystore
openssl s_client -connect theirdomain.be:443 -showcerts </dev/null 2>/dev/null|openssl x509 -outform DER >theirdomain.der
openssl x509 -inform der -in theirdomain.der -out theirdomain.pem
keytool -import \
-alias theirdomain \
-keystore theirdomain.be.keystore \
-file ./theirdomain.pem \
-storepass theirdomain \
-noprompt
echo "Copy '~/ssl/theirdomain.be.keystore' to cluster servers"
cp theirdomain.be.keystore /home/admin_jworks/ssl/
sudo scp ssl/theirdomain.be.keystore cc-backend-node-02:/home/admin_jworks/ssl/
sudo scp ssl/theirdomain.be.keystore cc-frontend-node-01:/home/admin_jworks/ssl/

@ -133,6 +133,10 @@
(handler {:params {:rhyme-target "foo"}
::reitit/router router}))
(let [router (state/system :com.darklimericks.server.router/router)]
(reitit/match-by-path router "/.well-known/foo.txt"))
(db.albums/num-albums
(-> state/system :database.sql/connection))

@ -1,16 +1,19 @@
(ns com.darklimericks.linguistics.core
(:require [com.owoga.prhyme.data.dictionary :as dict]
[com.owoga.prhyme.core :as prhyme]
[com.darklimericks.server.models :as models]
[com.owoga.corpus.markov :as markov]
[clojure.string :as string]))
(defn gen-artist []
(->> [(rand-nth (seq dict/adverbs))
(->> [(rand-nth (seq dict/adjectives))
(rand-nth (seq dict/nouns))]
(map string/capitalize)
(string/join " ")))
(defn gen-album []
(->> [(rand-nth (seq dict/adjectives))
(rand-nth (seq dict/nouns))]
(->> [(rand-nth (seq dict/adverbs))
(rand-nth (seq dict/verbs))]
(map string/capitalize)
(string/join " ")))
@ -18,4 +21,15 @@
(defn rhymes
"All rhymes. Slightly flexible. Ordered by number of rhyming syllables.
Most generic and likely desired rhyming algorithm."
[target])
[target]
(->> (prhyme/phrase->all-flex-rhyme-tailing-consonants-phones target)
(map first)
(map reverse)
(mapcat (partial markov/rhyme-choices models/rhyme-trie))
(sort-by (comp - count first))
(mapcat second)))
(comment
(rhymes "food")
)

@ -16,7 +16,8 @@
[com.darklimericks.db.limericks :as db.limericks]
[com.darklimericks.db.artists :as db.artists]
[com.darklimericks.server.views :as views]
[com.darklimericks.server.limericks :as limericks]))
[com.darklimericks.server.limericks :as limericks]
[com.darklimericks.linguistics.core :as linguistics]))
(defmethod ig/init-key ::handler [_ {:keys [router]}]
(http/ring-handler
@ -264,10 +265,13 @@
(defn show-rhyme-suggestion [db cache]
(fn [request]
(let [suggestions (linguistics/rhymes (:rhyme-target (:params request)))]
{:status 201
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (views/wrapper
db
request
{}
(views/show-rhyme-suggestion request))}))
(views/show-rhyme-suggestion
request
suggestions))})))

@ -2,6 +2,7 @@
(:require [clojure.string :as string]
[clojure.java.io :as io]
[reitit.core :as reitit]
[com.darklimericks.server.models :as models]
[com.darklimericks.db.artists :as artists]
[com.darklimericks.db.albums :as albums]
[com.darklimericks.db.limericks :as db.limericks]
@ -12,7 +13,6 @@
[com.owoga.corpus.markov :as markov]
[com.owoga.prhyme.data-transform :as data-transform]
[com.owoga.tightly-packed-trie.encoding :as encoding]
[taoensso.nippy :as nippy]
[taoensso.timbre :as timbre]))
(defn parse-scheme-element [[tokens ctx]]
@ -104,12 +104,6 @@
(map string/capitalize)
(string/join " ")))
(def database (nippy/thaw-from-resource "models/database.bin"))
(def rhyme-trie (into (trie/make-trie) (nippy/thaw-from-resource "models/rhyme-trie.bin")))
(def markov-trie (tpt/load-tightly-packed-trie-from-file
(io/resource "models/tpt.bin")
(markov/decode-fn database)))
(comment
(->> (markov/rhyme-from-scheme
'[[A 9] [A 9] [B 6] [B 6] [A 9]]
@ -127,9 +121,9 @@
(let [{:keys [scheme session-id]} message
limerick (->> (markov/rhyme-from-scheme
scheme
database
markov-trie
rhyme-trie)
models/database
models/markov-trie
models/rhyme-trie)
(map reverse)
(map (partial map second))
(map data-transform/untokenize))

@ -0,0 +1,12 @@
(ns com.darklimericks.server.models
(:require [taoensso.nippy :as nippy]
[com.owoga.trie :as trie]
[com.owoga.tightly-packed-trie :as tpt]
[clojure.java.io :as io]
[com.owoga.corpus.markov :as markov]))
(def database (nippy/thaw-from-resource "models/database.bin"))
(def rhyme-trie (into (trie/make-trie) (nippy/thaw-from-resource "models/rhyme-trie.bin")))
(def markov-trie (tpt/load-tightly-packed-trie-from-file
(io/resource "models/tpt.bin")
(markov/decode-fn database)))

@ -5,7 +5,8 @@
[reitit.coercion.spec]
[reitit.http.interceptors.parameters :refer [parameters-interceptor]]
[com.darklimericks.server.handlers :as handlers]
[com.darklimericks.server.interceptors :as interceptors]))
[com.darklimericks.server.interceptors :as interceptors]
[reitit.ring :as ring]))
(defmethod ig/init-key ::router [_ {:keys [db cache]}]
(let [routes [["/" {:name ::home
@ -36,7 +37,9 @@
["/wgu"
{:name ::wgu
:get {:handler (handlers/wgu db cache)}
:post {:handler (handlers/show-rhyme-suggestion db cache)}}]]]
:post {:handler (handlers/show-rhyme-suggestion db cache)}}]
["/.well-known/*" (ring/create-file-handler
{:root "resources/public/.well-known"})]]]
(timbre/info "Starting router.")
(http/router
routes

@ -207,7 +207,8 @@
"Show rhyme suggestions"))])
(defn show-rhyme-suggestion
[request]
[request suggestions]
[:div
(wgu request)
[:div "Hi"]])
(for [suggestion suggestions]
[:div suggestion])])

Loading…
Cancel
Save