This file contains 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
(defun rot-time-duration (begin &optional end) | |
(if end | |
(org-minutes-to-clocksum-string | |
(- (org-duration-to-minutes end) | |
(org-duration-to-minutes begin))) | |
(seq-let (begin end) (mapcar 's-trim (s-split "-" begin)) | |
(rot-time-duration begin end)))) | |
;; (rot-time-duration "9:00" "17:00") |
This file contains 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
(import '(java.util Base64)) | |
(defn b64encode [to-encode] | |
(.encode (Base64/getEncoder) (.getBytes to-encode))) |
This file contains 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 fixed-length-password | |
([] (fixed-length-password 20)) | |
([n] | |
(let [chars (map char (concat (range 48 58) (range 65 91) (range 97 123))) | |
password (repeatedly n #(rand-nth chars))] | |
(reduce str password)))) |
This file contains 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 deep-get | |
[m k] | |
(let [values_ (transient [])] | |
(walk/prewalk (fn [e] (if (and (map? e) (get e k)) | |
(do (conj! values_ (get e k)) e) | |
e)) m) | |
(persistent! values_))) |
This file contains 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 now-with-pattern | |
"Returns current time as string with pattern" | |
[pattern] | |
(.format (java.time.LocalDateTime/now) (java.time.format.DateTimeFormatter/ofPattern pattern))) | |
(now-with-pattern "yyyyMMddHHmmss") |
This file contains 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 maps-to-table | |
([labels list-of-maps] | |
(maps-to-table labels list-of-maps true)) | |
([labels list-of-maps with-headers?] | |
(let [header (when with-headers? [(mapv name labels)]) | |
data (mapv (apply juxt labels) list-of-maps)] | |
(if with-headers? | |
(concat header data) | |
data)))) |
This file contains 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 -main [& args] | |
) | |
(when (= *file* (System/getProperty "babashka.file")) | |
(-main *command-line-args*)) |
This file contains 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
;; https://gist.github.com/jizhang/4325757?permalink_comment_id=2633984#gistcomment-2633984 | |
(ns md5-clj | |
(:import (java.security MessageDigest) | |
(java.math BigInteger))) | |
(defn md5 | |
[^String s] | |
(->> s | |
.getBytes | |
(.digest (MessageDigest/getInstance "MD5")) |
This file contains 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.string :as str]) | |
(require '[clojure.java.shell :refer [sh]]) | |
(defn shell-linux [cmd] | |
(sh "sh" "-c" cmd)) | |
(defn shell-windows [cmd] | |
(sh "cmd" "/C" cmd)) | |
(def shell |
This file contains 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
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKCYAN = '\033[96m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' |
NewerOlder