Fork me on GitHub
#clojure
<
2020-05-27
>
Fredrik Cumlin07:05:14

I want to set a color with rgba in my clojure code. How do I do it?

Fredrik Cumlin07:05:46

Like {:background-color rgba(0,0,0,0.5)}

seancorfield07:05:43

Are you talking about a web app or a terminal app?

Fredrik Cumlin07:05:25

This solved it: (str "rgba("255","0","0","0.2")")

Daniel Tan07:05:57

why not just “rgba(0,0,0,0.5)”

Fredrik Cumlin08:05:17

Yeah, much better. Thanks!

delaguardo08:05:25

there is also https://github.com/thi-ng/color

(require '[.color.core :as col])

@(col/as-css (col/rgba 255 0 0 0.2))
if you need more control

👍 4
Daniel Tan08:05:47

thanks, i needed this

Daniel Tan08:05:20

but why is the whole thing only shell

delaguardo08:05:00

this lib is written using literate programming

quan09:05:07

google cloud functions just support java11 runtime, I try to run clojure app on it but got the error. Follow the jave sample from this https://github.com/GoogleCloudPlatform/functions-framework-java, I have this class

(ns cloudfn.core
  (:gen-class
    :implements [com.google.cloud.functions.RawBackgroundFunction]))

(defn -accept [this s ctx]
  (prn s))
then, after build to uberjar file, run function by using the Functions Framework jar directly, I got error (same error as deploy to cloud function)
% java -jar java-function-invoker-1.0.0-alpha-2-rc5.jar --classpath target/cloudfn-0.1.0-SNAPSHOT-standalone.jar --target cloudfn.core
2020-05-27 16:41:36.206:INFO::main: Logging initialized @205ms to org.eclipse.jetty.util.log.StdErrLog
Exception in thread "main" java.lang.ExceptionInInitializerError
        at clojure.lang.Namespace.<init>(Namespace.java:34)
        at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
        at clojure.lang.Var.internPrivate(Var.java:156)
        at cloudfn.core.<clinit>(Unknown Source)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at com.google.cloud.functions.invoker.NewBackgroundFunctionExecutor.forClass(NewBackgroundFunctionExecutor.java:71)
        at com.google.cloud.functions.invoker.runner.Invoker.servletForDeducedSignatureType(Invoker.java:362)
        at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:290)
        at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:140)
Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.
        at clojure.lang.RT.load(RT.java:462)
        at clojure.lang.RT.load(RT.java:424)
        at clojure.lang.RT.<clinit>(RT.java:338)
        ... 13 more
Idk why clojure can't be load here?

sergey.shvets19:05:54

I haven't tried it yet, but have you tried to give class a name and add --entry-point parameter? pointing to that class? https://cloud.google.com/blog/products/application-development/introducing-java-11-on-google-cloud-functions I'm sure you have to specify entry point for functions somehow.

quan03:05:16

Yes, I did & still got the same error

lloydshark06:05:06

How did you package your app?

lloydshark06:05:50

Doesn't that exception indicate clojure itself hasn't been included in the jar?

quan10:05:54

I'm using lein uberjar with aot enable

eskos11:05:25

I have a need for backend WebSocket client library. Any recommendations? There seems to be multiple opinions online, but no definitive answer 🙂

Linus Ericsson12:05:22

Jetty has one. (Add: gniazdo is working, weve used it too)

hyankov12:05:50

We use https://github.com/stalefruits/gniazdo in production. Can't say it's the best thing out there but it gets the job done. Apart from a memory leak I had to deal when using custom low-level client - we haven't had issues with it.

👍 12
eskos13:05:53

Gniazdo seems to work fine for my use case, thanks! 👍

👍 4
roklenarcic12:05:16

does anyone have a templating library like yogthos/Selmer but with whitespace control? Template tags keep leaving up empty lines which breaks stuff for me.

dominicm15:05:11

@roklenarcic selmer doesn't insert any whitespace afaik. I usually have the opposite problem :) You might need to do something like {{A}}{{/A}}{{B}}{{/B}} to make sure whitespace does what you want.

roklenarcic16:05:11

It doesn’t add whitespace, but if you put if or for tags or endif or endfor tags in their own line for readability they will leave behind the empty line

dominicm16:05:53

Yeah, you have to put them on the same line

dominicm16:05:04

Most languages work that way

roklenarcic16:05:16

so then I stack so many tags into the same line to prevent empty newlines, that the line gets really really really long, which makes the template unreadable, which makes template pointless

roklenarcic16:05:33

in Jinja templates you can tell it to remove whitespace preceeding or succeeding the tag

roklenarcic16:05:06

Jinja templates being the Python library Selmer is based on

vlaaad19:05:24

Check this out! Newest version of #reveal (Read Eval Visualize Loop) seamlessly supports chart views for chartable data! And they are not just a picture, every data point can be explored further as a value!

👀 16
🆒 4
🎉 4
phronmophobic20:05:59

is there a screenshot of some of the chart stuff available?

phronmophobic20:05:33

oh whoops. didn’t realize the charts.gif wasn’t just the github auto image for the repo

p-himik20:05:45

That looks really nice. How do you plot the data, with cljfx?

vlaaad20:05:23

Yes, with cljfx

👍 4
markus06:05:08

Nice work vlaaad!

vlaaad06:05:47

Thanks 😊

naomarik20:05:29

Is this the fastest way to write something like this?

(persistent!
 (reduce
  (fn [acc itm]
    (assoc! acc itm itm))
  (transient {})
  (range 1e4)))

dpsutton20:05:49

i believe into does this for you under the hood?

naomarik20:05:54

This is just an example, my real case requires something like this, doing things in the reduce.

naomarik20:05:06

Incrementing a map of {<id> val} based on a set of ids.

Alex Miller (Clojure team)20:05:04

then yes, you're reducing over the source and doing amortized adds in batches via transient

naomarik20:05:41

Cool 🙂 Tried a bunch of different ways and found this to be much faster than everything else.

noisesmith20:05:50

transduce can be convenient here, as you can put the persistent! call into the completion arity

noisesmith20:05:13

but if breaking out part of the code into a transducer doesn't fit, reduce is fine

Alex Miller (Clojure team)20:05:34

and you'll do best if your source coll is something self-reducible (map, vector, few other things)

noisesmith20:05:49

range, like the example :D

Alex Miller (Clojure team)20:05:06

I was assuming that was for demo purposes :)

naomarik20:05:19

Yup was for demo purposes.

Alex Miller (Clojure team)20:05:32

importantly, NOT a seq if you can avoid it

noisesmith20:05:41

I just found it amusing that range is also one of the self-reducing inputs

Alex Miller (Clojure team)20:05:14

yeah, range, cycle, repeat, and iterate all self-reducible too

dpsutton20:05:53

self-reduce is IReduceInit or IReduce?

ghadi20:05:31

IReduceInit is the preferred interface

ghadi20:05:00

IReduce has the yucky signature that is missing the init arity

dpsutton20:05:20

yeah not a fan of that one.

ghadi20:05:54

there's also clojure.core.protocols/CollReduce (a protocol) if you don't control the class impl

seancorfield21:05:45

(a good opportunity to mention that next.jdbc/plan returns an IReduceInit 🙂 )