beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
solf 2021-02-02T00:50:35.351200Z

Yeah, trying out doom-themes has been in my backlog for a long time 🙂 A few years ago I had a emacs "theme bankrupcy", I removed all my aesthetic customizations and I'm now running the default light theme 😅

Christian 2021-02-02T14:11:19.367100Z

I want to call several Java methods and:

((juxt #(.getYear %) #(.getMonthValue %) #(.getDayOfMonth %) )
does the job, but it doenst look pretty. Is there a shorcut for this like the ..?
((juxt .getYear .getMonthValue .getDayOfMont))
Will not compile, because these are not clojure functions, right?

bronsa 2021-02-02T14:17:24.367700Z

right, you can use memfn but it's not worth it IMO

bronsa 2021-02-02T14:17:31.367900Z

#() is your best choice

Christian 2021-02-02T14:20:56.369700Z

If I had a lot of code that calls juxt with java methods, would this be a valid reason to write a macro that behaves like the original juxt?

Mno 2021-02-02T14:21:18.370200Z

well you don’t need to make a macro… I think

Christian 2021-02-02T14:21:19.370300Z

Or is it possible to do that with a function?

Mno 2021-02-02T14:23:03.372100Z

(defn javajuxt [& fns]
  (apply juxt (map memfn fns))]))

Mno 2021-02-02T14:23:51.373Z

I have no idea if that’ll work 😅

2021-02-02T14:23:55.373200Z

memfn is a macro, so it wouldn’t work in combination with map

Mno 2021-02-02T14:24:28.374Z

aaah.. ok that won’t work then.

alexmiller 2021-02-02T14:27:57.375Z

you have to be a little careful around this kind of thing to avoid reflection

alexmiller 2021-02-02T14:28:19.375400Z

but really, it's probably the most straightforward to just do what you're doing

bronsa 2021-02-02T14:29:16.376500Z

it'd have to be a macro since .foo is not a first class thing but it's syntax

bronsa 2021-02-02T14:29:32.377Z

but... really #() is not bad :)

2021-02-02T14:29:50.377300Z

you could also make a dedicated namespace for function that suppose to deal with some specific Java classes.

Mno 2021-02-02T14:30:03.377700Z

if you really dislike it would wrapping the ones that you use a lot with clojure fns work? (defn get-year [obj] (.getYear obj))

alexmiller 2021-02-02T14:31:19.378600Z

people have written wrappers that do this kind of thing across big chunks of api but you're just adding layers and layers have cost

Mno 2021-02-02T14:32:15.379300Z

Cool, that’s good to keep in mind. Thanks!

2021-02-02T14:36:07.382900Z

