tupelo.misc

Miscellaneous functions.

*os-shell*

dynamic

boolean->binary

(boolean->binary arg)
Inputs: [arg :- s/Bool]
Returns: s/Int

Convert true => 1, false => 0

byte-signed->hex

(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.

byte-signed->unsigned

(byte-signed->unsigned signed-byte)
Inputs: [signed-byte :- s/Int]

Converts a signed byte [-128..127] into an unsigned byte [0..255].

byte-unsigned->hex

(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.

byte-unsigned->signed

(byte-unsigned->signed unsigned-int)
Inputs: [unsigned-int :- s/Int]

Converts an unsigned int value [0..255] into a signed byte [-128..127].

bytes-signed->hex-str

(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.

bytes-signed->unsigned

(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] 

bytes-unsigned->hex-str

(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.

bytes-unsigned->signed

(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]

dot

(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)))

dot-counter-watch-fn

(dot-counter-watch-fn key dot-counter-ref old-count new-count)

dots-config!

(dots-config! ctx)

edn->sha

(edn->sha edn-data)
Inputs: [edn-data]
Returns: s/Str

Converts EDN data into a normalized SHA-1 string

find-pattern

(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.

fn-info

(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' }
          

fn-info-caller

(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' }
          

get-os

(get-os)

get-path

(get-path path-str)
Wrapper for Java Paths/get to work around the varargs strangeness

hash->hex

(hash->hex & args)
Inputs: [& args]
Returns: s/Str

Given arbitrary arguments, uses clojure.lang/hash to generate a 32-bit hex hashcode.

hex->int

hex-chars

hex-str->signed-bytes

(hex-str->signed-bytes hex-str)
Inputs: [hex-str :- s/Str]

Converts a hex string to a vector of unsigned bytes

hex-str->unsigned-bytes

(hex-str->unsigned-bytes hex-str)
Inputs: [hex-str :- s/Str]

Converts a hex string to a vector of unsigned bytes

HID

hid->wid

(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.

hid?

(hid? arg)
Inputs: [arg]
Returns: s/Bool

Returns true if the arg is a legal HexID

int->hex

log-uncaught-exceptions

(log-uncaught-exceptions)

new-hid

(new-hid)
Inputs: []
Returns: HID

Returns a new HexID

normalized-sorted

(normalized-sorted edn-data)
Walks EDN data, converting all collections to vector, sorted-map-generic, or sorted-set-generic

sha-uuid

(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)
      

shell-cmd

(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
             }

stacktrace-info

(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'} 

str->byte-array

(str->byte-array str-val)
Inputs: [str-val :- s/Str]

str->sha

Returns the SHA-1 hex string for a string

take-dist

(take-dist n coll)
Returns a sequence of n items from a collection, distributed
evenly between first & last elements, which are always included.

uuid->sha

(uuid->sha uuid)
Returns the SHA-1 hex string for a UUID's string representation

walk-map->sorted

(walk-map->sorted data)
Recursively walks a data structure, converting maps (but not records!) into (plain) sorted maps.

walk-map->sorted-generic

(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.

walk-rec->map

(walk-rec->map data)

with-dots

macro

(with-dots & body)
Increments indentation level of all spy, spyx, or spyxx expressions within the body.