babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
agilecreativity 2021-03-02T00:09:26.207Z

From the quick start from bootleg: https://github.com/retrogradeorbit/bootleg/blob/master/examples/quickstart/example-combine.clj

(mustache "quickstart.html"
          (assoc (yaml "fields.yml")
                 :body (markdown "simple.md" :html)))

borkdude 2021-03-02T07:54:59.207600Z

But using the pod interface does that work as well?

borkdude 2021-03-02T09:35:13.208200Z

Crispin, bootleg author, provided me with an answer:

(require '[babashka.pods :as pods])

(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")

(require '[pod.retrogradeorbit.bootleg.markdown :as md])

(def md-text
"# Hello

- This is a list
- Another item"
  )

(md/markdown md-text :data :html)

Jakub Holý 2021-03-02T13:24:57.208400Z

Wasn't there an example of serving static content from bb, possibly via http kit server?

borkdude 2021-03-02T13:34:52.208500Z

@holyjak I have an image viewer example here: https://github.com/babashka/babashka/blob/master/examples/image_viewer.clj

❤️ 1
wilkerlucio 2021-03-02T14:16:06.208800Z

any special reason for not using hiccup on the html generation?

borkdude 2021-03-02T14:22:18.209Z

Hiccup wasn't part of babashka when I wrote that. Feel free to send a PR

Dig 2021-03-02T14:46:44.210500Z

Is there a way to do #!/usr/bin/env --stream -io in the script or something equivalent?

borkdude 2021-03-02T14:49:30.211Z

@i.slack There are some tricks using exec

#!/bin/sh

#_(
   "exec" "bb" "$0" hello "$@"
   )

(prn *command-line-args*)

./script.clj 1 2 3
("hello" "1" "2" "3")

Dig 2021-03-02T14:52:12.211800Z

thanks I will keep it as bash function for this one then: function truncate-lines { bb --stream -io "(subs *input* 0 (min ${1:-$COLUMNS} (count *input*)))" }

borkdude 2021-03-02T14:55:16.212100Z

nifty :)

Dig 2021-03-02T15:20:08.214Z

Another one I use all the time:

function squeeze-lines {
    bb --stream -io "(let [c #{\space \tab \-}] (->> *input* (partition-by c) (map (fn [[f :as r]] (if (c f)
 (str f) (apply str r)))) (apply str)))"
}

Dig 2021-03-02T15:21:10.215200Z

of cause if you do not stuck on windows you can just do $ colrm for first one and $ tr -s ' -' for second 🙂

borkdude 2021-03-02T15:24:27.215700Z

This is some advanced i/o flag usage :)

borkdude 2021-03-02T15:25:07.216Z

You can probably write this as a single bb script though

borkdude 2021-03-02T15:25:16.216200Z

without the i/o flags

Dig 2021-03-02T15:25:51.216800Z

yes, but then it will not be one liner lol

borkdude 2021-03-02T15:26:02.217100Z

squeeze-lines.clj - yeah, you're right, one-liners are fun ;)

Dig 2021-03-02T15:28:06.217800Z

did you write squeeze-lines.clj? or is it just a tease?

borkdude 2021-03-02T15:28:26.218200Z

just a suggestion that instead of bash fns you can write a script and put it on your path

borkdude 2021-03-02T15:29:45.219600Z

you will probably need (line-seq (io/reader *in*)) or (str/split-lines (slurp *in*))

Dig 2021-03-02T15:30:21.220Z

cool that helps

nate 2021-03-02T18:49:56.225700Z

is there a preferred babashka-compatible library for colorizing output in the terminal? https://github.com/ams-clj/clansi fails to load because of ref, https://github.com/trhura/clojure-term-colors seems to work

nate 2021-03-02T18:50:45.226700Z

I would be nice to be able to do more than the basic 8 colors

borkdude 2021-03-02T18:53:11.226900Z

what was that one called again...

borkdude 2021-03-02T18:53:29.227100Z

https://github.com/babashka/babashka/issues/547

borkdude 2021-03-02T18:54:20.227500Z

^ @nate

nate 2021-03-02T18:55:59.227700Z

aha!

nate 2021-03-02T18:56:03.227900Z

thank you!

borkdude 2021-03-02T19:03:11.228200Z

Feel free to add the clojure-term-colors to the issue

borkdude 2021-03-02T19:03:22.228500Z

And I guess we should add ref

nate 2021-03-02T19:04:11.229400Z

sure, I'll add a comment

borkdude 2021-03-02T19:04:40.230100Z

although that lib is so old when atoms probably were not the defacto mutability solution /cc @skuro (clansi: developed at the Amsterdam Clojure meetup it seems)

nate 2021-03-02T19:06:38.230700Z

