Fork me on GitHub
#clojure
<
2018-04-20
>
mkeathley02:04:33

Does anyone have any experience doing SAML 2.0 authentication and ADFS in clojure?

mkeathley02:04:16

I see this https://github.com/vlacs/saml20-clj but I don’t see how to fit the pieces together

qqq03:04:49

here is a design pattern I am running into. I have a

(try ... (catch ...) (finally ...))
block. I am writing code inside the try section. I want to automatically add a function to be called in both the catch & finally blocks, and have them executed in reverse order (of appearance in the try block).

qqq03:04:34

The context here is: I am doing a computation, I am allocating some resources, there may or may not be exceptions. Either way, I want to release these resources once we are out of the try block.

mfikes04:04:21

Sounds a lot like with-open

the2bears04:04:55

I'm not sure what you mean? Anything in the finally expression will get executed after both the try, or the exception blocks.

the2bears04:04:14

Not sure what you mean by "in reverse order"

mfikes04:04:54

It is fairly common to close resources in the reverse order from what they were opened

the2bears04:04:58

You want to release the resources in the reverse of allocating them I think?

mfikes04:04:49

I suspect you could generalize with-open, replacing .close with your own function

qqq04:04:02

with-open doesn't quite do what I want: it assumes that Ipm stuff things into a let block, and calling .close on it

qqq04:04:21

but I have code where I do a glAttachShader, then want to register a "glDetachShader" even though nothing is allocated

qqq04:04:52

@the2bears: you're right about catch/finally duplication ;I did not realize finally block code is auto executed by catch blocks too

the2bears04:04:01

A lot of experienced Java people miss that or forget that, so not to worry.

qqq04:04:16

My current best solution is:

