babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
wilkerlucio 2021-02-28T14:45:35.142400Z

given https://clojurians.slack.com/archives/CLX41ASCS/p1614426753131400?thread_ts=1614417434.128100&cid=CLX41ASCS limitation, is there a way to implement a custom map type in Babashka?

borkdude 2021-02-28T15:31:04.142900Z

@wilkerlucio What would you need to implement this? reify + ILookup + ...?

wilkerlucio 2021-02-28T15:31:30.143Z

but also IFn, to make (map :key)

borkdude 2021-02-28T15:31:56.143300Z

and what about assoc etc?

wilkerlucio 2021-02-28T15:32:29.143500Z

yeah, all of those, in the CLJ side I'm currently using Potemkin, but there he also takes care of a lot of Java specific interfaces that I believe are unescessary in Kondo

wilkerlucio 2021-02-28T15:32:46.143700Z

for CLJS there also a few different protocols, so I'm not sure the exact list needed for babashka*

borkdude 2021-02-28T15:32:52.143900Z

kondo?

borkdude 2021-02-28T15:33:02.144200Z

ah

wilkerlucio 2021-02-28T15:33:55.144400Z

this is what I have (clj using Potemkin / CLJS manually): https://github.com/wilkerlucio/pathom3/blob/master/src/main/com/wsscode/pathom3/interface/smart_map.cljc#L291-L390

borkdude 2021-02-28T15:40:11.144700Z

Can you clone babashka locally? And then the branch custom-map.

$ clojure -M:main -e '(def m (reify clojure.lang.ILookup (valAt [this x] (str "->" x)))) (:foo m)'
"->:foo"

borkdude 2021-02-28T15:40:20.144900Z

Clone using the --recursive option

wilkerlucio 2021-02-28T15:41:16.145100Z

so, my guess here is that I may be able to almost fulfil the complete contract, just not the IFn part?

borkdude 2021-02-28T15:43:13.145400Z

$ clojure -M:main -e '(def m (reify clojure.lang.IFn (invoke [this arg] (str "arg->" arg)))) (m :foo)'
"arg->:foo"

borkdude 2021-02-28T15:45:19.145600Z

The way it's currently set up it only supports one arity but I think I can change this

wilkerlucio 2021-02-28T16:05:45.145800Z

cool, working on other things now, but I'll give a try on that, thanks!

borkdude 2021-02-28T16:28:52.146Z

I fixed the arity problem locally. Any more interfaces you need?

borkdude 2021-02-28T16:28:55.146200Z

I'm about to cut a release

wilkerlucio 2021-02-28T16:50:23.146400Z

sorry, cant check now

wilkerlucio 2021-02-28T16:50:35.146700Z

go ahead with the release 🙂

borkdude 2021-02-28T17:22:02.146900Z

I've got ILookup and IFn working now for all arities

borkdude 2021-02-28T17:47:56.147100Z

Luis Santos 2021-02-28T19:14:40.150300Z

Hi everyone, I'm currently trying to use records in babashka but they don't seem to work. The documentation says that the implementation is different from clojure but that it should work as expected. In the example bellow the messages are never printed. Am I doing something wrong? Should I open a bug or is this a know limitation? Thanks

(defprotocol Task
  (test [this])
  (test2 [this]))

(defrecord TaskImpl [a b]
  Task
  (test  [this] (println "It should be printed"))
  )

(defmethod test2 TaskImpl []
  (println "It should be printed")
  )

(let [ t (->TaskImpl "a" "b") ]
  (.test t)
  (.test2 t))

borkdude 2021-02-28T19:39:10.151400Z

@luis559 Made it a little bit linter proof ;). Note that you can just call the methods by name, you don't have to use .test, although we could probably make that work

(ns foo (:refer-clojure :exclude [test]))

(defprotocol Task
  (test [this])
  (test2 [this]))

(defrecord TaskImpl [a b]
  Task
  (test [_] (println "It should be printed (proto)")))

