Fork me on GitHub

has anybody succeded in using lacinia-graphql on top of ring server? I’m thinking of routing requests to /graphql to lacinia, while keeping all the other RESTful requests working as usual.


I want to convert a map containing some SAML assertions to an EDN-string. Currently doing this to get nice-looking output:

(-> (get-in req [:session :saml :assertions])
However, the map contains a Java instant and that comes out looking like
:not-on-or-after #object[java.time.Instant 0x4f69adf "2021-05-20T07:48:00Z"]
and I would like it to be a string without the Clojure/JVM-specific extra garbage. How do I do this? Also, would love to keep it pretty-printed.


That worked great! Thank you so much, @U4ZDX466T.


Glad to hear it.


What’s a smart way to implement a submap? fn to compare two maps, taking into account subsets inside the map too? E.g. {:a {:b #{:c}} should be a valid submap of {:a {:b #{:c :d}} .

Yehonathan Sharvit10:05:57

(defn submap [a b]
  (nil? (first ( a b)))

🙏 2
💥 2
Yehonathan Sharvit10:05:09



That was incredibly succinct! WOW.


Wonder how that would look like in Java 😜

Ben Sless11:05:42

@U0L91U7A8 playing around with diffs a few weeks ago paid off? 😄


I have a more involved one here: which also treats strings as "sub-things" of regexes

👍 2
Yehonathan Sharvit11:05:31

Actually, it was more a few months ago when I create this online EDN diff tool leveraging self-hosted ClojureScript


@U04V15CAJ That seems very useful. I think I will stick with the more succinct solution, but keep yours in mind if I end up needing to support regexes.


has a ton of stuff in this ballpark

Jakub Holý (HolyJak)11:05:12

Is there a way to hint the JIT to replace a fn call with its result? Namely the count call in

(subs "Bearer xyz" (count "Bearer "))
I like the code because it is much clearer than the alternative (subs "Bearer xyz" 7) yet I do not want to have to count the length of the string upon every invocation. (Or perhaps I am worrying too much and Java will make "Bearer " into a static string with its length known so that the whole thing will end up as a single, cheap memory access on every execution?) 🙏


(defmacro embed [form]
  (eval form))


And then

(embed (count "Bearer "))

Jakub Holý (HolyJak)12:05:33

Thank you! But I would prefer a solution not involving a new macro 🙂 Something line ^:static if it exists/applies here. Or to hear that it is not an issue b/c JIT is smart enough...


possibly you can also use a data reader for this


#holyjak/inline (count "Bearer")


but honestly a macro isn't a bad idea either

☝️ 2

This sounds a good case for (def ^:const Bearer (count "Bearer")) and (subs "Bearer xyz" Bearer)


> possibly you can also use a data reader for this In that case #=(count "Bearer ") would even work (although #= is not public api iirc). To be honest; unless this is running in a tight loop i wouldn't worry too much about it.

👍 2

let the JIT deal with it

☝️ 4
👍 2

I don't like the "the JIT will solve it" argument. If you can write efficient code with little effort, I would prefer that over some other tool to solve the slowness (which may not even work in all targets)


premature optimization...


How about regex:

(some->> bearer
           (re-find #"((?i)bearer[\s]+)(.*)$")

Ben Sless17:05:53


 (fn [x]
   (if (or (vector? x) (string? x))
     (. clojure.lang.RT (count x))
     `(. clojure.lang.RT (count ~x)))))

Jakub Holý (HolyJak)17:05:10

@UK0810AQ2 could you be so kind and explain a little how will :inline be used?

Ben Sless17:05:14

@U0522TWDA at macro expansion time, if a function has :inline key it will be called like a macro on the call site. Lets functions behave like macros some of the time. You can (ab)use it

❤️ 2

Don’t use it :)

👍 2

@U054W022G’s solution is simple and intuitive. I'd remove ^:const though as it isn't exactly a public feature (it's not advertised in I think) I'd simply configure direct-linking in production - it's equivalent. That way one uses supported features, and ^:const won't get in your way while developing (it can interfere with a repl workflow among other things)


Yeah not that public but not even that private . It’s not that equivalent to direct-linking as the call to count would happen everytime (it just removes the var indirection). And true, ^:const should be used only on computations that can happen at compile time. However, do not confuse that with defonce (which is probably even more problematic when reloading).


Is there a way to intercept all the calls happens via clj-http? Without touching each call individually?


clj-http uses the Apache HttpComponent client, which can log all outgoing calls using log4j2. See Using Logback, to enable logging of outgoing requests add this to logback.xml: <logger name="org.apache.http.wire" level="debug"/>


You can even change it runtime:

(.. (org.slf4j.LoggerFactory/getLogger "org.apache.http.wire")
    (setLevel (ch.qos.logback.classic.Level/DEBUG)))


if clj-http doesn't have a built-in way to do it, you could try monkey-patching (if this is for debugging purposes)


No, it’s not for debugging purposes, I need request details for all outgoing request via it.


the probably make you own wrapper, if clj-http doesn't support it

👍 2

you could probably use this


@US3UEE2VB I'm not sure where your application is in the development process, I would suggest passing in an http client into your application as an argument, rather than intercepting outgoing calls

💯 2

the argument might just be a plain fn that takes a request map and returns a response map


that avoids the mocking/stubbing problem by design