Fork me on GitHub
#babashka
<
2022-02-01
>
Benjamin09:02:20

I wonder if I can serialize to MessagePack with babashka

โœ… 1
borkdude09:02:57

can you tell more? there is a clojure library: https://github.com/edma2/clojure-msgpack but I'm not sure how well it works and it won't be that fast when converting loads of data

borkdude09:02:18

It seems it requires java.io.DataInput which isn't in bb, but I could add that

borkdude09:02:03

depending on your use case, you could also use nbb + a node lib for this

borkdude09:02:22

but if you're interesting in having clojure-msgpack work in bb, let me know

Benjamin10:02:09

the potential use case is to provide data for a csharp program that uses msgpack. Now I'm thinking json will do. It it some non critical code path

borkdude10:02:14

for fun, I will add the necessary classes for https://github.com/edma2/clojure-msgpack, to see if it works for you, if it doesn't you can fall back to JSON anyway

borkdude10:02:25

what OS are you using bb on?

Benjamin10:02:08

lul nice. Linux but this script would be for windows

Benjamin10:02:46

(require '[msgpack.core :as msg])
(require 'msgpack.clojure-extensions)

(assert (msg/pack {:compact true :schema 0}))
; => #<byte[] [B@60280b2e>

(assert (:compact (msg/unpack (msg/pack {:compact true :schema 0}))))
; => {:schema 0, :compact true}
works

borkdude11:02:47

Let me know if this adds any value, I haven't merged this to master yet

Benjamin11:02:00

I can say I use it for my thingy now. Beyond that I don't know what the tradeoffs are

borkdude11:02:36

no real disadvantages, just wondering if the messagepack lib is working correctly

Benjamin11:02:52

at first glance it does. I guess I can try with testcheck or something. Isn't there something that makes arbitrary objects?

borkdude11:02:16

Just a smoke test on your project will do.

borkdude11:02:11

you can always get the latest master build from https://github.com/babashka/babashka-dev-builds

Benjamin11:02:24

ah that is sweet

Benjamin17:02:26

jo borkdude now I'm trying on windows ends up java.io.DataInput is missing there still. Version 0.7.5. Sorry for the late followup. wait maybe I'm lying ok yea I can confirm 0.7.5 works

borkdude18:02:12

so it works - problem solved?

Benjamin18:02:00

I was just doing something with the wrong version ๐Ÿ™ˆ

borkdude18:02:35

no problem :)

weidtn16:02:53

Hey, I want to use babashka like python for some scientific calculations and plotting. I am very familiar with matplotlib for python. Can I use libpython-clj with babashka? Is there some other way to generate plots with babashka? All I see is for viewing plots in the browser with things like hanami or oz. But I really prefer images for org-babel or even publishing.

borkdude16:02:09

@U01LR7M2B7A has done some cool stuff with org-babel and babashka.

borkdude16:02:29

libpython-clj doesn't work with babashka.

borkdude16:02:56

you might have more luck with #nbb - there you can use any Node.js library which may have some good plotting libraries

borkdude16:02:01

or just shell out to Python

dpsutton17:02:47

Is there a way to put something on the systemโ€™s clipboard from bb? A way to create a classpath or java command and have the person have access to that rather than managing the process directly in bb?

djblue17:02:21

Whenever I need to do this I shell out to a system utility, like pbcopy on osx for example.

escherize17:02:13

You could shell out to a python script with pyperclip to get cross-OS clipboard compatability.

escherize17:02:32

I lazy load dependencies like this:

(defn can-do? [program] (= 0 (:exit (sh "command" "-v" program))))

(defn install-or-noop [program install-fn]
  (when-not (can-do? program)
    (println (<< "You don't have {{program}} installed. Installing now..."))
    (install-fn)
    (println (<< "{{program}} should be installed now. Thanks!"))))

๐Ÿ™Œ 1
borkdude18:02:31

@U11BV7MTK I could see if that java.awt clipboard thing works with bb, without adding too much binary size... What was the invocation again?

dpsutton18:02:04

what do you mean?

dpsutton18:02:34

i am asking because i might do some scripting in the future. No need quite yet. And no idea how many others would find it useful

borkdude18:02:18

Something like this, but those awt classes aren't in bb yet: https://gist.github.com/exupero/1462ec16d8874dee9ee710257eaf3d3c I think with bb you could just shell out to pbcopy on mac, e.g.

@(babashka.process/process ["pbcopy"] {:in "dude"})

borkdude18:02:25

and then dude is in your clipboard

dpsutton18:02:59

yeah that would work on osx right now. I was wondering if there was a portable way

dpsutton18:02:14

i can make my own local scripts, but if anyone on windows wanted to share they are out of luck conceptually

borkdude18:02:32

yeah, that's where the .awt thing comes in, or you could dispatch on OS name to do the most likely thing

borkdude18:02:40

not sure if Windows has something like pbcopy

borkdude18:02:03

There is a predicate in babashka.core named windows? which only returns true on Windows

borkdude18:02:12

(for now that's the only function there)

borkdude18:02:43

some linuxes also have xclip so to be fully portable you could check with fs/which which one is available on which OS

borkdude18:02:05

We could paste that portable function on the babashka wiki

shem14:02:41

and in wayland linux it would be wl-copy

borkdude14:02:55

btw, I tried getting awt clipboard stuff into bb but it's not playing so well with graalvm (and adds binary size), so I think dispatching on os + finding the appropriate binary would still be best

๐Ÿ‘ 2
dpsutton15:02:37

That's so nice that you checked. Thanks @U04V15CAJ

Dig21:02:30

if you use osc52 enabled terminal like xterm, windows terminal, mintty, etc. you can use https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm/etc/osc52.sh, should be straight forward to port it to pure bb.