Fork me on GitHub
#babashka
<
2023-10-13
>
pez09:10:25

Is this a good way to replace the extension part of a path-string?

(defn replace-ext [path new-ext]
  (let [old-ext (fs/extension path)]
    (string/replace path (str "." old-ext) (str "." new-ext))))
Or am I missing something in the API? In bash I would do it more like
(str (fs/path (fs/parent path) (fs/basename path)) "." new-ext)
Well, actually I would rather do "${path%.*}.$new_ext", but anyway. 😃

borkdude09:10:46

You can use split-ext to get the extension and the rest

👍 1
borkdude09:10:11

that seems safer than replacing the extension everywhere in the string, since the extension may also be part of the normal filename

borkdude09:10:37

e.g.:

foon.exer.exe
exe -> com
foon.comr.com

pez09:10:56

Yeah, sloppy of me. I wrote the code on the fly here. Should be a regex of course. But that only makes the case for split-ext even stronger. 😃 Thanks!

pez09:10:07

(defn replace-ext [path new-ext]
  (str (first (fs/split-ext path)) "." new-ext))

👍 1
sheluchin11:10:50

I'd like to use Babashka for some lightweight load testing against my server. What would be a good way to send a bunch of simultaneous requests? core.async, virtual threads, something else?

borkdude11:10:19

you can use babashka.http-client with :async for example

borkdude11:10:41

you can supply a fixed thread pool to limit the concurrent requests

borkdude11:10:52

or a virtual thread pool for unbounded

sheluchin11:10:15

Are there any examples of this sort of thing I could look at?

sheluchin11:10:38

@U04V15CAJ nevermind, the https://github.com/babashka/http-client#timeouts example in the docs is enough. Thanks very much for the pointers!

joshmiller20:10:15

I’ve got an nbb web server that needs to run some async HTTP fetching processes on an interval. I have a function that uses promesa.core/all to collect the results from each fetch (using node-fetch), and on server setup I do (js/setInterval do-http-fetches interval-time). This sort of works, in that the function is indeed invoked on schedule, but it seems like not all of the promises actually happen every time. Is there some kind of Node/Promise/CLJS interaction issue I’m not getting here?

joshmiller20:10:39

This happens with setTimeout as well, where if I just call the fn once on a delay of 10 ms or something, I get some but not all of the calls completed.

lispyclouds21:10:26

trying in #C029PTWD3HR might be better?

joshmiller21:10:43

Ooh, didn’t realize that existed, will take the issue there, thanks.

1
🙏 1
borkdude21:10:10

promesa.core/all returns a promise of a vector of all results, right? should work, but without a repro it's hard to say

joshmiller21:10:01

That’s what it should do, working on a repro, will post in #C029PTWD3HR if/when I get it nailed down

Felix Dorner21:10:01

I read through the book but still dont understand.. I’m new to babashka, and have never used deps.edn: I have a lib.clj that has a bunch of helper functions. these helpers only depend on stuff that’s included with babashka. Where would I now put that file so that I can use the helpers from my scripts, when I want to run the scripts via #!/usr/bin/env bb ?

borkdude21:10:27

@U05KWT468F8 Welcome! • Next to your #!/usr/bin/env bb file create a bb.edn file • In that bb.edn file add {:paths ["."]} Now you can add helper files in the same directory as your script

borkdude21:10:20

You can also add them in a src directory, in that case in bb.edn write:

{:paths ["src"]}
The lib.clj file would then go in src/lib.clj and the ns form would look like (ns lib)

Felix Dorner21:10:03

Hey Borkdude! Thanks. Will try.

Felix Dorner21:10:35

.
├── bb.edn
├── 
└── src
    └── frkct.clj
This works. If I wanted to later publish frkct (without the scripts), I could then probably just put normal maven coordinates into the bb.edn?

borkdude22:10:07

@U05KWT468F8 To publish this, you could just put this in a github repo and people can use #babashka-bbin to install your tool / https://github.com/babashka/bbin

borkdude22:10:47

actually, you need to use a deps.edn instead of a bb.edn if you want to publish this as a project and put this into your bb.edn for local usage:

{:deps {io.github.felixdorner/frkct {:local/root "."}}}

borkdude22:10:46

another option is to just let people git clone your repo and add the to their PATH

borkdude22:10:07

If you haven't read it yet, https://www.braveclojure.com/quests/babooka/ might be a good resource along with https://book.babashka.org/

Felix Dorner22:10:22

Ok, for the moment I’m cool. This is already nice. Thanks Michiel!

👍 1
Felix Dorner22:10:21

The hard part is to sneak it into the company now 🙂

borkdude22:10:01

you can also disguise bb as a self-contained binary with your program in it: https://github.com/babashka/babashka/wiki/Self-contained-executable#uberjar this only works with the development version as documented there

borkdude22:10:10

and you'll have to build it for each specific OS

borkdude22:10:47

but it's less hassle if people would just install bb ;)

grounded_sage09:10:16

Haha I like the advice on how to sneak in the code 😆