Fork me on GitHub
#beginners
<
2021-02-02
>
Christian14:02:19

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?

delaguardo14:02:50

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

bronsa14:02:24

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

bronsa14:02:31

#() is your best choice

Christian14:02:56

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?

Mno14:02:18

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

Christian14:02:19

Or is it possible to do that with a function?

Mno14:02:03

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

Mno14:02:51

I have no idea if that’ll work 😅

delaguardo14:02:55

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

Mno14:02:28

aaah.. ok that won’t work then.

alexmiller14:02:57

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

alexmiller14:02:19

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

bronsa14:02:16

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

bronsa14:02:32

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

Mno14:02:03

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

alexmiller14:02:19

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

Mno14:02:15

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

Mno16:02:04

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

afry14:02:07

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 ƛ

Daniel Stephens16:02:57

looks interesting, good luck!

afry17:02:50

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

Daniel Stephens17:02:48

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

sova-soars-the-sora05:02:26

hey I noticed when you started this, I think I got wind of it via the reddit/clojure channel... Love the ambition. Glad you're doing it and streaming it! 😃

haywood16:02:35

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

haywood16:02:27

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

haywood16:02:02

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

dpsutton16:02:20

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

haywood16:02:25

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

alexmiller16:02:26

this is not a thing you can generically do with resources

teachtyler16:02:16

🌊👋 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

alexmiller16:02:26

this is not a thing you can generically do with resources

dpsutton16:02:11

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

alexmiller16:02:25

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

haywood16:02:57

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

haywood16:02:16

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

alexmiller16:02:53

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

alexmiller16:02:34

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

haywood16:02:37

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

haywood16:02:06

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

alexmiller16:02:26

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

alexmiller16:02:49

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

alexmiller16:02:26

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

dpsutton16:02:17

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, returns a url which is handy as well: (slurp (io/resource "my-thing")) will yield the contents of the file

caumond20:02:41

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

Stuart21:02:00

There is #reveal :)

caumond21:02:29

Lol, a REVEALation !

seancorfield21:02:06

@U018QDQGZ9Q 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
caumond21:02:06

Cool, I'll suggest a direct contribution then !

seancorfield21:02:30

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

vlaaad21:02:47

sounds about right 🙂

Mario C.21:02:08

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?

dpsutton21:02:12

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

Mario C.21:02:15

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?

dpsutton21:02:56

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

dpsutton21:02:05

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

dgb2321:02:07

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

dgb2321:02:22

(in your situation)

Mario C.21:02:50

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.21:02:57

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

Stuart21:02:21

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.

dgb2321:02:36

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.

Mario C.21:02:15

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

Mario C.21:02:23

thanks guys

noisesmith23:02:49

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

🎯 1
sb21:02:05

(def custom-formatter (tf/formatter "yyyyMMddHHmm"))
  (l/to-local-date-time (tf/parse custom-formatter "202011141555")) >> 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") >> not valid

sb21:02:32

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

Lennart Buit21:02:03

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

sb21:02:07

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

Lennart Buit22:02:55

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
sb22:02:11

Yes, I read that before I post here.

sb22:02:58

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

seancorfield22:02:53

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

👍 1
sb22:02:57

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

seancorfield23:02:26

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

👍 2
sb02:02:43

Yes, this is little bit painful. I solved without clj-time.. (I hope tick will have better documentation later.)

sova-soars-the-sora04:02:00

clj-time is so cool though... ;_;

seancorfield05:02:30

@U3ES97LAC Seriously? I mean, I'm one of the maintainers and I don't think there's anything "cool" about it...

sova-soars-the-sora05:02:35

yes i think it's awesome ... but the latest state-of-the-art recommendation is to use java-time via interop?

👍 1
seancorfield05:02:12

Or cljc.java-time or tick (although we use clojure.java-time at work because it was available first). Mostly we use interop.