This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-20
Channels
- # adventofcode (7)
- # announcements (1)
- # aws (1)
- # babashka (127)
- # bangalore-clj (1)
- # beginners (54)
- # calva (8)
- # cider (12)
- # clj-http (2)
- # clj-kondo (8)
- # cljdoc (10)
- # cljs-dev (2)
- # clojure (48)
- # clojure-australia (14)
- # clojure-dev (6)
- # clojure-europe (105)
- # clojure-nl (6)
- # clojure-taiwan (1)
- # clojure-uk (62)
- # clojurebridge (1)
- # clojurescript (112)
- # code-reviews (4)
- # cursive (20)
- # data-science (1)
- # depstar (1)
- # events (8)
- # fulcro (6)
- # graalvm (11)
- # honeysql (2)
- # introduce-yourself (3)
- # jobs (1)
- # jobs-discuss (30)
- # malli (23)
- # nrepl (4)
- # off-topic (47)
- # pedestal (22)
- # polylith (10)
- # portal (3)
- # re-frame (16)
- # reitit (9)
- # releases (3)
- # rewrite-clj (1)
- # ring (1)
- # spacemacs (1)
- # tools-deps (12)
- # xtdb (7)
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])
(pprint)
(with-out-str))
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.
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}}
.
Leveraging clojure.data/diff
@U0L91U7A8 playing around with diffs a few weeks ago paid off? 😄
I have a more involved one here: https://github.com/clj-kondo/clj-kondo/blob/4f1252748b128da6ea23033f14b2bec8662dc5fd/test/clj_kondo/test_utils.clj#L15 which also treats strings as "sub-things" of regexes
Actually, it was more a few months ago when I create this online EDN diff tool leveraging self-hosted ClojureScript https://blog.klipse.tech/clojure/2020/10/08/edn-diff.html
@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.
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?) 🙏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...
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.
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)
Cheat
(alter-meta!
#'clojure.core/count
assoc
:inline
(fn [x]
(if (or (vector? x) (string? x))
(. clojure.lang.RT (count x))
`(. clojure.lang.RT (count ~x)))))
Thank you all!
@UK0810AQ2 could you be so kind and explain a little how will :inline be used?
@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
@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 http://clojure.org 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 https://github.com/clojure/clojure/blob/master/changes.md#215-const-defs . 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 https://github.com/dakrone/clj-http#logging.
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.
it seems clj-http accepts middleware: https://github.com/dakrone/clj-http#custom-middleware
@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