Fork me on GitHub

Hi folks, which "utility" library (like taonesso/encore) do you use that is fully compatible with babashka? Thanks for all the replies in advance 😄


This is a rather general question, since "utility" can mean all sorts of things


Oh yes sorry it is rather generic and I meant if basically one of the libs like tupelo , encore, known to be fully compatible with babashka. We use encore in our code base but that particular one is not compatible.


e.g. medley is a utility library which has some functions that should maybe belong in core. but do you want to use a utility library for the sake of using a utility library? gotta go now, dinner

👍 1

yeah the answer is no - my next step would be to check what it contains and see if it matches our code base - I'll check medley thanks


I'd just write/maintain my own util lib in that case


which is custom to your need


I'm having déjà vu – I feel like I asked this question before, but I can't figure it out (maybe again). I can do something like this, right?

curl -s "" | bb --stream --nrepl-server
and then connect to it from my editor and once there:
(def data (json/parse-stream *in* true))
Then I can analyze the data however I want. Now, how do I do the same thing but in the same terminal session? I can even do this:
curl -s "" | bb -i -e '(json/parse-stream *in* true)'
but that just prints the results, and I want it to remain in the repl


probably it's best to just start the console REPL, then use bb.http-client or so to fetch the json, parse the json and then handle it as you like, without using any bash magic or bb i/o flags


unless @U013JFLRFS8 has a better suggestion, I saw he was just typing something :)

Bob B21:06:43

I was just gonna say that I think -e and the repl are sort of (currently) mutually exclusive, and was going to try and throw together some bash magic

😆 1
Bob B21:06:50

Actually, now that I think about it, since the piping would occupy stdin, the repl wouldn't be able to read input from the terminal, so the curl would probably need to become a pseudo-file

👍 1

bb does support --init btw, where you can supply a file which is ran before anything else is done. so bb --init init.clj repl would work


what about preloads?


that also works


$ BABASHKA_PRELOADS='(prn :dude)' bb repl
Babashka v1.3.185 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.



(I am on an old laptop here, laying on the couch, hence the old bb version)


I mean, personally, for me, the first case with the nrepl-server works the best. I was just trying to show someone how easy it is to use Babashka to sift through API response data with very simple one-liner. I thought it would be simple, I guess, not through piping. And then it turned into a stupid question to quench my curiosity.

Bob B22:06:52

I cheated a bit by using slurp, but:

$ bb --init <(echo '(def x (json/parse-string (slurp "") true))')
Babashka v1.3.191 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (keys (first x))
(:breed_group :reference_image_id :name :life_span :bred_for :weight :id :temperament :origin :height)

metal 1

My attempt: BABASHKA_PRELOADS="(do (require '[babashka.http-client :as http]) (def d (-> \"\" http/get :body (json/parse-string true))))" bb repl


Holy cow, I had no idea you could slurp urls... TIL


it works in a limited number of cases


e.g. it doesn't work very well if the url needs redirection


yeah, but... I had no idea you could do this even for simple gets... I'm like totally befuddled. Clojuredocs even have the example right there. It just never occurred to me to read the docs for slurp. It always worked and I never needed to check the docs. I don't like PLs for which you have to open the docs, even for the simple stuff like reading a file.


Thank you friends.

❤️ 1
Bob B22:06:26

and if you want to get crazy, a little tweak to the portal CLI script that bbin can install could be used to pop a portal window with some json that comes from curl'ing, but I'm maybe going a bit too far here

👍 2
😯 1

Whoa. It never seizes to amaze me. You ask Clojurians a question for a simple one-liner, and they'll take you on a wild, mind-blowing journey. To find the answers for the ultimate questions of life, the universe, and everything... 🙂


Holy mother of Alan Turing, that even worked:

bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.56.0"}}}' --init <(echo '(require (quote [portal.api :as p])) (def p (p/open)) (def data (-> "" slurp (json/parse-string true))')
Now, can you tell me guys, how to tap to inspect data? I've never used Portal before.

Bob B22:06:19

from <>:

(tap> data)
you did open already, so it should just need the other two - that command seems to be missing a paren when I ran it, but after fixing that, p/tap and tap> did the trick


Whoaah... dogs, cats and avocados

bb -Sdeps '{:deps {djblue/portal {:mvn/version "0.56.0"}}}' --init \
    <(echo '(require (quote [portal.api :as p])) \
    (def p (p/open)) \
    (def data (-> "" slurp (json/parse-string true))) \
    (p/tap) \
    (tap> data) \
This is awesome.

👍 2