babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2020-09-29T07:18:38.155Z

@jeroenvandijk Found a way to automatically update the path after install:

function glam-install {
    export PATH="$(clojure -M:glam --install $@):$PATH"
}

borkdude 2020-09-29T07:18:58.155400Z

(and renamed the repo, since it conflicted with the C++ package manager: https://github.com/borkdude/glam)

2020-09-29T07:53:53.156Z

@borkdude nice!

2020-09-29T07:55:51.157100Z

Glam is also a nice find ๐Ÿ™‚

danielgrosse 2020-09-29T10:42:46.164300Z

Hello @borkdude, I wrote some small tools with Babashka an really like it. So thanks for the work you put into. I currently create a more complex project and would like to add some tests. But putting the script into a Clojure folder structure brings up errors when running it. Also I donโ€™t know how to run tests, especially with pods. Do you have an example where I can look at?

borkdude 2020-09-29T10:51:21.165Z

@danielgrosse When putting it in a Clojure folder structure you will need to add src and test to the classpath: -cp src:test

borkdude 2020-09-29T10:51:56.165400Z

@danielgrosse Here is a snippet that shows how you can run tests: https://github.com/borkdude/babashka#running-tests

borkdude 2020-09-29T10:52:06.165800Z

And thanks.

2020-09-29T11:40:39.167600Z

Iโ€™m trying to write a Pod in babashka using pod-babashka-hsqldb as an example (https://gist.github.com/jeroenvandijk/55dc9005035bc506493ca279d43b2236). Something goes wrong in the communication while loading the pod, but I donโ€™t see it how it is different from the example. This is the error

bb <http://pod-usage.bb|pod-usage.bb>
{format edn, namespaces [{name (quote calculate), vars [{name (quote +)}]}], opts {shutdown {}}}
[message {id #object[[B 0x167d0535 [B@10c7ae618], op #object[[B 0x10cb3ebd [B@10c7aec00]}]
{:id2 ab473001-1b2b-482f-abd8-c9b2a7f3a619, :op2 :describe}
----- Error --------------------------------------------------------------------
Type:     java.lang.ClassCastException
Message:  clojure.lang.PersistentVector cannot be cast to byte[]
Location: /Users/jeroen/Projects/Github/bb-pod/pod-usage.bb:3:1

----- Context ------------------------------------------------------------------
1: (require '[babashka.pods :as pods])
2:
3: (pods/load-pod ["bb" "<http://pod.bb|pod.bb>"])
   ^--- clojure.lang.PersistentVector cannot be cast to byte[]
4:
5: (println "pod loaded")
6:
7: (require '[calculate])
8:

----- Stack trace --------------------------------------------------------------
user - /Users/jeroen/Projects/Github/bb-pod/pod-usage.bb:3:1

:EOF

borkdude 2020-09-29T11:42:00.168400Z

Not sure, I've got a meeting coming up, so I'll answer later today.

2020-09-29T11:42:07.168700Z

o wait i see it i think nope

2020-09-29T11:42:10.168900Z

Thanks

borkdude 2020-09-29T11:52:40.169400Z

@jeroenvandijk it often helps to write to stderr in the pod in case of an error

2020-09-29T11:59:11.170Z

Ok it was a quoting issue in describe map , now it works ๐Ÿ™‚

borkdude 2020-09-29T12:00:49.170400Z

๐Ÿ˜Ž

2020-09-29T12:01:01.170700Z

Iโ€™ve updated the gist. Will make something more interesting later I hope ๐Ÿ™‚

tzzh 2020-09-29T14:17:50.171900Z

Iโ€™ve released v0.0.2 of https://github.com/tzzh/pod-tzzh-aws with improved pagination, better code generation and more services (happy to include more if anybody needs)

๐Ÿ‘ 2
borkdude 2020-09-29T14:43:11.172300Z

:thumbsup:

borkdude 2020-09-29T15:11:26.172600Z

@thomas.ormezzano btw, I checked:

borkdude@DESKTOP-JN2UNTV ~ $ /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe

Try the new cross-platform PowerShell <https://aka.ms/pscore6>

PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\Ubuntu-20.04\home\borkdude&gt; clojure
Clojure 1.10.1
user=&gt; (System/getProperty "os.arch")
"amd64"
;; Linux:
borkdude@DESKTOP-JN2UNTV ~ $ clojure
Clojure 1.10.1
user=&gt; (System/getProperty "os.arch")
"amd64"
                                                                                                                                                                                                         ;; MacBook

$ clj
Clojure 1.10.1
user=&gt; (System/getProperty "os.arch")
"x86_64"

borkdude 2020-09-29T15:12:03.172800Z

so on macOS or maybe depending on which Java version you are on, os.arch responds with x86_64 or amd64 hmm

tzzh 2020-09-29T15:12:46.173Z

ah ok they are the same though right ? I just copied what had been auto generated in the binaries I created tbh

borkdude 2020-09-29T15:13:07.173200Z

yeah, maybe the package manager should just deal with that

borkdude 2020-09-29T15:13:51.173400Z

I'll fix that, thanks

๐Ÿ‘ 1
borkdude 2020-09-29T15:16:18.173800Z

borkdude@MBP2019 ~ $ glam install tzzh/pod-tzzh-aws -g
borkdude@MBP2019 ~ $ pod-tzzh-aws
works :)

tzzh 2020-09-29T15:17:16.174Z

nice ๐Ÿ™‚

2020-09-29T15:28:57.174800Z

Here is a proof of concept for loading arbitrary Clojure libraries via Pods https://github.com/jeroenvandijk/pod-babashka-clj/blob/master/examples/aws.bb.clj

๐Ÿ˜Ž 2
2020-09-29T15:30:52.175400Z

It needs some more work around keeping track of the started jvm processes, but the basics work

borkdude 2020-09-29T15:31:18.175600Z

why not directly go with Clojure in this case, would be the obvious question?

2020-09-29T15:32:28.175800Z

True, iโ€™m thinking you could have a process running in the background that can deal with the things that Babashka canโ€™t. So if you use AWS a lot it only needs to start once

borkdude 2020-09-29T15:33:08.176Z

yeah. can also use the nREPL client for that

2020-09-29T15:33:39.176200Z

yeah maybe that would be an alternative. This is using the prepl so same idea i guess

borkdude 2020-09-29T15:33:58.176400Z

cool idea

2020-09-29T15:34:25.176600Z

itโ€™s a combination of pods and this idea https://github.com/jeroenvandijk/clojure-scripting

borkdude 2020-09-29T15:35:00.177Z

:thumbsup:

2020-09-29T15:35:01.177200Z

Writing a pod in babashka itself was easier than i had expected

borkdude 2020-09-29T15:36:20.177400Z

Have you already tested the tzzh aws pod, since you are interested in AWS stuff?

borkdude 2020-09-29T15:36:44.177600Z

You can now install it using glam :)

2020-09-29T15:37:19.177800Z

No I havenโ€™t. My main concern is not having to learn new libraries ๐Ÿ˜… I think the tzzh aws pod is inventing a new API

2020-09-29T15:38:03.178Z

iโ€™ll check it out now before i say something stupid

borkdude 2020-09-29T15:40:40.178200Z

I think a similar approach could work for Clojure. Just generate all the code at compile time instead of using reflection/dynamic requires

borkdude 2020-09-29T15:40:59.178400Z

(at least, that's how I think the cognitect lib works?)

2020-09-29T15:41:10.178600Z

yeah I agree. pretty sure the aws-api can be made compatible with Graalvm

2020-09-29T15:41:19.178800Z

it just requires some work

borkdude 2020-09-29T15:41:42.179Z

the tzzh pod looks quite easy to use though.

borkdude 2020-09-29T15:42:06.179200Z

although I don't know the Java AWS API, I can't imagine why they would re-invent a different API in Go or Python

borkdude 2020-09-29T15:42:21.179400Z

it's all going to the same endpoints eventually I guess

2020-09-29T15:42:31.179600Z

no i mean the clojure api is not the same

2020-09-29T15:42:39.179800Z

the backend is definitely the same

2020-09-29T15:43:11.180Z

so I mean the api of pod-tzzh-aws is not the same as cognitect aws-api. So i would have to learn both

2020-09-29T15:43:19.180200Z

cannot reuse my code

2020-09-29T15:44:57.180400Z

And personally I donโ€™t want to debug go code if things go wrong

2020-09-29T15:45:22.180600Z

But thatโ€™s just me. itโ€™s nice that pod-tzz-aws exists

borkdude 2020-09-29T15:47:04.180800Z

fair

borkdude 2020-09-29T15:49:52.181Z

I think the idea to use a small fast starting script to invoke something in a larger stateful context is similar to Datomic Ions with AWS Lambda + Datomic running on other machines

borkdude 2020-09-29T15:50:23.181300Z

so you could have one Clojure REPL running on an EC2 instance permanently

borkdude 2020-09-29T15:50:35.181500Z

and babashka in AWS lambda sending commands to its REPL

2020-09-29T15:51:01.181700Z

yeah i think you are right, pretty similar

2020-09-29T15:53:00.181900Z

It could also be useful if stateful means loading a really big library that would otherwise impact startup time

2020-09-29T15:57:20.182100Z

Iโ€™m not sure if the prepl should be used for concurrent commands, but the concept could be implemented via other protocols as well

borkdude 2020-09-29T15:58:18.182300Z

nREPL supports this well via ids

2020-09-29T15:59:04.182500Z

sounds like its more suited for something like this then

borkdude 2020-09-29T15:59:06.182700Z

Small example: https://github.com/borkdude/babashka#communicating-with-an-nrepl-server

borkdude 2020-09-29T15:59:25.183100Z

A more full example can be seen in the tests of babashka.nrepl

๐Ÿ‘ 1
borkdude 2020-09-29T16:00:05.183300Z

The babashka pod protocol is more or less the same as nREPL, with a few twists

2020-09-29T16:05:58.183500Z

cool, i havenโ€™t really dived into that protocol yet. Not sure what the tradeoffs are compared with the prepl protocol

richiardiandrea 2020-09-29T17:42:05.184100Z

is this a way to generically use any clojure/java library?

richiardiandrea 2020-09-29T17:44:31.184300Z

(I am looking for a quick way to run the Mongo or the RabbitMQ clients in babashka ๐Ÿ˜„)

richiardiandrea 2020-09-29T17:46:33.184500Z

Oh I see what you did there, kinda cool good job!

2020-09-29T17:49:01.184700Z

Yeah the idea is that anything that tools.deps can load, can be accessed via this pod

2020-09-29T17:49:28.184900Z

Currently there is no proper management of the backend process and the port is hardcoded right now, but this can be fixed

2020-09-29T17:50:21.185100Z

And maybe some error scenarios are hard to debug because of the limited communication between the pod and the babashka process right now. Probably needs another layer to get this right

richiardiandrea 2020-09-29T17:53:57.185400Z

seems like this could be a good candidate for being embedded in babashka.. pods are nice for interop with other langs but if you already have a clojure libs it can be easier

2020-09-29T20:56:19.185600Z

Yeah maybe. Pods give us a nice way to experiment with this idea for now at least. If you want to try with Mongo and RabbitMQ I can help out if you run into problems

borkdude 2020-09-29T20:57:54.185800Z

doesn't mongo support an http api btw?

Dig 2020-09-29T21:13:55.186800Z

what would be equivalent in babashka to a common pattern $ cat file.txt | sort | uniq -c ?

nate 2020-09-29T21:18:30.187Z

one version:

bb '(-&gt; (slurp "file.txt") (str/split #"\n") sort distinct)'

2020-09-29T21:19:11.187300Z

you are too quick ๐Ÿ™‚ I can only add clojure.string/split-lines over str/split

nate 2020-09-29T21:19:23.187500Z

ah, good one

nate 2020-09-29T21:19:45.187700Z

I like to let bb to the input, so I would prefer this:

cat file.txt | bb -i '(-&gt; *input* sort distinct)'

nate 2020-09-29T21:19:49.187900Z

seems a bit cleaner

isak 2020-09-29T21:20:13.188100Z

I think he needs frequencies , no?

Dig 2020-09-29T21:20:39.188300Z

yep, that uniq -c is the tricky peace

nate 2020-09-29T21:21:07.188500Z

ah, true, replace distinct with frequencies

nate 2020-09-29T21:21:17.188700Z

cat file.txt | bb -i -O '(-&gt; *input* sort frequencies)'

2
nate 2020-09-29T21:22:02.189100Z

to make the number show up first:

cat file.txt | bb -i -O '(-&gt; *input* sort frequencies (-&gt;&gt; (map reverse)))'

๐Ÿ‘ 1
nate 2020-09-29T21:23:33.189300Z

absolute closest to the original:

cat file.txt | bb -i -o '(-&gt; *input* sort frequencies (-&gt;&gt; (map reverse) (map (partial str/join " "))))'

nate 2020-09-29T21:23:42.189500Z

ok, I'll stop now, bb is just too fun

๐Ÿ™‚ 1
lucian303 2020-09-29T21:31:11.191500Z

i'm getting an error trying to use drewr/postal with bb . is this something that should work or is it not supported? if the latter is there another way to send an email? i don't need anything fancy, it's just for error notifications. smtp or sendmail would be fine

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.text.SimpleDateFormat
Location: postal/date.clj:24:1

----- Context ------------------------------------------------------------------
20: ;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21: ;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22: ;; OTHER DEALINGS IN THE SOFTWARE.
23:
24: (ns postal.date
    ^--- Unable to resolve classname: java.text.SimpleDateFormat
25:   (:import [java.util Date]
26:            [java.text SimpleDateFormat ParsePosition]))
27:
28: (defn make-date
29:   ([tmpl s]

richiardiandrea 2020-09-29T21:32:29.191600Z

I think it does

borkdude 2020-09-29T21:35:50.192300Z

Nicer formatting:

cat README.md | bb -io '(-&gt;&gt; *input* sort frequencies (map (fn [[l n]] (format "%3s %s" n l))))'

borkdude 2020-09-29T21:37:22.193Z

@lucian303 Not yet supported.

borkdude 2020-09-29T21:38:19.193500Z

@lucian303 I did in fact had one branch with postal in it once: https://github.com/borkdude/babashka/issues/366, but I ran into a JDK 11 bug

lucian303 2020-09-29T21:39:14.194300Z

gotcha. thanks. are there any alternative libraries that you know of that might work? @borkdude

borkdude 2020-09-29T21:40:06.195200Z

Probably not out of the box I think. The only alternative now is probably shelling out to sendmail or alike or using an HTTP mail service like sendgrid

lucian303 2020-09-29T21:40:47.195700Z

gotcha. thanks. i'm probably just going to shell out then

borkdude 2020-09-29T21:45:49.196500Z

Come to think of it, I think this can be perfectly implemented as a mailer pod

borkdude 2020-09-29T21:45:58.196700Z

since an email is just plain data

borkdude 2020-09-29T21:46:35.197200Z

e.g. drewr/postal could be compiled with GraalVM java 8 and then be used from babashka

borkdude 2020-09-29T21:47:04.197700Z

it's a bit of work, but not too hard since there's already plenty of examples around

Dig 2020-09-29T21:50:13.198500Z

thank you! i've added couple of things and end up with

tshark -r /var/tmp/DNS.pcap00.gz -T fields -e dns.qry.name dns.qry.type==1 | bb -io '(-&gt;&gt; *input* sort frequencies clojure.set/map-invert (into (sorted-map)) (map (fn [[k v]] (format "%6s %s" k v))))'

borkdude 2020-09-29T21:51:37.199400Z

:thumbsup: clojure power!

Darin Douglass 2020-09-29T21:51:45.199600Z

The fix for postal in java 9+ is super easy https://github.com/drewr/postal/issues/107

borkdude 2020-09-30T14:08:54.239900Z

I tried this, but I still get the same error

Darin Douglass 2020-09-30T14:30:44.240100Z

hmm, shucks. that fixed postal for me in a normal JVM context. not sure what more graal will need ๐Ÿ˜•

borkdude 2020-09-30T14:35:13.240400Z

I fixed that by adding a class to the reflection config. Now I'm looking at `javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/plain; charset=utf-8 `

Darin Douglass 2020-09-30T15:05:03.240600Z

feels like we're going down the rabbit hole of javax.mail soon. (i WORK at a clojure shop that deal with email, so a rabbit hole it is)

borkdude 2020-09-30T15:05:45.240800Z

Summary in https://github.com/borkdude/babashka/issues/599

borkdude 2020-09-30T15:06:04.241200Z

Maybe writing it as a pod wrapping that other library could work

borkdude 2020-09-29T21:53:32.200800Z

Ah nice. We can re-consider adding drewr/postal using that approach or implementing it as a pod first (depending on the extra size, how many people need this, etc)

borkdude 2020-09-29T21:57:12.201100Z

Made an issue here: https://github.com/borkdude/babashka/issues/599 Feel free to leave feedback

borkdude 2020-09-29T22:02:09.201500Z

btw, this is another lib in the SMPT space: https://github.com/toyokumo/tarayo

nate 2020-09-29T22:02:52.202100Z

wow

nate 2020-09-29T22:03:20.202500Z

be careful with map-invert, it'll collapse ties

lucian303 2020-09-29T22:03:25.202700Z

nice. i'll try tarayo as i'm a bit short on time

nate 2020-09-29T22:04:00.203Z

(clojure.set/map-invert {:foo 1 :bar 1}) -> {1 :bar}

borkdude 2020-09-29T22:04:00.203200Z

I don't think that will work with bb out of the box though

borkdude 2020-09-29T22:04:43.203500Z

bb doesn't have the javax.mail.Transport etc classes currently

lucian303 2020-09-29T22:07:26.203800Z

yeah, it won't