Fork me on GitHub
#babashka
<
2023-02-01
>
worrelsik14:02:08

What's the difference between running bb and bb repl (in a Linux terminal)? The screen looks the same to me.

Bob B14:02:20

bb has several subcommands; if no subcommands are provided, the subcommand implicitly used is repl

šŸ‘ 1
worrelsik14:02:47

Argh, I should have read to the very last line of bb help . Thanks!

ag21:02:44

I'm using borkdude/jet to convert json to edn, having too minor issues: ā€¢ --keywordize turns json strings like: "@class" to clj keywords like :@class ā€¢ commas, I don't need them, how do I remove 'em?

borkdude21:02:37

You can pass a function to --keywordize and do whatever you want

ag21:02:11

Ah, cool. Thank you. Will try that! Appreciate it!

borkdude21:02:23

About commas, I don't think Clojure has a way to not print those when printing maps

ag21:02:29

Right, right... I am having my first senior moment or something šŸ™‚ I quite forgot, I asked you about commas long ago, you told me to use zprint instead if they bother me so much

borkdude21:02:15

@U0G75ARHC I think you can also write a tiny babashka script to rip out the commas from maps using rewrite-clj

ag21:02:37

it's alright, it ain't biggy. I'm basically using it to convert responses when poking into APIs from Emacs. I would run a query; it comes back with json; there's a hook fn, it grabs the content and feeds it into call-process-region.

ag21:02:09

which on its turn calls jet and voila

ag21:02:36

I love it. I can then quickly dissect the data, see the count, filter, map, etc. Damn, I wish more people knew how much better EDN is compared to json. It's more concise and much more readable; you can quickly align things, sort, group and filter.

šŸ‘ 1
ag21:02:30

I used to get annoyed when someone sends me a link to a json snippet "grrr.. why do I have to stare at this monstrosity?"... now, I'd just run my transform function (that uses jet), and immediately see what's up

borkdude21:02:37

Out of curiosity I tried stripping commas with rewrite-clj:

user=> (str (let [loc (z/of-string "{:a 1, :b 2}")] (loop [loc loc] (let [next (z/next* loc)] (if (z/end? loc) (z/root loc) (if (= :comma (z/tag loc)) (recur (z/remove* loc)) (recur next)))))))
"{:a 1 :b 2}"
cc @UE21H2HHD

clojure-spin 2
šŸ†’ 2
babashka 1
ag21:02:55

Maaan, sometimes I'm scared to talk to you. You think faster in Clojure, than I can type in English.

borkdude21:02:15

Here's the script:

[email protected] ~/dev/babashka (master*) $ echo '{:a 1 :b 2}' | jet
{:a 1, :b 2}
[email protected] ~/dev/babashka (master*) $ echo '{:a 1 :b 2}' | jet | /tmp/strip_commas.bb
{:a 1 :b 2}
[email protected] ~/dev/babashka (master*) $ cat /tmp/strip_commas.bb
#!/usr/bin/env bb

(require '[rewrite-clj.zip :as z])

(-> (let [loc (z/of-string (slurp *in*))]
       (loop [loc loc]
         (let [next (z/next* loc)]
           (if (z/end? loc) (z/root loc)
               (if (= :comma (z/tag loc))
                 (recur (z/remove* loc))
                 (recur next))))))
    str
    (print))

(flush)

metal 4
šŸ‘ 1
šŸ¤“ 1