<commit_before>(ns lambda-blog.utils
  (:require [clj-time.format :as f]
            [clojure.string :refer [split]]
            [ring.util.codec :refer [url-encode]]))

(defn- parse [separator path]
  (when path
    (split path separator)))

(defn- join
  ([] ".")
  ([a] a)
  ([a b] (str a "/" b)))

(defn pathcat [& parts]
  (reduce join
          (filter (complement empty?)
                  (flatten (map (partial parse #"/")
                                parts)))))

(defn format-date [timestamp]
  (f/unparse (f/formatter "YYYY-MM-dd HH:mm")
             (f/parse timestamp)))

(defn sanitize [name]
  ;; FIXME Probably needs to be FS safe in addition to being URL-safe.
  (when name
    (url-encode name)))<commit_msg>Added docstrings to the lambda-blog.utils namespace.<commit_after>(ns lambda-blog.utils
  "Various useful utilities."
  (:require [clj-time.format :as f]
            [clojure.string :refer [split]]
            [ring.util.codec :refer [url-encode]]))

(defn- parse [separator path]
  (when path
    (split path separator)))

(defn- join
  ([] ".")
  ([a] a)
  ([a b] (str a "/" b)))

(defn pathcat
  "Concatenates filesystem/URL paths `parts` while maintaining correct format."
  [& parts]
  (reduce join
          (filter (complement empty?)
                  (flatten (map (partial parse #"/")
                                parts)))))

(defn format-date
  "Formats a `timestamp` according to a given format."
  [timestamp]
  (f/unparse (f/formatter "YYYY-MM-dd HH:mm")
             (f/parse timestamp)))

(defn sanitize
  "Sanitizes a `string` for use in URLs and filesystem paths."
  [string]
  ;; FIXME Probably needs to be FS safe in addition to being URL-safe.
  (when string
    (url-encode string)))
{'fraction_non_alphanumeric': 0.14507772020725387, 'fraction_numerical': 0.0, 'mean_word_length': 2.4145383104125737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6927989', 'n_tokens_mistral': 585, 'n_tokens_neox': 559, 'n_words': 175}