Miscellaneous functions.
Miscellaneous functions.
(boolean->binary arg)
Inputs: [arg :- s/Bool] Returns: s/Int
Convert true => 1, false => 0
Inputs: [arg :- s/Bool] Returns: s/Int Convert true => 1, false => 0
(byte-signed->hex signed-byte)
Inputs: [signed-byte] Returns: s/Str
Converts a sequence of unsigned bytes [0..255] to a hex string, where each byte becomes 2 hex digits.
Inputs: [signed-byte] Returns: s/Str Converts a sequence of unsigned bytes [0..255] to a hex string, where each byte becomes 2 hex digits.
(byte-signed->unsigned signed-byte)
Inputs: [signed-byte :- s/Int]
Converts a signed byte [-128..127] into an unsigned byte [0..255].
Inputs: [signed-byte :- s/Int] Converts a signed byte [-128..127] into an unsigned byte [0..255].
(byte-unsigned->hex unsigned-byte)
Inputs: [unsigned-byte :- s/Int] Returns: s/Str
Converts a sequence of unsigned bytes [0..255] to a hex string, where each byte becomes 2 hex digits.
Inputs: [unsigned-byte :- s/Int] Returns: s/Str Converts a sequence of unsigned bytes [0..255] to a hex string, where each byte becomes 2 hex digits.
(byte-unsigned->signed unsigned-int)
Inputs: [unsigned-int :- s/Int]
Converts an unsigned int value [0..255] into a signed byte [-128..127].
Inputs: [unsigned-int :- s/Int] Converts an unsigned int value [0..255] into a signed byte [-128..127].
(bytes-signed->hex-str signed-bytes)
Inputs: [signed-bytes :- [s/Int]] Returns: s/Str
Converts a sequence of signed bytes [-128..127] to a hex string, where each byte becomes 2 hex digits.
Inputs: [signed-bytes :- [s/Int]] Returns: s/Str Converts a sequence of signed bytes [-128..127] to a hex string, where each byte becomes 2 hex digits.
(bytes-signed->unsigned byte-vals)
Inputs: [byte-vals]
Converts a vector of signed byte values [-128..127] into one of unsigned byte values [0..255]
Inputs: [byte-vals] Converts a vector of signed byte values [-128..127] into one of unsigned byte values [0..255]
(bytes-unsigned->hex-str unsigned-bytes)
Inputs: [unsigned-bytes :- [s/Int]] Returns: s/Str
Converts a sequence of unsigned bytes [0..255] to a hex string, where each byte becomes 2 hex digits.
Inputs: [unsigned-bytes :- [s/Int]] Returns: s/Str Converts a sequence of unsigned bytes [0..255] to a hex string, where each byte becomes 2 hex digits.
(bytes-unsigned->signed byte-vals)
Inputs: [byte-vals]
Converts a vector of unsigned byte values [0..255] into one of signed byte values [-128..127]
Inputs: [byte-vals] Converts a vector of unsigned byte values [0..255] into one of signed byte values [-128..127]
(dot)
Prints a single dot (flushed) to the console, keeping a running count of dots printed. Wraps to a newline when 100 dots have been printed. Displays the running dot count at the beginning of each line. Usage:
(ns demo.core
(:require [tupelo.misc :as tm]))
(tm/dots-config! {:decimation 10} )
(tm/with-dots
(doseq [ii (range 2345)]
(tm/dot)
(Thread/sleep 5)))
Prints a single dot (flushed) to the console, keeping a running count of dots printed. Wraps to a newline when 100 dots have been printed. Displays the running dot count at the beginning of each line. Usage: (ns demo.core (:require [tupelo.misc :as tm])) (tm/dots-config! {:decimation 10} ) (tm/with-dots (doseq [ii (range 2345)] (tm/dot) (Thread/sleep 5)))
(edn->sha edn-data)
Inputs: [edn-data] Returns: s/Str
Converts EDN data into a normalized SHA-1 string
Inputs: [edn-data] Returns: s/Str Converts EDN data into a normalized SHA-1 string
(find-pattern pattern-vec data-vec)
Inputs: [pattern-vec :- tsk/List data-vec :- tsk/List] Returns: [s/Int]
Searches for pattern-vec within data-vec, returning a lazy seq of indexes into data-vec.
Inputs: [pattern-vec :- tsk/List data-vec :- tsk/List] Returns: [s/Int] Searches for pattern-vec within data-vec, returning a lazy seq of indexes into data-vec.
(fn-info)
Inputs: [] Returns: tsk/KeyMap
Returns a map of info about the current function, like:
{:ns-name 'demo.core'
:fn-name 'add2'
:class-name 'demo.core$add2'
:file-name 'core.clj'
:line-num 57
:method-name 'invokeStatic' }
Inputs: [] Returns: tsk/KeyMap Returns a map of info about the current function, like: {:ns-name 'demo.core' :fn-name 'add2' :class-name 'demo.core$add2' :file-name 'core.clj' :line-num 57 :method-name 'invokeStatic' }
(fn-info-caller)
Inputs: [] Returns: tsk/KeyMap
Returns a map of info about the caller of the current function, like:
{:ns-name 'demo.core'
:fn-name 'add2'
:class-name 'demo.core$add2'
:file-name 'core.clj'
:line-num 57
:method-name 'invokeStatic' }
Inputs: [] Returns: tsk/KeyMap Returns a map of info about the caller of the current function, like: {:ns-name 'demo.core' :fn-name 'add2' :class-name 'demo.core$add2' :file-name 'core.clj' :line-num 57 :method-name 'invokeStatic' }
(get-path path-str)
Wrapper for Java Paths/get to work around the varargs strangeness
Wrapper for Java Paths/get to work around the varargs strangeness
(grouper re input-str)
Uses js/RegExp to find matching groups. Sample output:
(grouper #"[a-z0-9][A-Z]" "aTaTa") =>
[ {:groups ["aT"] :match "aT" :index 0 :last-index 2 :input "aTaTa" }
{:groups ["aT"] :match "aT" :index 2 :last-index 4 :input "aTaTa" } ]
(grouper #"((\d+)-(\d+))" "672-345-456-3212") =>
[ {:groups ["672-345" "672-345" "672" "345" ] :match "672-345" :index 0 :last-index 7 :input "672-345-456-3212" }
{:groups ["456-3212" "456-3212" "456" "3212"] :match "456-3212" :index 8 :last-index 16 :input "672-345-456-3212" } ]
Note that the JS value returned by :last-index
is the index of the first char in the input string after the current match.
Uses js/RegExp to find matching groups. Sample output: (grouper #"[a-z0-9][A-Z]" "aTaTa") => [ {:groups ["aT"] :match "aT" :index 0 :last-index 2 :input "aTaTa" } {:groups ["aT"] :match "aT" :index 2 :last-index 4 :input "aTaTa" } ] (grouper #"((\d+)-(\d+))" "672-345-456-3212") => [ {:groups ["672-345" "672-345" "672" "345" ] :match "672-345" :index 0 :last-index 7 :input "672-345-456-3212" } {:groups ["456-3212" "456-3212" "456" "3212"] :match "456-3212" :index 8 :last-index 16 :input "672-345-456-3212" } ] Note that the JS value returned by `:last-index` is the index of the first char in the input string *after* the current match.
(hash->hex & args)
(hash->hex & rest49582)
Inputs: [& args] Returns: s/Str
Given arbitrary arguments, uses clojure.lang/hash to generate a 32-bit hex hashcode.
Inputs: [& args] Returns: s/Str Given arbitrary arguments, uses clojure.lang/hash to generate a 32-bit hex hashcode.
(hex-str->signed-bytes hex-str)
Inputs: [hex-str :- s/Str]
Converts a hex string to a vector of unsigned bytes
Inputs: [hex-str :- s/Str] Converts a hex string to a vector of unsigned bytes
(hex-str->unsigned-bytes hex-str)
Inputs: [hex-str :- s/Str]
Converts a hex string to a vector of unsigned bytes
Inputs: [hex-str :- s/Str] Converts a hex string to a vector of unsigned bytes
(hid->wid hid)
Inputs: [hid :- HID] Returns: s/Keyword
Uses an HID to look up a human-friendly Word-ID (WID) from an English dictionary. Useful for debugging purposes.
Inputs: [hid :- HID] Returns: s/Keyword Uses an HID to look up a human-friendly Word-ID (WID) from an English dictionary. Useful for debugging purposes.
(hid? arg)
Inputs: [arg] Returns: s/Bool
Returns true if the arg is a legal HexID
Inputs: [arg] Returns: s/Bool Returns true if the arg is a legal HexID
(new-hid)
Inputs: [] Returns: HID
Returns a new HexID
Inputs: [] Returns: HID Returns a new HexID
(normalized-sorted edn-data)
Walks EDN data, converting all collections to vector, sorted-map-generic, or sorted-set-generic
Walks EDN data, converting all collections to vector, sorted-map-generic, or sorted-set-generic
(sha-uuid)
Inputs: [] Returns: s/Str
Returns a string that is the SHA-1 hash of the
Clojure: (clj-uuid/v1)
ClojureScript: (cljs.core/random-uuid)
Inputs: [] Returns: s/Str Returns a string that is the SHA-1 hash of the Clojure: (clj-uuid/v1) ClojureScript: (cljs.core/random-uuid)
(shell-cmd cmd-str)
Runs a command string in the default OS shell (/bin/bash); returns result in a Clojure map. Example:
(shell-cmd "ls -ldF *")
;=> {:exit 0 ; unix exit status (0 -> normal)
:err '' ; text from any errors
:out '...' ; text output as would printed to console
}
Runs a command string in the default OS shell (/bin/bash); returns result in a Clojure map. Example: (shell-cmd "ls -ldF *") ;=> {:exit 0 ; unix exit status (0 -> normal) :err '' ; text from any errors :out '...' ; text output as would printed to console }
(stacktrace-info throwable)
Inputs: [throwable :- Throwable] Returns: [tsk/KeyMap]
Returns a map with the caller's namespace and function names as strings, like: {:ns-name 'tst.demo.core' :fn-name 'funky'}
Inputs: [throwable :- Throwable] Returns: [tsk/KeyMap] Returns a map with the caller's namespace and function names as strings, like: {:ns-name 'tst.demo.core' :fn-name 'funky'}
(str->byte-array str-val)
Inputs: [str-val :- s/Str]
Inputs: [str-val :- s/Str]
Returns the SHA-1 hex string for a string
Returns the SHA-1 hex string for a string
(str->sha str-val)
Inputs: [str-val :- s/Str]
Inputs: [str-val :- s/Str]
(take-dist n coll)
Returns a sequence of n items from a collection, distributed evenly between first & last elements, which are always included.
Returns a sequence of n items from a collection, distributed evenly between first & last elements, which are always included.
(uuid->sha uuid)
Returns the SHA-1 hex string for a UUID's string representation
Returns the SHA-1 hex string for a UUID's string representation
(walk->snippet-dims dims data)
Inputs: [dims :- [[s/Num]] data]
Inputs: [dims :- [[s/Num]] data]
(walk-map->sorted data)
Recursively walks a data structure, converting maps (but not records!) into (plain) sorted maps.
Recursively walks a data structure, converting maps (but not records!) into (plain) sorted maps.
(walk-map->sorted-generic data)
Recursively walks a data structure, converting maps (but not records!) into generic sorted maps. A generic sort allows keys of different categories such as keyword, string, int, nil, etc.
Recursively walks a data structure, converting maps (but not records!) into generic sorted maps. A generic sort allows keys of different categories such as keyword, string, int, nil, etc.
(with-dots & body)
Increments indentation level of all spy, spyx, or spyxx expressions within the body.
Increments indentation level of all spy, spyx, or spyxx expressions within the body.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close