Fork me on GitHub
#babashka
<
2024-03-14
>
Noah Bogart01:03:03

I have a defrecord that implements IPersistentStack so I can call (pop myrec) and have it do something custom. babashka/sci says that defrecord can't implement interfaces, only protocols. is there a workaround?

Noah Bogart01:03:11

code in question:

(ns noahtheduke.splint.pipeline
  (:import
   [clojure.lang IPersistentStack PersistentQueue]))

(defrecord Pipeline [steps queue]
  IPersistentStack
  (peek [_] (or (peek queue) (peek steps)))
  (pop [_] (->Pipeline (pop (into queue steps)) PersistentQueue/EMPTY)))

borkdude09:03:19

This isn't possible in SCI unfortunately. The workaround is to not make a custom type but just use data and functions, e.g. a map with the stack in it

7tupel11:03:37

I'm trying to get a piece of code working that uses a ThreadLocal to generate some random bytes. It seems this is not available in bb. Are there any recommendations/best practices on how to do this in bb? I could surely skip the thread local part for now but to be able to use this piece of code properly it would be nice to have this isolated per thread.

borkdude11:03:14

I could try to add this class and you could test it. Do you have a small snippet which could serve as a test?

7tupel11:03:59

Thanks a lot. I basically would like to use this library to generate ulids: https://github.com/theikkila/clj-ulid The following lines use the ThreadLocal: https://github.com/theikkila/clj-ulid/blob/master/src%2Fclj_ulid.clj#L36-L37 Testing if this works should be as easy to require this library and try to generate an ulid using the example from the repos readme.

borkdude12:03:06

Promising result locally:

$ clj -M:babashka/dev -e '(defonce ^ThreadLocal threadlocal-random (proxy [ThreadLocal] [] (initialValue [] (rand-int 100)))) (prn (.get threadlocal-random)) @(future (prn (.get threadlocal-random)))'

47
68
I'll push this to a branch. What OS do you have so you can test the binary?

7tupel12:03:18

Linux on standard intel CPU

7tupel14:03:01

Haven't been able to try, i'm on ice cream duty with my daughter :'D I'll try later today

7tupel20:03:55

Thanks :) sorry but will be tomorrow that I'll be able to test it :/

borkdude21:03:24

no worry, I already merged it to main btw, you can test with:

bash <(curl ) --dev-build --dir /tmp
and then:
/tmp/bb ...

eval202016:03:36

Did some spring cleaning of:babashka: tasks and this library came out :bubbles:

st16:03:01

Hi there, It seems that not all Java classes are available via interop (as explained here https://github.com/babashka/babashka?tab=readme-ov-file#including-new-libraries-or-classes) e.g

Babashka v1.3.189 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> java.math.RoundingMode/HALF_DOWN
#object[java.math.RoundingMode 0x2710654d "HALF_DOWN"]
user=> (java.text.DecimalFormat.)
clojure.lang.ExceptionInfo: Unable to resolve classname: java.text.DecimalFormat [at <repl>:2:1]
Is there a list or a way to find which Java classes are available? I am experimenting the use of babashka to run existing scripts. The context is that I’m able to run bb only in a docker container (the enterprise policy is not super friendly: windows, proxy, …) Any hint welcome.

st17:03:38

Thank you very much !

Bob B19:03:52

And regarding the context, I'm in what might be a somewhat similar situation at work (stuck on windows, company proxy that essentially does MITM attacks and re-signs web traffic from a company CA). I use babashka from my desktop using a batch file that injects into the command line JVM props that graalvm binaries accept: bb.exe -Dhttps.proxyHost=... -Dhttps.proxyPort=... (same thing for http vars) -.ssl.trustStore=C:/path/to/trustStore %* that trust store includes my company CA certs, and I've had good results from that. Where something as basic as slurping google would give me cert errors without those options, this has been sufficient (in my context) to make it so that I don't think about network configuration with bb any longer.

st19:03:12

Thanks for the additional info!