(let [fns (atom [])]
   (try ...
     (swap! fns conj ....) ...
     (finally (doseq [f (reverse @fns)] (f)))

the2bears04:04:28

So what you sort of need is a construct that takes a list of resources that implement a 'allocate/deallocate' protocol, allocating in order during the try, then deallocating in reverse in the finally block

mfikes04:04:29

Yeah ^ that's what I used to write in Java

mfikes04:04:41

Perhaps you could write a with-shader macro, but then your code would end up being nested for each shader

caleb.macdonaldblack04:04:56

I’m threading the same function like this:

caleb.macdonaldblack04:04:14

I can use a reduce here like this:

caleb.macdonaldblack04:04:42

Is there a simpler way to do this? It feels like there would be

caleb.macdonaldblack04:04:35

I dont think that works on ->> and multiple argument functions require more work

the2bears04:04:47

The threading version is pretty readable and easy to follow.

the2bears04:04:14

Ah, but yeah, if it's the same function I see your point.

emccue07:04:54

@qqq This is polyfitting, but being lazy you can use @the2bears suggestion to have a 'allocate/deallocate' protocol

emccue07:04:44

skip the DI part of that noise for a moment

emccue07:04:28

pretend that is written

emccue07:04:51

basically with-open, but it works on a general component

emccue07:04:02

(reify Lifecycle (start [] ...) (stop [] ...))

emccue07:04:10

for the simplest case

emccue07:04:42

wrap it in a (make-component start stop) to reduce clutter

emccue07:04:55

might be a bit tricky since you need to return "self" as per the docs to be a proper component

emccue07:04:17

@qqq let me know what ends up working for you, I want to know how to solve this problem without going through the error part of trial and error that you will have to

sarna12:04:05

hey, do you guys still use gloss? why has it been archived?

Andreas Liljeqvist13:04:08

trying to generate a pom with clj. clj -Spom -A:dev fails, but clj -Spom -R:dev works.

Andreas Liljeqvist13:04:20

clj -A:dev works also

Andreas Liljeqvist13:04:45

Trying to understand why, even though -R is good enough

Alex Miller (Clojure team)14:04:53

are you on latest version?

Alex Miller (Clojure team)14:04:40

does clj -Sverbose report version 1.9.0.375 ?

Alex Miller (Clojure team)14:04:44

I think this was actually fixed in the latest version

Alex Miller (Clojure team)14:04:49

-Spom is a totally different code path. It’s goal is to build a pom with top-level libs in it, not to build a classpath. So it doesn’t do all the same modifications that aliases do when they resolve-libs and build-classpath. It does try to apply some modifications like :extra-deps and :override-deps on the top-level libs, but these are done via different code entirely.

Andreas Liljeqvist14:04:45

.358, will try new version later

Alex Miller (Clojure team)15:04:26

yeah, the -A aliases were being ignored during -Spom before and that was fixed in 375

Andreas Liljeqvist14:04:04

I have extra deps in an alias that I want in pom

Alex Miller (Clojure team)14:04:16

that’s ok - those should be added

Alex Miller (Clojure team)14:04:23

assuming you’re using :extra-deps

emccue15:04:26

@qqq here is the non handwavey version

emccue15:04:16

Lifecycle is copied from component, with-component is just a slightly modified with-open

qqq15:04:32

haskell has xmonad; is there any window manager written in Clojure ?

bronsa15:04:02

there’s stumpwm which is in common lisp

Alex Miller (Clojure team)15:04:20

I think Rich is working on that

dominicm15:04:39

prepl purpose revealed

Alex Miller (Clojure team)15:04:17

sorry, I’m about 19 days behind

bronsa15:04:18

I think this is the first rickroll I didn’t see coming

8
Alex Miller (Clojure team)15:04:38

I don’t troll often…. but when I do…

sveri15:04:55

Thank god I live in germany. The video is not available here. For once and for all our almighty ruler, the content industry, has saved me 😄

Alex Miller (Clojure team)15:04:27

Here I’ll sing it for you…

emccue15:04:37

I got an ad before, which ruined it

pablore16:04:48

Whats is the state of clojurescript on nodejs? I want to do some system scripting but clojure startup time is too slow

john16:04:17

There's a control for rickroll in the GDPR

john16:04:52

@pablore people are doing it, I believe. Planck and Lumo are good entry points, but the latest cljs.main work makes it pretty easy to launch a nodejs process as well.

pablore16:04:23

@john great! I’ll take a shot at lumo.

Sallide16:04:20

Hi all, I'm just starting a basic server using http-kit. It looks like even when the server's just idling the heap size increases; is this normal? I don't have much experience with java outside of school homework

devn16:04:14

the thing about the people in the clojure community that really sets it apart is that in all of my time being a part of it, no one has ever given up on me or let me down. it's not the kind of community where people run around and hurt one another.

devn16:04:55

thanks @alexmiller for setting such a great example

joelsanchez17:04:37

that's so mean @bronsa consider yourself banned (although maybe not as mean as subtly rickrolling everyone in here)

seancorfield17:04:38

@squarenegative Yes, that's pretty normal. We have processes that, even when they're completely idle, show a sawtooth graph in memory usage. When the heap gets 70-80% full, you'll see a full GC (so heap usage drops, but overall system memory will not -- the JVM doesn't return memory to the host in general).

seancorfield17:04:27

When a process is getting a lot of activity, it'll also do GC more often. And it'll also depend on which GC you're using. We use the G1 collector for, in theory, more consistent response times in a web app. For a very active process, the GC will be nearly continuous and you'll see heap usage going up and down a lot but in a much smaller window, often in the 40-60% range.

Sallide17:04:58

yeah, I was just testing using g1 and it seemed the heap size increased much more slowly

Sallide17:04:00

great, thank you

seancorfield17:04:37

(it's an http-kit REST API)

orestis17:04:40

@seancorfield What do you use for getting those metrics and generating the graphs?

seancorfield18:04:15

New Relic. We love it! I blogged about how to add trace annotations to Clojure code, and also some stuff about startup time... https://www.google.com/search?q=site%3Aseancorfield.github.io&amp;q=new+relic (should be top two results)

👍 4
Sallide17:04:42

@seancorfield awesome, thank you very much

Garrett Hopper17:04:03

Is there a way to destructure namespaced keywords automatically with the current namespace?

(let [{:keys [without.this.namespace/a without.this.namespace/b]} {::a 1 ::b 2}]
  [a b])

sundarj17:04:45

use ::keys

Garrett Hopper18:04:18

Awesome, thanks! Could we get this documented at https://clojure.org/guides/destructuring?

Alex Miller (Clojure team)18:04:45

it’s documented in the reference page

Alex Miller (Clojure team)18:04:31

actually, maybe it’s not

Garrett Hopper18:04:03

Yeah, I'd looked there too.

Alex Miller (Clojure team)18:04:13

oh…. I wrote a whole updated section for this page

Alex Miller (Clojure team)18:04:30

and never got it finalized with Rich

Alex Miller (Clojure team)18:04:46

wow, I wonder where I put that :)

seancorfield18:04:15

New Relic. We love it! I blogged about how to add trace annotations to Clojure code, and also some stuff about startup time... https://www.google.com/search?q=site%3Aseancorfield.github.io&amp;q=new+relic (should be top two results)

👍 4
Sallide18:04:09

what does it offer over jvisualvm?

seancorfield18:04:49

New Relic monitors all sorts of stuff, not just memory/heap. It can show you performance of database queries etc, response times for the web apps (although http-kit is not fully supported so you don't get full web app monitoring), and external calls (e.g., to payment gateways etc).

seancorfield18:04:03

We also have it monitoring our background processes and tracking metrics in those (I need to write up how that's done -- mostly you start a thread with the New Relic agent and tell it which function to call for "probing" your app, and you track metrics and send them to NR in that function).

seancorfield18:04:58

It can also monitor servers: disk, CPU, RAM, I/O, availability. You can also tag deployments from your build script and so New Relic can track performance comparatively for each new deployed build.

Sallide18:04:07

sounds pretty cool

seancorfield18:04:31

It also has JS you can use to instrument the front end of your apps. It's pretty comprehensive as a monitoring/health system.

theeternalpulse18:04:28

is there a good library to help with repl debugging, such as viewing local values and such?

Garrett Hopper18:04:42

@U61HA86AG That's really cool; thanks.

Garrett Hopper19:04:00

I have seen that. I keep meaning to look into it more.

theeternalpulse19:04:59

@seancorfield for a boot.profile is middleware the plugin equivalent?

seancorfield19:04:10

This is REPL middleware (I assume you're talking about Sayid) so it's specific to using a REPL, regardless of Boot/Leiningen.

theeternalpulse20:04:11

I guess I was referring to these instructions

{:user {:plugins [[cider/cider-nrepl "0.14.0"]
                   [com.billpiel/sayid "0.0.16"]]
         :dependencies [[org.clojure/tools.nrepl "0.2.12"]]}}
are specific to lein's profile.clj

theeternalpulse20:04:39

wasn't sure the boot.profile equivalent to the plugins section

seancorfield05:04:23

@U1CUUKHDL Ah, sorry. I haven't used Leiningen for a long time. That's not what I was expecting to see from Sayid, when I read its site and it talked about REPL middleware 😐 I sort of remember some other configuration that's needed for REPL middleware. Pretty sure, in Boot, all you need is to add those dependencies.

seancorfield05:04:49

I would expect to see some configuration for the REPL itself that installs the REPL middleware... but maybe it installs itself automatically...?

huthayfa20:04:07

are there any performance downsides of using multimethods (defmulti )

huthayfa20:04:20

can it be used in all use cases wherever the polymorphism needed?

jjttjj21:04:41

@huthayfa.ainqawi performance is the major tradeoff in choosing multimethods over protocol based dispatch, so yes

jjttjj21:04:42

it maybe be that this is a negligible performance hit on your overall program though, it really depends

huthayfa21:04:02

is there any other ways to choose between different implementations without using protocols, multimethods or cond ?

joelsanchez22:04:54

a map 🙂

👍 8
arrdem22:04:16

these things are all variously implementations of single mappings trollface

arrdem22:04:28

except for multimethods with hierarchies.