Fork me on GitHub
#babashka
<
2022-01-31
>
Krishan V11:01:43

Hello everyone, how would I go about removing a tagged literal that comes with the output of babashka.fs functions? I want to write my list of files in an edn but I have hit a blocker with extending my reader to recognise #object[sun.nio.fs.UnixPath . I am not familiar with tagged literals and the reader itself, I can do without them for now, I just need the raw paths to the files.

borkdude11:01:46

@krishanvj Just transform them into strings with str

🙌 2
Krishan V11:01:46

Thanks! Appreciate your fast reply

Krishan V13:01:47

I ran into a strange behavior, I have to be missing something obvious here. Why am I always running the truthy path?

(let [[output-dir container-name inside-container?] *command-line-args*]
  (when (or (empty? output-dir) (empty? container-name))
    (System/exit 1))
  (if (true? (boolean inside-container?))
    (println "truthy with these args: " inside-container? )
    (println "falsy")))
I'd always get truthy with these args: true or truthy with these args: false regardless of what I supply as my third argument. Can't reach the falsy path 😞

borkdude13:01:10

@krishanvj boolean converts a truthy value into true. Only nil and false are non-truthy values. A string is always a truthy value.

borkdude13:01:41

You can use parse-boolean instead, or just write (= "true" inside-container?")

borkdude13:01:36

(boolean "false") ;;=> true

Krishan V13:01:58

Just went with the parse-boolean function, is this part of Clojure or only found within babashka for this exact use-case? Thank btw!

borkdude13:01:17

it's new in clojure 1.11 alpha4 and already available in bb.

🙌 1
1
Dimitar Uzunov14:01:44

to prep our CI agents, I need to run a bb.edn file in order for the deps.clj packages be downloaded in the CI user dir. Is there an easier way to “prep” a user for future use of bb?

borkdude14:01:15

Just run bb tasks or so should do.

Nick Stares20:01:01

Trying to make an ISO-8601 formatter for AWS. Unfortunately this is giving me my offset time instead of GMT. What am I missing?

(def ISO-8601 (DateTimeFormatter/ofPattern "yyyyMMdd'T'HHmmss'Z'"))
(.format (LocalDateTime/now) ISO-8601)
;; => "20220131T121126Z" (should be GMT, not UTC-8?)

1
borkdude20:01:43

Is the behavior in bb different than in clj?

Nick Stares20:01:44

Oops, it's probably not. I posted here because I was going off your SO example for babashka. Can move to a different channel 😅

borkdude20:01:14

No problem, just checking :)

borkdude20:01:47

Maybe you need to use a ZonedDateTime?

Nick Stares20:01:46

Ok, I can try that and set the zone to GMT. I'm just confused because I didn't want a zone at all, and I thought LocalDateTime didn't have that, so I'm wondering how it is even getting my local timezone at all

borkdude20:01:11

I think it just appends whatever you put in your format string:

user=> (def ISO-8601 (java.time.format.DateTimeFormatter/ofPattern "yyyyMMdd'T'HHmmss'Zxxx'"))
#'user/ISO-8601
user=> (.format (java.time.LocalDateTime/now) ISO-8601)
"20220131T212352Zxxx"

borkdude20:01:45

> >

ZonedDateTime.now( ZoneOffset.UTC ).format( DateTimeFormatter.ISO_INSTANT )
>

borkdude20:01:35

user=> (-> (java.time.ZonedDateTime/now) (.format java.time.format.DateTimeFormatter/ISO_INSTANT))
"2022-01-31T20:26:29.232494Z"

borkdude20:01:04

Is this the right one?

user=> (def ISO-8601 (java.time.format.DateTimeFormatter/ofPattern "yyyyMMdd'T'HHmmss'Z'"))
#'user/ISO-8601
user=> (-> (java.time.ZonedDateTime/now) (.format ISO-8601))
"20220131T212950Z"

borkdude20:01:58

Or maybe this one:

user=> (-> (java.time.ZonedDateTime/now java.time.ZoneOffset/UTC ) (.format ISO-8601))
"20220131T203047Z"

🎉 1
Nick Stares20:01:40

Ah that's the one! Wow thank you so much 😍

👍 1
escherize21:01:58

A question about getting output from a babashka process: I have a subprocess that needs to print things to stdout, but it produces a value I want to get back. What’s a good way to get the value back out of it? I am considering passing a file path, and watching the file path from the caller… is this such a good idea though? 😅

borkdude21:01:52

@U051GFP2V

(-> (babashka.process/process ["foo"] {:out :string}) deref :out)

👀 1
escherize21:01:37

Thanks, I ended up using stderr to send back the result.

escherize21:01:08

so it would look like:

(-> (babashka.process/process ["foo"] {:err :string :inherit true}) deref :err)

borkdude21:01:25

Cool! Honestly I would do it the other way around, send questions over stderr and send data over stdout, but inquirer JS might already send over stdout, so then that's not an option

borkdude21:01:01

stderr is usually for warnings, side information, stdout is the real data you want from a program

borkdude21:01:20

but it's just a convention

escherize21:01:34

yea that is true, maybe I can redirect it to use stderr

escherize21:01:05

the thing is, inquirer doesn’t work very well when speaking in stderr, missing colors etc

borkdude21:01:00

yeah, then what you had first was probably the right call, or a file as you said

borkdude21:01:26

perhaps you can call your program with an optional output file argument

escherize22:01:24

I was considering it, if there are actual instances of stderr coming through I will switch to that. Thanks for all your help today!!

dpsutton21:01:48

can you print things to stderr and put the return value in stdout?

David Pham21:01:40

Babashka is now installed in circle ci image!!

🆒 4
David Pham21:01:46

✔️ 1
🥳 2