(defmethod test2 TaskImpl [_]
  (println "It should be printed (mm)"))

(let [ t (->TaskImpl "a" "b") ]
  (test t)
  (test2 t))
It should be printed (proto)
It should be printed (mm)

Luis Santos 2021-02-28T19:41:13.151700Z

Thanks. Let me try it again.

Luis Santos 2021-02-28T20:15:30.152Z

@borkdude Thanks. I managed to get it to work. I figured out what my problem was. I was not able to call methods my name like you suggested because I forgot to import them. I guess the biggest difference between the 2 approaches would be weather or not you one needs to import the methods. To make sure my library is compatible with clojure and babashka I have to make sure I don't use the dot syntax.

robertfw 2021-02-28T20:44:39.156600Z

Apologies if I missed something obvious in the docs - how can I have a script I am writing return a non-zero exit code? I'm giving babashka a whirl for the first time today, writing a little helper script so I can have one command to properly pick the right command for unpacking a given file. I've googled "tar gz command line options" more than I care to admit, and then today downloaded something that was .tar.xz. Figured it was time to scratch the itch. I've called it bunpack 🐰 🫓

robertfw 2021-02-28T20:46:42.157200Z

doh. Never fails, ask a question publicly, find your answer immediately thereafter. I believe System/exit is what I needed

borkdude 2021-02-28T20:47:17.157700Z

@robertfrederickwarner That's it and don't worry, feel free to ask anything here

robertfw 2021-02-28T20:48:33.158900Z

Thanks @borkdude. Your prolific work astounds! I always loathed writing bash scripts, this is a wonderful addition to the ecosystem

borkdude 2021-02-28T20:54:52.159Z

This looks exciting, thanks for making it babashka compatible @luis559 :)

🆒 3
Luis Santos 2021-02-28T20:56:29.159100Z

Thank for helping and sorry misspelling babashka. ;)

borkdude 2021-02-28T20:56:32.159300Z

@luis559

