@em not 100% sure which "blocking aspect" you mean. 'block' in the blockchain is not about blocking. π
@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 π
β’ 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?
(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 π
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, @flowthing.
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}}
.
(defn submap [a b]
(nil? (first (clojure.data/diff a b)))
Leveraging clojure.data/diff
That was incredibly succinct! WOW.
Wonder how that would look like in Java π
@viebel 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
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?) π@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)
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).
@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.
(defmacro embed [form]
(eval form))
And then
(embed (count "Bearer "))
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
This sounds a good case for (def ^:const Bearer (count "Bearer"))
and (subs "Bearer xyz" Bearer)
Is there a way to intercept all the calls happens via clj-http? Without touching each call individually?
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
it seems clj-http accepts middleware: https://github.com/dakrone/clj-http#custom-middleware
you could probably use this
> 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.
has a ton of stuff in this ballpark
let the JIT deal with 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)
premature optimization...
How about regex:
(some->> bearer
(re-find #"((?i)bearer[\s]+)(.*)$")
last)
@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
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
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!
@ben.sless could you be so kind and explain a little how will :inline be used?
@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
Donβt use it :)