Fork me on GitHub
#babashka
<
2022-08-22
>
Dumch13:08:33

I was looking into SCI code and found https://github.com/babashka/sci/blob/49817626dd2b1bb69dd10457137e5df1f1fd9445/src/sci/impl/evaluator.cljc#L339. Why are other types extended if there is already an Object there with the same extension? Code below would work the same.

#?(:clj (extend-protocol types/Eval
          Object
          (eval [expr _ _]
            expr)
          nil (eval [_ _ _] nil))
Or is there something I don't see?

borkdude14:08:07

Maybe a performance reason

Cora (she/her)20:08:20

is there a trivial way in babashka to read all *in* to bytes? (meaning read until eof)

borkdude20:08:24

@corasaurus-hex

$ echo 'yolo' | bb -e '(-> (.readAllBytes System/in) (String. "utf-8"))'
"yolo\n"

Cora (she/her)20:08:36

ahhhh System/in

Cora (she/her)20:08:23

ahhhh readAllBytes was added in java 9

Cora (she/her)20:08:25

that explains it

Cora (she/her)20:08:37

I was looking at java 8's docs

Cora (she/her)21:08:40

#!/usr/bin/env bb

(require '[ :as io])
(import '[java.util.zip Inflater InflaterInputStream])

(with-open [input (InflaterInputStream. System/in (Inflater. true))]
  (io/copy input System/out))
for inflating as part of a pipeline in the shell. in this case I'm working with SAML SSO and the request data is string->bytes->deflate->base64encode->urlencode and this handles the inflate portion of reversing that

👍 1
Cora (she/her)22:08:48

is babashka/cli going to be included in babashka eventually?

borkdude22:08:58

it already is

Cora (she/her)22:08:27

I created this a while back

Cora (she/her)22:08:13

I imagine some kind of combination of babashka/cli with this sort of thing would be interesting. being able to install these as shell scripts on your path and execute something in a library

Cora (she/her)22:08:05

basically you can do cljx babashka/fs which ls and it will pull down the latest babashka/fs and run the which function with an argument of "ls"

Cora (she/her)22:08:34

I could see something like this being useful with, say, a database migration tool like ragtime, being able to run a function to create a new migration or to run existing migrations

Cora (she/her)22:08:54

perhaps even have something in the package that describes valid args and commands and such and this could extract that to generate output

Cora (she/her)22:08:31

it's similar to clojure tools, in a way