Skip to content

Instantly share code, notes, and snippets.

@escherize
Created December 14, 2023 02:09
Show Gist options
  • Save escherize/f308ee4ee58970671de3d2da93b8c76c to your computer and use it in GitHub Desktop.
Save escherize/f308ee4ee58970671de3d2da93b8c76c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bb
(ns emoji-hash
(:require [babashka.deps :as deps]
[babashka.http-client :as http]
[cheshire.core :as json]
[clj-yaml.core :as yaml]
[clojure.data.xml :as xml]
[clojure.edn :as edn]
[selmer.parser :refer [<<]]
[clojure.string :as str]))
#_(deps/add-deps '{:deps {}})
(def emojis
["๐Ÿ˜€" "๐Ÿ˜" "๐Ÿ˜‚" "๐Ÿ˜ƒ" "๐Ÿ˜„" "๐Ÿ˜…" "๐Ÿ˜†" "๐Ÿ˜‡" "๐Ÿ˜ˆ" "๐Ÿ˜‰" "๐Ÿ˜Š" "๐Ÿ˜‹" "๐Ÿ˜Œ" "๐Ÿ˜" "๐Ÿ˜Ž"
"๐Ÿ˜" "๐Ÿ˜" "๐Ÿ˜‘" "๐Ÿ˜’" "๐Ÿ˜“" "๐Ÿ˜”" "๐Ÿ˜•" #_"๐Ÿ˜–" "๐Ÿ˜—" "๐Ÿ˜˜" "๐Ÿ˜™" "๐Ÿ˜š" "๐Ÿ˜›" "๐Ÿ˜œ" "๐Ÿ˜"
#_"๐Ÿ˜ž" #_"๐Ÿ˜Ÿ" "๐Ÿ˜ " "๐Ÿ˜ก" "๐Ÿ˜ข" "๐Ÿ˜ฃ" "๐Ÿ˜ค" #_"๐Ÿ˜ฅ" "๐Ÿ˜ฆ" #_"๐Ÿ˜ง" #_"๐Ÿ˜จ" #_"๐Ÿ˜ฉ" "๐Ÿ˜ช" #_"๐Ÿ˜ซ" "๐Ÿ˜ฌ"
"๐Ÿ˜ญ" "๐Ÿ˜ฎ" #_"๐Ÿ˜ฏ" "๐Ÿ˜ฐ" #_"๐Ÿ˜ฑ" #_"๐Ÿ˜ฒ" "๐Ÿ˜ณ" "๐Ÿ˜ด" "๐Ÿ˜ต" "๐Ÿ˜ถ" "๐Ÿ˜ท" "๐Ÿ˜ธ" "๐Ÿ˜น" "๐Ÿ˜บ" "๐Ÿ˜ป"
"๐Ÿ˜ผ" "๐Ÿ˜ฝ" "๐Ÿ˜พ" "๐Ÿ˜ฟ" "๐Ÿ™€" "๐Ÿ™" "๐Ÿ™‚" "๐Ÿ™ƒ" "๐Ÿ™„" "๐Ÿ™…" "๐Ÿ™†" "๐Ÿ™‡" "๐Ÿ™ˆ" "๐Ÿ™‰" "๐Ÿ™Š"
#_"๐Ÿ™‹" "๐Ÿ™Œ" #_"๐Ÿ™" #_"๐Ÿ™Ž" "๐Ÿ™" "๐Ÿš€" "๐Ÿš" "๐Ÿš‚" "๐Ÿšƒ" "๐Ÿš„" "๐Ÿš…" "๐Ÿš†" "๐Ÿš‡" "๐Ÿšˆ" "๐Ÿš‰"
"๐ŸšŠ" "๐Ÿš‹" "๐ŸšŒ" "๐Ÿš" "๐ŸšŽ" "๐Ÿš" "๐Ÿš" "๐Ÿš‘" "๐Ÿš’" "๐Ÿš“" "๐Ÿš”" "๐Ÿš•" "๐Ÿš–" "๐Ÿš—" "๐Ÿš˜"
"๐Ÿš™" "๐Ÿšš" "๐Ÿš›" "๐Ÿšœ" "๐Ÿš" "๐Ÿšž" "๐ŸšŸ" "๐Ÿš " "๐Ÿšก" "๐Ÿšข" "๐Ÿšฃ" "๐Ÿšค" "๐Ÿšฅ" "๐Ÿšฆ" "๐Ÿšง"
"๐Ÿšจ" #_"๐Ÿšฉ" "๐Ÿšช" "๐Ÿšซ" "๐Ÿšฌ" "๐Ÿšญ" "๐Ÿšฎ" "๐Ÿšฏ" "๐Ÿšฐ" "๐Ÿšฑ" "๐Ÿšฒ" "๐Ÿšณ" "๐Ÿšด" "๐Ÿšต" "๐Ÿšถ"
"๐Ÿšท" "๐Ÿšธ" "๐Ÿšน" "๐Ÿšบ" "๐Ÿšป" "๐Ÿšผ" "๐Ÿšฝ" "๐Ÿšพ" "๐Ÿšฟ" "๐Ÿ›€" "๐Ÿ›" "๐Ÿ›‚" "๐Ÿ›ƒ" "๐Ÿ›„" "๐Ÿ›…"
"๐Ÿ›‹" "๐Ÿ›Œ" "๐Ÿ›" "๐Ÿ›Ž" "๐Ÿ›" "๐Ÿ›" "๐Ÿ›‘" "๐Ÿ›’" "๐Ÿ›•" "๐Ÿ›–" "๐Ÿ›—" "๐Ÿ›" "๐Ÿ›ž" "๐Ÿ›Ÿ" "๐Ÿ› " "๐Ÿ›ก"
"๐Ÿ›ข" "๐Ÿ›ฃ" "๐Ÿ›ค" "๐Ÿ›ฅ" "๐Ÿ›ฉ" "๐Ÿ›ซ" "๐Ÿ›ฌ" "๐Ÿ›ฐ" "๐Ÿ›ณ" "๐Ÿ›ด" "๐Ÿ›ต" "๐Ÿ›ถ" "๐Ÿ›ท" "๐Ÿ›ธ" "๐Ÿ›น" "๐Ÿ›บ"
"๐Ÿ›ป" "๐Ÿ›ผ" "๐ŸŸ " "๐ŸŸก" "๐ŸŸข" "๐ŸŸฃ" "๐ŸŸค" "๐ŸŸฅ" "๐ŸŸฆ" "๐ŸŸง" "๐ŸŸจ" "๐ŸŸฉ" "๐ŸŸช" "๐ŸŸซ"])
(defn hash-to-emojis [obj]
(let [h1 (hash obj)
h2 (hash h1)
index1 (mod h1 (count emojis))
index2 (mod h2 (count emojis))
emoji1 (nth (cycle emojis) index1)
emoji2 (nth (cycle emojis) index2)]
(str emoji1 emoji2)))
(defn sanitize [s]
(let [replace {"&quot;" "\"" "&amp;" "&" "&lt;" "<"
"&gt;" ">" "&apos;" "'" "&nbsp;" " " "&#39;" "'"
;; can't have [ or ] inside a slack link!
"]" "โŸฉ" "[" "โŸจ"}]
(reduce (fn [s [k v]] (clojure.string/replace s k v)) s replace)))
(defn get-title [owner repo issue-num]
(-> "https://api.github.com/repos/%s/%s/issues/%s"
(format owner repo issue-num)
http/get :body (json/decode keyword) :title sanitize))
(defn emoji-hash [issue-num]
(try
(format "%s:[%s](https://github.com/metabase/metabase/pull/%s)"
(hash-to-emojis issue-num)
(get-title "metabase" "metabase" issue-num)
issue-num)
(catch Exception _
(format "[#%s](https://github.com/metabase/metabase/pull/%s)" issue-num issue-num))))
(defn -main [& args]
(let [issue-number (first *command-line-args*)]
(when-not (re-matches #"\d+" issue-number)
(binding [*out* *err*]
(println "Usage: eh issue-number")))
(println (emoji-hash issue-number))))
(when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment