This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-13
Channels
- # ai (5)
- # announcements (4)
- # babashka (34)
- # beginners (78)
- # biff (6)
- # calva (41)
- # cider (47)
- # clerk (1)
- # clj-commons (3)
- # clj-http (1)
- # clojure (72)
- # clojure-europe (51)
- # clojure-nl (1)
- # clojure-norway (87)
- # clojure-romania (1)
- # clojure-uk (5)
- # clojuredesign-podcast (2)
- # community-development (1)
- # conjure (2)
- # cursive (11)
- # datomic (6)
- # docker (4)
- # emacs (13)
- # exercism (20)
- # hyperfiddle (56)
- # matrix (6)
- # membrane (4)
- # nbb (11)
- # off-topic (88)
- # pathom (7)
- # pedestal (1)
- # polylith (20)
- # portal (16)
- # practicalli (1)
- # re-frame (13)
- # reagent (4)
- # reitit (2)
- # remote-jobs (7)
- # shadow-cljs (49)
- # sql (4)
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. 😃that seems safer than replacing the extension everywhere in the string, since the extension may also be part of the normal filename
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!
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?
@U04V15CAJ nevermind, the https://github.com/babashka/http-client#timeouts example in the docs is enough. Thanks very much for the pointers!
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?
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.
trying in #C029PTWD3HR might be better?
promesa.core/all
returns a promise of a vector of all results, right? should work, but without a repro it's hard to say
That’s what it should do, working on a repro, will post in #C029PTWD3HR if/when I get it nailed down
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
?
@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
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)
Hey Borkdude! Thanks. Will try.
.
├── 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?@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
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 "."}}}
If you haven't read it yet, https://www.braveclojure.com/quests/babooka/ might be a good resource along with https://book.babashka.org/
The hard part is to sneak it into the company now 🙂
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
Haha I like the advice on how to sneak in the code 😆