This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-content | |
[content] | |
(into {} (map (fn [c] [(:tag c) (first (:content c))]) (:content content)))) | |
(defn find-products | |
"Crawls the url's sitemap and for each product, will call f with the site and the product" | |
[site url f] | |
(let [p (parse-xml url) | |
tag (:tag p)] | |
(println (str "Parsing URL: " url " for site " site)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.xml :as xml]) | |
(defn parse-xml [url] | |
(try (xml/parse url) | |
(catch Exception e | |
(println | |
(str "Caught Exception parsing xml: " (.getMessage e)))))) | |
(parse-xml "https://bellroy.com/sitemap.xml") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
:tag :urlset, | |
:content [ | |
{:tag :url, :attrs nil, :content [ | |
{:tag :loc, :attrs nil, :content ["https://bellroy.com/journal/carry-portraits-anna-marrone"]} | |
{:tag :lastmod, :attrs nil, :content ["2021-10-06"]} | |
{:tag :changefreq, :attrs nil, :content ["daily"]} | |
{:tag :priority, :attrs nil, :content ["1.0"]}]} | |
{:tag :url, :attrs nil, :content [ | |
{:tag :loc, :attrs nil, :content ["https://bellroy.com/corporate-gifting"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:paths ["src"] | |
:deps {etaoin/etaoin {:mvn/version "0.4.6"} | |
com.taoensso/carmine {:mvn/version "3.1.0"} | |
congomongo/congomongo {:mvn/version "2.2.3"} | |
funcool/cuerdas {:mvn/version "2021.05.29-0"} | |
org.clojure/data.json {:mvn/version "2.4.0"} | |
org.clojure/core.async {:mvn/version "1.3.618"}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<url> | |
<loc>https://bellroy.com/products/pod-jacket</loc> | |
<lastmod>2021-10-26</lastmod> | |
<changefreq>daily</changefreq> | |
<priority>1.0</priority> | |
</url> | |
<url> | |
<loc>https://bellroy.com/journal/the-art-and-science-of-the-aha-moment</loc> | |
<lastmod>2021-10-06</lastmod> | |
<changefreq>daily</changefreq> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn wr-cstring [view string] | |
(binf/wr-string view (str string "\0")) | |
view) | |
(defn rr-cstring [view] | |
(loop [index (binf/position view) acc []] | |
(let [b (binf/rr-u8 view)] | |
(if (zero? b) | |
(.toString | |
(.decode binf.string/decoder-utf-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.9' | |
services: | |
postgres: | |
image: postgres:13 | |
ports: | |
- 5432:5432 | |
environment: | |
POSTGRES_USER: jimmy | |
POSTGRES_PASSWORD: banana | |
POSTGRES_DB: world |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- parse-header [bb] | |
(let [_ (.flip bb) | |
tag (.get bb) | |
len (.getInt bb)] | |
(log/info (str "RECEIVED TAG: " tag ", LENGTH: " len)) | |
[tag len])) | |
(defn- read-message [tag len client] | |
(let [bb (ByteBuffer/allocate (+ 1 len)) ;; Allocate for full message | |
_ (.put bb tag) ;; Add back tag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.clunk.message-socket | |
(:require [clojure.core.match :as m] | |
[clojure.core.async :as async] | |
[octet.core :as buf] | |
[com.clunk.pw :as pw] | |
[com.clunk.codecs :as codecs] | |
[com.clunk.buffer-socket :as bs])) | |
(defrecord MessageSocket [buffer-socket in-ch out-ch]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Utility | |
(defn print-ints | |
"Prints byte array as ints" | |
[ba] | |
(println (map #(int %) ba))) | |
;; Get socket connection | |
(def buffer-socket (get-buffer-socket 5432 "localhost")) | |
;; Startup message for user: "jimmy", and database: "world" |