yeah, it's a very old lib

lukasz 2021-03-02T19:11:00.232Z

btw, my bb + lambda experiment is on hold - Lambda doesn't support pulling images from linked accounts 😢

2021-03-03T10:46:31.249900Z

@lukaszkorecki Did you check lambda layers? I was experimenting with Sci and nodejs for lambda before and I think layers are shareable cross account

2021-03-03T10:48:20.250200Z

Layers support resource-based policies for granting layer usage permissions to specific AWS accounts, AWS Organizations, or all accounts.
https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html

borkdude 2021-03-03T11:48:55.252400Z

borkdude 2021-03-03T11:49:07.252800Z

borkdude 2021-03-03T11:49:15.253200Z

This is from the GraalVM slack, channel native-image

👍 2
lukasz 2021-03-03T17:05:15.258700Z

To clarify - this is not specific to GraalVM, as this is a limitation of Lambda+Docker in general

borkdude 2021-03-03T17:06:32.258900Z

Yeah, just wanted to bring it to his attention ;)

borkdude 2021-03-03T17:06:49.259100Z

@borkdude if they're talking about container images, that will be supported in the future, but obviously I can't say exactly when

borkdude 2021-03-03T17:06:57.259300Z

this was his reply

lukasz 2021-03-03T17:07:11.259500Z

Yeah, there's a thread in AWS support forum, no more information beyond that

lukasz 2021-03-03T17:07:29.259700Z

Knowing them and my luck - it will be fixed tomorrow 😉

lukasz 2021-03-02T19:11:15.232200Z

and that's a blocker for us

borkdude 2021-03-02T19:14:48.232900Z

ah, that's a bummer. what is a "linked account"? and the layer approach?

lukasz 2021-03-02T19:21:33.234400Z

In AWS you can setup permissions for one account to pull/push images from another, this is useful if you're using a multi-account setup (we have an account per environment, for example). This way you can push images to one account, and all others can pull them, without duplicating storage. It's all still protected via IAM of course

lukasz 2021-03-02T19:22:14.235200Z

Currently for Lambda to pull an image, the ECR image repository has to be in the same account

borkdude 2021-03-02T19:26:26.237Z

@wilkerlucio OK, I think we can add them here: https://github.com/babashka/babashka/blob/f335716d1d24e2d2bf9c345ff773d985ad8f2a35/src/babashka/impl/reify.clj#L42 Please also add an accompanying test in babashka.main-test somewhere at the bottom

borkdude 2021-03-02T19:28:29.237600Z

Associate and Counted should also be added here: https://github.com/babashka/babashka/blob/f335716d1d24e2d2bf9c345ff773d985ad8f2a35/src/babashka/impl/classes.clj#L252

borkdude 2021-03-02T19:28:48.238200Z

Let's continue in babashka-sci-dev, I'll invite you there

wilkerlucio 2021-03-02T19:29:26.238300Z

one consideration here, so far I see Babashka mimics the JVM API/protocols, but the protocols from CLJS are better (due to CLJS coming later, the protocols there are better broken down, I remember David Nolen talking about would be great if Clojure used those, but were too late for Clojure, for compatibility)

wilkerlucio 2021-03-02T19:29:47.238500Z

so I wonder if a better idea would be to mimic CLJS protocols instead, but I have no idea how that impacts the Babashka dev on itself

rwstauner 2021-03-02T20:31:39.238700Z

how would you (like to) refer to the other colors? i've never found the 88/256 number schemes to be very intuitive so i'm curious how you think about them (or how you use them in another context)

nate 2021-03-02T21:55:46.239Z

I have a wonderful vim plugin that lets me highlight words in a variety of colors, and that helps me track multiple identifiers at once.

nate 2021-03-02T21:56:08.239200Z

I was considering writing a babashka script that would do the same thing when looking at a log file

nate 2021-03-02T21:56:28.239400Z

but I need to be able to highlight with more than the base 8

nate 2021-03-02T21:56:32.239600Z

I'll probably pick a good set from the 256 color palette and just give them names

nate 2021-03-02T21:57:27.239900Z

I figured out how to print out the codes, it's just a series of characters

nate 2021-03-02T21:58:48.240100Z

oh cool, I found a listing of them with names and the 256-code number: http://jonasjacek.github.io/colors/

rwstauner 2021-03-02T22:15:13.240400Z

yeah, i do that with vim sometimes. i also wrote a script to colorize multiple terms in perl many years ago. i also wrote an ansi parser in perl. but i haven't thought about that in years

nate 2021-03-02T22:36:49.240600Z

https://github.com/inkarkat/vim-mark is the plugin that I use

nate 2021-03-02T22:37:10.240900Z

it's probably in my top 5 plugins from a usage POV