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 [meander.epsilon :as m]) | |
(def test-data | |
{:root | |
{:first-child | |
[{:inner-child | |
[{:element "1"} | |
{:element "2"}]} | |
{:elements [{:element "3"} | |
{:element "4"} |
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
import os | |
import pickle | |
import hashlib | |
from functools import wraps, reduce | |
def default_filename_fn(args, kwargs): | |
base = reduce(lambda acc,x: acc + str(x), args, "") | |
return hashlib.sha1(base.encode()).hexdigest() |
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
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' |
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.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 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
;; 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 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 -main [& args] | |
) | |
(when (= *file* (System/getProperty "babashka.file")) | |
(-main *command-line-args*)) |
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 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 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 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 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 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 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 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)))) |