clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
Aron 2021-05-20T02:19:26.102900Z

@em not 100% sure which "blocking aspect" you mean. 'block' in the blockchain is not about blocking. πŸ™‚

Aron 2021-05-20T02:42:55.103400Z

@thegobinath I am saying blockchain is not good for general solutions because the whole point of blockchain systems is that there is a distributed ledger that can be used anyone on the network. The overhead of building a system that uses such a ledger and integrates it with the rest of the company is huge, if after adopting such a system you still have to develop another custom solution, it will be wasteful for everyone using the network. It makes much more sense for any solution, that uses blockchain datastructures to provide auditability, to be built as lightweight as possible to keep the costs of transactions down. That's the physical argument, it's simply more effective (less cost, less risk, less time consumed) in the end to not have any superfluous incidental complexity. The other side is about time. Blockchain, as the name says, progresses link by link, one block built on the previous one. Please note that this is definedly not how actual distributed systems work. A truly distributed system functions distributed in space AND in time. Transactions in Timbuktu don't have to wait for transactions in Vanuatu to finish. I am oversimplifying because it's less about waiting for others than stepping in unison, but the picture is more or less the same: your local transaction depends on the global system, not the other way around. This provides strong automatic tools to handle failures, but it's costly. Because of this limitation, blockchains either are slow or require additional tricks to speed them up to anything that would be useful in a modern economic setting. I can go on, but I think I stop here and see if what I wrote so far makes sense for you πŸ™‚

2021-05-20T03:41:00.103900Z

β€’ The main selling point of eth is that blockchain can have a broader and general scope than just crypto - as implemented in its source idea: bitcoin β€’ It even came with the latest buzz: "world computer" or the "internet computer" β€’ The holistic concept of a open and decentralised web (web 3.0)which includes cryptocurrencies but also websites, apps or basically most kind of software. β€’ couple of other examples are http://onflow.org and http://dfinity.org which are implementing blockchains and http://radicle.xyz which is implementing ethereum for peer to peer software versioning and collaboration like GitHub, http://status.im which is implementing ethereum for messaging and there are few which shows that the main selling point of ethereum is actually viable. β€’ So in your point of view, how these ideas and projects hold any real value in terms of what they are promising?

2021-05-20T04:41:56.104700Z

(scoffs, offended he was never offered a bribe. I won't TAKE one to vote on a Clojure issue I do not care about, but just the fact that you didn't think to try bribing me πŸ™‚

2021-05-20T07:17:56.107800Z

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.

simongray 2021-05-20T07:53:49.109400Z

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.

flowthing 2021-05-20T08:13:53.109700Z

https://github.com/henryw374/time-literals maybe?

simongray 2021-05-20T10:00:41.111Z

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

flowthing 2021-05-20T10:01:03.111200Z

Glad to hear it.

simongray 2021-05-20T10:17:14.113200Z

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 Sharvit 2021-05-20T10:38:57.113800Z

(defn submap [a b]
  (nil? (first (clojure.data/diff a b)))

πŸ’₯ 1
πŸ™ 1
βœ… 2
Yehonathan Sharvit 2021-05-20T10:39:09.114Z

Leveraging clojure.data/diff

simongray 2021-05-20T10:53:27.114800Z

That was incredibly succinct! WOW.

raspasov 2021-05-20T11:10:54.115400Z

Wonder how that would look like in Java 😜

Ben Sless 2021-05-20T11:23:42.115600Z

@viebel playing around with diffs a few weeks ago paid off? πŸ˜„

borkdude 2021-05-20T11:26:56.117200Z

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

πŸ‘ 1
Yehonathan Sharvit 2021-05-20T11:27:31.118200Z

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

Jakub HolΓ½ 2021-05-20T11:29:12.119500Z

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?) πŸ™

vemv 2021-05-21T10:37:13.135700Z

@reborg’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)

reborg 2021-05-21T13:00:45.146Z

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).

simongray 2021-05-20T11:33:53.119700Z

@borkdude 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.

p-himik 2021-05-20T11:34:08.119900Z

(defmacro embed [form]
  (eval form))

p-himik 2021-05-20T11:34:33.120100Z

And then

(embed (count "Bearer "))

Jakub HolΓ½ 2021-05-20T12:02:33.120400Z

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...

borkdude 2021-05-20T12:03:44.120600Z

possibly you can also use a data reader for this

borkdude 2021-05-20T12:04:04.120800Z

#holyjak/inline (count "Bearer")

borkdude 2021-05-20T12:04:16.121Z

but honestly a macro isn't a bad idea either

☝️ 1
reborg 2021-05-20T12:38:24.121600Z

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

βž• 1
svt 2021-05-20T12:44:12.122400Z

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

borkdude 2021-05-20T12:45:36.123Z

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

svt 2021-05-20T12:46:42.123200Z

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

borkdude 2021-05-20T12:47:47.123400Z

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

πŸ‘ 1
borkdude 2021-05-20T12:49:32.123700Z

it seems clj-http accepts middleware: https://github.com/dakrone/clj-http#custom-middleware

borkdude 2021-05-20T12:49:43.124100Z

you could probably use this

2021-05-20T13:23:57.124300Z

> 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.

πŸ‘ 1
ghadi 2021-05-20T13:27:42.124700Z

https://github.com/nubank/matcher-combinators/

πŸ‘ 2
ghadi 2021-05-20T13:27:49.124900Z

has a ton of stuff in this ballpark

ghadi 2021-05-20T13:28:37.125100Z

let the JIT deal with it

πŸ‘ 1
☝️ 2
borkdude 2021-05-20T13:30:33.125400Z

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)

ghadi 2021-05-20T13:30:43.125600Z

premature optimization...

Thuan 2021-05-20T13:34:20.125900Z

How about regex:

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

ghadi 2021-05-20T16:28:02.130300Z

@cksharma122 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

πŸ’― 1
ghadi 2021-05-20T16:28:26.130500Z

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

ghadi 2021-05-20T16:29:02.130700Z

that avoids the mocking/stubbing problem by design

Ben Sless 2021-05-20T17:19:53.131100Z

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)))))

Jakub HolΓ½ 2021-05-20T17:31:09.131500Z

Thank you all!

Jakub HolΓ½ 2021-05-20T17:32:10.131700Z

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

Ben Sless 2021-05-20T17:35:14.131900Z

@holyjak 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

❀️ 1
ghadi 2021-05-20T17:57:46.132400Z

Don’t use it :)

πŸ‘ 1
Ben Sless 2021-05-20T20:47:55.133Z

❀️ 1