binary: "/usr/bin/ffprobe"
args:   [:show_format :show_streams "<http://ftp.nluug.nl/pub/graphics/blender/demo/movies/ToS/ToS-4k-1920.mov>"]
task:   {:ss nil, :ex #error {
 :cause "error=2, No such file or directory"
It's probably best to look on the path for ffprobe?

Luis Santos 2021-02-28T20:57:39.159500Z

I will update the docs. But if you remove the binary name it will use whatever is available in the path.

borkdude 2021-02-28T20:58:20.159700Z

Ah I didn't know that, thanks.

2021-02-28T21:18:50.161Z

Used Babashka over cgi to create a really basic line art svg generator https://cgi.eccentric-j.com/lineart/lineart.svg?bg=000000&amp;fg=ffffff

🆒 2
2021-02-28T21:19:39.161700Z

https://github.com/eccentric-j/clj-lineart src if anyone’s interested in how it works

2021-02-28T21:26:51.168600Z

It did bring about some rough edges I’m trying to come up with better solutions for. The first one is the shebang for the entry point script. #!/home1/&lt;username&gt;/bin/bb makes it less portable. If I could set the PATH variable then I could use #!/user/bin/end bb but unfortunately cgi is pretty locked down so most environment variables are stripped away if set with Apache (according to my research and tests). I’m wondering if I could write a script that behaves like env that will set the path, point to bb, and perhaps supply the src dir relative to the entrypoint script.

adam-james 2021-03-01T13:30:39.188200Z

@jayzawrotny this is cool! If you plan to expand on the idea with more SVG elements, my library https://github.com/adam-james-v/svg-clj might be interesting to you. I'm working hard to get it polished, but some of the functionality might be useful to you as is.

2021-03-01T20:24:35.206100Z

That’s really cool! I foresee making more generative art experiments in the future. Thanks!

❤️ 1
2021-02-28T21:28:39.169800Z

Then at least it would be like #!../../bin/devenv bb which is a bit easier to replicate in a local docker for development or move to another server.

borkdude 2021-02-28T22:35:28.170200Z

@jayzawrotny Maybe you can str/replace the shebang once you deploy the script to bluehost?

borkdude 2021-02-28T22:36:58.170400Z

Is it possible to set the interpreter in the cgi config (for a certain file extension)? (sorry, no idea, I haven't used this myself)

2021-02-28T22:44:13.171200Z

As far as I found I can only modify a .htaccess to specify:

AddHandler cgi-script .clj
So that apache knows what to do with requests for that file.

2021-02-28T22:44:46.171400Z

There’s also some runtime config that would be nice to automate so I think a wrapper script would be a reasonable approach

borkdude 2021-02-28T22:44:48.171600Z

Yeah, so maybe making a before-deploy hook which rewrites your script just in time, will work

borkdude 2021-02-28T22:44:54.171800Z

ah I see

borkdude 2021-02-28T22:45:02.172Z

yeah, you could write a little bash wrapper

2021-02-28T22:47:43.172200Z

Deploys are pretty primitive right now, sometimes SFTP, sometimes rsync, sometimes scp

2021-02-28T22:51:56.172400Z

Is there a way to load code from a local file not on the classpath? Maybe load-file?

borkdude 2021-02-28T22:54:37.172600Z

Yep, that's the one

robertfw 2021-02-28T23:22:25.173900Z

Any suggested exemplars for a published babashka script intended for use on the command line? I pushed my little bunpack script up onto github, if anyone has use for it or any suggestions for how to package it in a nicely reusable form. https://github.com/robertfw/bunpack

🎉 2
borkdude 2021-02-28T23:27:37.175700Z

You could use a shebang so you don't need the bash wrapper:

#!/usr/bin/env bb

robertfw 2021-02-28T23:27:47.176Z

I meant to be learning CLJS today. I started installing shadow-js and got to the "install node" step, had to google "extract tar.xz" file.. and now here we are. I haven't learned CLJS but at least I got my feet wet with bb 😋

2
borkdude 2021-02-28T23:27:48.176100Z

And then just place the .clj script on the path

robertfw 2021-02-28T23:28:19.176300Z

I started with that but my emacs setup was throwing a hissy fit when trying to auto format the buffer

borkdude 2021-02-28T23:29:55.176600Z

@robertfrederickwarner If you are in clojure mode it should deal well with the shebang

robertfw 2021-02-28T23:34:40.176800Z

I may be making some basic mistake in how I'm interacting with the code. Currently, I'm running cider-jack-in-clj to connect my repl, and then cider-format-buffer . That results in an Invalid symbol: !/usr/bin/env. error

borkdude 2021-02-28T23:36:08.177Z

Have you put the hash sign in front of this?

robertfw 2021-02-28T23:36:26.177200Z

yup.

robertfw 2021-02-28T23:38:15.177400Z

Ah. I wonder if this is just starting up a regular clojure REPL. I'm guessing I'd want this to fire up a babashka repl instead?

borkdude 2021-02-28T23:38:17.177600Z

Then that could be a bug in cider-format-buffer. I'm always just using this function:

(defun iwb ()
  "Indent whole buffer."
  (interactive)
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))
Might be worth filing this bug to CIDER

borkdude 2021-02-28T23:38:57.177800Z

Yeah, that will start a regular clojure JVM

borkdude 2021-02-28T23:39:19.178Z

I've got to go now, later 💤

robertfw 2021-02-28T23:39:44.178200Z

Thanks for the tips! Good night

2021-02-28T23:50:32.178400Z

#!/bin/bash

export PATH="/home1/&lt;username&gt;/bin/:$PATH"
export CLJ_BB_LIB_PATH="/home1/&lt;username&gt;/lib/"

exec env bb -cp src "$@"
Making that my bbenv wrapper which I could reference from the parent dir or create a sibling symlink to. Should do the trick to keep host specific things out of the repos.