Hello fellow Clojure beginners! I wanted to drop a line in this channel real quick and let you know that I'm doing daily Clojure coding livestreams over on my Twitch channel: https://www.twitch.tv/a_fry_ I'm embarking on an ambitious project this year: 12 startups in 12 months. Each month I'm going to build and release a startup MVP from start to finish, all in Clojure and ClojureScript. I'm now officially in Month Two of the project, which means I'm in month two of learning how to code in Clojure! It's been a trip so far, but I think I'm catching on to the rudiments of the language fairly well. I start each morning with a 30-minute warmup, so if you want to watch a fellow beginner bungle through a coding challenge or two and learn how the language works, you can join me every weekday at 9:30 AM EST. I've also got a back-catalog of livestreams over on Youtube (although I only started the morning warmup segment last week: https://www.youtube.com/channel/UCkDn7Pnyeq3SJha1x3GXTkQ). Cheers ƛ

souenzzo 2021-02-02T15:06:40.383200Z

- clojure.core/bean - https://github.com/clojure/java.data

Mno 2021-02-02T16:02:04.383500Z

today I learned what a Java Bean is. Thanks dude.

haywood 2021-02-02T16:12:35.384600Z

anyone familiar with how to deal with calling io/resource on a resource directory?

haywood 2021-02-02T16:13:27.385300Z

closest I’ve come is doing (io/file (str (io/resourece "path")))

haywood 2021-02-02T16:14:02.386Z

but the str call returns a path prefixed with file: that io/file doesn’t like, I could regex that bit out of the string but that seems bad

dpsutton 2021-02-02T16:16:20.387100Z

ignore all code and say what you want to happen. "i want to get all the files in my resources directory", "i need the edn from resources/foo.edn" or something like that

haywood 2021-02-02T16:18:25.389100Z

right on, you nailed it really “i want to get all the files in a resources sub-directory”

teachtyler 2021-02-02T16:19:16.389700Z

🌊👋 I'm new to cljs, so i've been working on a template fork for others and myself down the road, that is currently in a protect-your-eyes state, so any feedback would be appreciated 😅 https://github.com/teachtyler/Fraction

dpsutton 2021-02-02T16:27:11.391400Z

i'm not finding any good way to do this. I believe just like java packages, in a jar there is no hierarchy or container. just "addresses" that share a prefix. "resources/foo/bar" and "resources/foo/quux". we can "see" a hierarchy but there's no node containing the two

alexmiller 2021-02-02T16:27:25.391700Z

directories are not a resource thing, they're a file thing

haywood 2021-02-02T16:27:57.392200Z

the resource returns the path which is really all I need, but it’s got this file: prefix which I can just remove

haywood 2021-02-02T16:28:16.392500Z

io/file doesn’t like that type of file url

alexmiller 2021-02-02T16:28:53.392800Z

you pass the path to resource - why use resource at all?

alexmiller 2021-02-02T16:29:34.393400Z

resources are a generic feature and classloaders can provide them from an open set of "places"

haywood 2021-02-02T16:29:37.393600Z

I only know the path relative to the resources directory, so I pass the relative path to io/resource

haywood 2021-02-02T16:30:06.394300Z

using io/resource shields the differences between my local machine and the jar in a docker image

alexmiller 2021-02-02T16:30:26.394700Z

it does, but you give up the concept of directories or "all things in a directory"

alexmiller 2021-02-02T16:30:49.395300Z

you just have resources, which have paths, no notion of resource container

alexmiller 2021-02-02T16:31:26.396Z

you're loading resources from the classpath, which includes all the jars as well

dpsutton 2021-02-02T16:36:17.397700Z

if you know you'll have files, use just a path to make files. If you lose the filesystem because of packaging into a jar, <http://clojure.java.io/resource|clojure.java.io/resource> returns a url which is handy as well: (slurp (io/resource "my-thing")) will yield the contents of the file

Daniel Stephens 2021-02-02T16:41:57.397800Z

looks interesting, good luck!

2021-02-02T17:06:50.398Z

Welp, the stream crashed halfway through 😬 But at any rate, if you're interested in joining hopefully it'll behave next time!

Daniel Stephens 2021-02-02T17:37:48.398200Z

👍 will try to pop in, interested to see what ideas you come up with!

caumond 2021-02-02T20:53:41.402200Z

Hi guys, I want to use reveal with leiningen, and for me it was not straightforward. As I'm not a leiningen expert, could you all check my proposal to @vlaaad. Reveal need to launch a repl function, I used the :repl-options { :init ...} option . @vlaaad, I did not find how to contribute directly to your website, a few lines in that readme I suggest you add in your tutorial: https://gitlab.com/caumond/reveal-lein-tuto

2021-02-02T21:14:00.402400Z

There is #reveal :)

caumond 2021-02-02T21:14:29.402600Z

Lol, a REVEALation !

Mario C. 2021-02-02T21:25:08.403300Z

I am trying to add web-sockets into an application I am working on.  My general understanding of WS is that Client A establishes a connection to Server A and they can send messages to each other. The issue I am seeing with this type of architecture is that we have multiple stateless servers.  So if Server B receives a request to process some information, that Client A is expecting to get a notification via WS, how will Server B Push out a message to Client A if Server B has no connection with Client A.  Sticky sessions doesn’t seem like the solution since its another system that is making requests to our API which would trigger a notification message sent to the connected client. And any node can potentially receive that request.  Is there a way a server can ask “Hey, who is connected to client Y?” And then have the server that responds with “Hey, I am connected to that client!” Send out the notification via WS?

seancorfield 2021-02-02T21:30:06.403400Z

@caumond FYI, https://github.com/vlaaad/vlaaad.github.io is the website repo (in general, you'll find <username>/<username>.http://github.io is the repo behind any github-hosted website.

👍 1
dpsutton 2021-02-02T21:31:12.404700Z

did that at the last job. broadcast to the nodes please let user zzz know this message. one (and only one) of them had a connection open and fulfilled it. the rest looked, saw that client wasn't connected and just kept humming

caumond 2021-02-02T21:32:06.405100Z

Cool, I'll suggest a direct contribution then !

seancorfield 2021-02-02T21:32:30.405300Z

This is the file that contains the source of all the Reveal information I think https://github.com/vlaaad/vlaaad.github.io/blob/master/reveal.md

Mario C. 2021-02-02T21:36:15.405700Z

Do you have any links for this sort of thing? I am guessing this would require setting up some sort of messaging passing service or can this be done with pure clojure?

dpsutton 2021-02-02T21:37:56.406Z

yeah i was assuming your machines already had some queue they could all talk to. if so its pretty trivial. there's an atom of connected clients and a message of who to send to

dpsutton 2021-02-02T21:38:05.406200Z

if no queue already you've got some plumbing to do

dgb23 2021-02-02T21:38:07.406400Z

Likely a dumb question, but is it feasible to have a dedicated websocket node as a proxy?

dgb23 2021-02-02T21:38:22.406600Z

(in your situation)

Mario C. 2021-02-02T21:41:50.406800Z

No there is no queue set up at the moment. As far as a dedicated ws node, Im not familiar with that so I can't say to be honest. How would that work? Would the load balancer see that a client is trying to make a WS connection and then route the request to the dedicated server?

Mario C. 2021-02-02T21:42:57.407300Z

Seems like at the end of the day it would sort of be the same situation, Some Node would need to send a message to the dedicated node. But honestly im not sure

vlaaad 2021-02-02T21:43:47.408Z

sounds about right 🙂

2021-02-02T21:44:21.408200Z

Could rabbit mq work for you here? We have agents at my work that sit connected to rmq. Can send a message to a particular machine or many machines. You just need to setup your routing keys appropriately. If a machine is offline its messages will sit in its queue ready to be picked up when it reconnects.

dgb23 2021-02-02T21:46:36.408600Z

I have to say I don’t quite have a complete picture in my mind. But it seems like you want a queue like the others suggested, since your services are behind a load balancer and you need some way to coordinate messages.

sb 2021-02-02T21:55:05.409500Z

(def custom-formatter (tf/formatter "yyyyMMddHHmm"))
  (l/to-local-date-time (tf/parse custom-formatter "202011141555")) &gt;&gt; works
  ; "Jul 12, 2020, 5:03:24 PM GMT+2"
  (def custom-eg-google (tf/formatter "MM dd, yyyy, hh:mm:ss aa zz"))
  (tf/parse custom-eg-google  "Jul 12, 2020, 5:03:24 PM GMT+2") &gt;&gt; not valid

sb 2021-02-02T21:55:32.410100Z

What do I wrong with clj-time? at custom formatter “”MM dd, yyyy, hh:mm:ss aa zz”

2021-02-02T21:58:03.410700Z

I would expect something around the timezone maybe. But thats a guess at best

Mario C. 2021-02-02T21:58:15.410900Z

Yea it looks like a message queue will be needed to accomplish this

Mario C. 2021-02-02T21:58:23.411300Z

thanks guys

sb 2021-02-02T21:59:07.412100Z

Yes, i tried in several way. I read yoda time documentation about, but not clear (no example for this case).

2021-02-02T22:01:55.412800Z

My eye fell on this piece of doc of Joda: > Zone names: Time zone names (‘z’) cannot be parsed. (Here: https://www.joda.org/joda-time/key_format.html )

👍 1
sb 2021-02-02T22:05:58.413700Z

I found a few example on the Github [not exact but good starter points], maybe first I check before I drop here the question.

sb 2021-02-02T22:06:11.413800Z

Yes, I read that before I post here.

seancorfield 2021-02-02T22:53:53.414900Z

@sb Joda Time and clj-time are both deprecated, in favor of using Java Time (and, possibly, a Clojure wrapper library). Just FYI.

👍 1
sb 2021-02-02T22:56:57.415Z

Thanks the information! 👍 I don’t know that..

2021-02-02T23:18:49.415500Z

since this is fire and forget, a distributed log / event system (which can be simpler than a queue) would work too

🎯 1
seancorfield 2021-02-02T23:21:26.415700Z

The clj-time README talks about it and recommends some modern wrappers for Java Time to use instead.

👍 2