To future readers, who may find this in a slack archive or zulip mirror:
I found the problem. It's the Set-Cookie
header.
When configuring the middleware like this:
(ring.middleware.defaults/wrap-defaults
{:session true
:security {:anti-forgery true
:hsts true
:ssl-redirect false
:frame-options :sameorigin
:xss-protection {:enable? true
:mode :block}}})
it will add a header like this:
"Set-Cookie" ("ring-session=17a0900a-00b0-42ea-b54d-fbeec2acb15e;Path=/;HttpOnly")
Notice that the value is a seq, and that's the issue.
The value must be a string for the AWS API Gateway to pass it through correctly.
Adding an ugly workaround like this additional middleware fixes the issue:
(defn fix-aws-api-gateway-cookie-header [handler]
(fn [req]
(let [res (handler req)
cookieList (get-in res [:headers "Set-Cookie"] [])]
(assoc-in res [:headers "Set-Cookie"] (or (first cookieList) "")))))
iiuc docker may go away, but you get podman and its friends instead...
They look like Clojure future
and promise
-- what am I missing?
(:import (org.apache.sshd.common.session SessionHeartbeatController$HeartbeatType))
;; or just
(:import org.apache.sshd.common.session.SessionHeartbeatController$HeartbeatType)
;; if you're only importing one class from that package
Can that alias just the inner class?
in Java, inner classes are not hierarchically "below" inner classes, they are just lexically nested within them. The only hierarchical relationship is classes in packages.
the class name of the nested class is SessionHeartbeatController$HeartbeatType so there is no way to break that apart
Oh I see. Thanks so much @alexmiller
Okay. But if the ns that does the require alters a dynamic var. The var being used by the macro in the required ns. Is that too late to alter how the macro expands?
Not sure if mostly Java related or Clojure, could guess Java/visualvm related but asking here just in case. Basically returning to my workstation today I find my project directory filled with *.class files, generated somehow. Guess it could be from a visualvm session yesterday with profiling?
Does this relatively new deprecation warning from Clojure tools
WARNING: Use of :main-opts with -A is deprecated. Use -M instead.
means that it is preferred to have $ clj -M:test:runner
now instead of $ clj -A:test:runner -M:runner
as described in https://github.com/seancorfield/clj-new?
Does anyone understand the mechanics of how this worked under the hood? https://www.youtube.com/watch?v=YY6B9EHbH24, particularly viewing values inside of function calls
Ahhh, I see @seancorfield was updating the README of seancorfield/clj-new
a few hours ago. I must have had the previous version open in my browser 🙂
That looks like AOT compilation- nothing to do with visualvm
@sztamas Yup, I'll be overhauling clj-new
to favor the -X
execution approach in the next release (while still retaining the -M
stuff), but I wanted to get the README etc updated sooner (you'll see the same issue with projects generated from clj-new
until I make that release).
Yes, thanks for that! The timing of it was a bit funny. I asked, then actually forked your project to make a PR with the README changes, but by then it all looked OK in my fork. Had a bit of a huh? moment... :-)
hm, could not be happening when running the samples/profiles from visualvm?
Is there a way to use with-redefs such that you wrap the root binding? For example:
(defn fake-invoke [arg]
(println "HEY!")
(original/invoke arg))
(with-redefs [original/invoke fake-invoke]
(original/invoke "Something"))
This will cause a stack overflow because original/invoke is still rebound. I'd like to "escape" the rebinding in the fake-invoke call.(let [original redefed] (with-redefs [redefed (fn new [...] (prn "intercepted) (original ...))
at my last job before with-redefs was added to clojure we had a macro with-var-roots
that did the same thing, but had the added feature of being able to use metadata to ask that the original value of the var by bound to some name in the scope of the expression
(with-var-roots [^{:original foo} original/invoke (fn [arg] (println "HEY!") (foo arg))] (original/invoke "something"))
so you could do something like thatWhat do you think of reducible queue?
(defn reducible-queue [^BlockingQueue q]
(reify IReduceInit
(reduce [_ f init]
(loop [acc init]
(let [ret (f acc (.take q))]
(if (reduced? ret)
@ret
(recur ret)))))))
(let [q (doto (ArrayBlockingQueue. 1024)
(.put 1)
(.put 2))]
(future (Thread/sleep 1000)
(.put q 3))
(transduce (take 3) conj [] (reducible-queue q)))
;; 1 second later:
=> [1 2 3]
one of the neat things about lisps (including clojure) is that they typically have a small number of language primitives, https://clojure.org/reference/special_forms . Not sure how Light Table did it, but you can basically just macro expand any form, look for the binding primitives (eg. let
fn
), and rewrite the code to extract the value when you eval the snippet
Just reduce over the queue
You can already reduce over all java Collections and even all, I forget the interface iterables?
Reducing directly over the queue wouldn't wait for the last value 3. But it seems to me like (reducible-queue q)
could be (repeatedly #(.take q))
oh, I haven't thought that queues are ordinary java collections
I wanted a reducible version for performance, I don't need intermediate collection...
hmm no, just reducing over queue does not block, that's not what I want
(let [q (doto (ArrayBlockingQueue. 1024)
(.put 1)
(.put 2))]
(future (Thread/sleep 1000)
(.put q 3))
(transduce (take 3) conj [] q))
;; immediately
=> [1 2]
ah, you already pointed it out @jkr.sw 🙂
(into [] (take 3) (reducible-queue q))
would probably be even faster since it uses transients
yeah, true 🙂
core.async has a reduce that reduces channels
although I now feel like we've had this identical conversation already
often you want to walk away from the queue based on an external signal, so continuous reduce might not be best thing
(no different with channels)
Hi folks. I was asked to write a little post about Clojure and one question I would love to answer is Why Clojure. To me was more curiosity than anything else... So wondering what is tour reason to choose Clojure over other functional or jvm languages (if this dont be long here just let me know Thabks)
The Clojure community is also great. Some attributes that come to mind: smart, humble, curious, thoughtful, generous, patient, welcoming.
I came to clojure because I read a bunch of blog posts saying lisps were cool. I stayed for the emphasis on programming with pure functions and ubiquitous use of immutable data structures.
We like dogma and cults
Most languages ship dead fish binaries, old languages like lisp/smalltalk encourage you to REPL into your running programs to build up your programs at runtime, Clojure still has this ability This is game changing for debugging and building long running processes like web servers or LSP servers or video game creation
The question is fine here as long as folks stick to answering in this thread (otherwise, for a more wide-ranging discussion, I'd suggest #off-topic ). My answer to "Why Clojure" is based on my language arc: I'd done a fair bit of Lisp at university (in the early '80s) and I specialized in FP for my postgraduate work (ML, Miranda, SASL -- all precursors of Haskell, along with the research language I created: SURE). My early professional work was COBOL, C, and assembler, then on to C++ in '92 (and eight years on the ANSI Standards Committee), then Java in '97 -- and I liked the JVM so everything since has been JVM-based. CFML/ColdFusion while I was at Macromedia, alongside Java. Then Groovy, then Scala -- as I wanted to tie together my earlier FP work with something on the JVM. That was around 2009. That got me casting around for more FP options on the JVM so I found Clojure in 2010, then introduced it at work in 2011 and cross-trained the other developers. And I've been doing Clojure in production ever since. So, "Why Clojure" is: a) because I have always felt FP is a better way to design/construct programs (despite all my years in the OOP wilderness -- and a lot of advocacy for OOP, since I never figured FP would go "mainstream") b) because I like dynamic languages better than statically typed languages (mostly personal) and compile-on-demand languages better than aot-compiled languages (my laziness and lack of patience 🙂 ) c) because immutability by default eliminates a whole class of bugs d) because the REPL provides immediate feedback and an interactive way to build programs (again, my lack of patience 🙂 )
Thanks for the thorough answer
don't remember it... I'm reluctant to depend on core async because of the startup time penalty it brings
well that's what returning reduced is for?
repl driven development support has also been a big reason I've stuck with clojure.
e.g. (take-while (fn [_] @running))
is somewhere in xform
this is for a library for others to depend on...
is there a transducer that does windowing by time? sort of like a partition-by
, but flushes elements at least every n millis if non-empty
you can't do that with a transducer
https://github.com/cgrand/xforms has some windowing xforms
the reducing function returns whatever value to a reducing context, and cannot wait for some timeout and flush
ah, good point
I still can't follow the idea of Repl DD haha.. good point
Eric Normand's REPL-Driven Development course on http://PurelyFunctional.tv is awesome (if you don't mind paying $49 for a month's subscription). Stu Halloway has two great talks on the topic: Running With Scissors and REPL-Driven Development.
I've prattled on about it a lot too: never type instead of the REPL, don't use refresh/reload "magic", eval every single change as you make it (without even saving files), learn to run tests via the REPL using a hot key in your editor.