This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-24
Channels
- # announcements (39)
- # aws (4)
- # babashka (18)
- # beginners (32)
- # biff (10)
- # calva (22)
- # clj-kondo (11)
- # clj-on-windows (2)
- # cljs-dev (20)
- # clojure (31)
- # clojure-europe (130)
- # clojure-norway (21)
- # clojure-spec (24)
- # clojure-uk (17)
- # clojured (2)
- # clojurescript (6)
- # conjure (1)
- # core-async (5)
- # cursive (11)
- # datalevin (1)
- # datomic (9)
- # emacs (24)
- # figwheel-main (42)
- # fulcro (6)
- # gratitude (6)
- # honeysql (8)
- # juxt (16)
- # kaocha (6)
- # lsp (235)
- # malli (2)
- # nbb (7)
- # off-topic (23)
- # other-languages (24)
- # pedestal (7)
- # reitit (6)
- # sci (1)
- # shadow-cljs (21)
- # tools-build (22)
- # tools-deps (57)
- # vim (24)
Hi y’all! so, tricky question about protocols, reify…
(ns dog.protocol)
(defprotocol Dog
(-get-name [this]))
(ns dog.implementation
(:require [dog.protocol]))
(def doggy
(reify dog.protocol/Dog
(-get-name [_] "Doggy"))
(defn logging-dog [original-dog]
(reify dog.protocol/Dog
(-get-name [_]
(let [name (dog.protocol/-get-name original-dog)
(println name)
name]))))
(def logging-doggy (logging-dog doggy))
(-get-name logging-doggy) ;; should return name and print it
as usual, contrived example.
I have a very similar situation, where I override some behaviour. It works all fine in the REPL and in local dev…
when I try to build an uberjar, it says that one of the methods of my protocol is not being implemented….which is not true.
Any clues?can you fix all the syntax errors in that code. if you then run it, does it exhibit the same problem that you observe in the real code?
In situations like this it could also be helpful to restart your REPL, to see if it still works there
it's most likely an issue with order of compilation, but without knowing more about how you're building the uberjar and the actual issue, it's hard to guess what's wrong
hm… that’s a good clue
the key is that you want the ns with the protocol compiled first
otherwise it will get compiled twice and you can have instances of the first (dead) class that no longer implement the second (alive) class
but also, doing top-level def's is something I would avoid as much as possible as they will happen during compilation too, if you're doing that in your actual code
got it.
What could be possible reasons of the same ns being compiled multiple times when building an uberjar?
This happens in leiningen, if you're using that. A solution there is to just say: :aot [my.main-ns]
instead of :aot :all
Does anyone know how to invalidate ring session cookies? Went through a security audit and even though logout (setting :session to nil) deletes the cookie from browser, someone can technically just save the cookie before logging out and then restoring the cookie after logging out
My answer to this question is always: how do they get the cookie in the first place? If you're using HTTP only, secure cookies along with correct SameSite attribute - they become quite hard to exfiltrate in the first place.
That said, if you do need that then you need to move to session handling in the backend and your session cookie should only store session ID. I believe there's a ring middleware/extensions that let's you use Redis for that - then on log out you "simply" delete the session from your session store and the value in the cookie is immediately invalidated
Yeah, I totally get that it's extremely hard to get the cookie if you don't already have it. Was wondering if there was an easy way to maybe expire the cookie during the logout
Pretty hard unless you track live sessions somewhere - one small thing is to attach expiration date as cookie value, and renew it on each request. This way if someone steals the cookie (somehow) has a limited window of using it because if they don't it will be past the expiration date - this is in addition to the cookie's own expiry date
whats the best way to write pretty foramtted (human readable) edn so that you can read it back in?
edn/read-string doesn't seem to understand "#:mvn{:version "..."}"
Technically, that's not yet EDN: https://github.com/edn-format/edn/issues/78
then i guess the question is, how do you write human readable edn to a file?
If you trust the data, you can probably just use clojure.core/read-string
and print it the way you do.
If you don't trust the data, you can bind *print-namespace-maps*
to false
before printing.
The EDN reader should understand these "namespace maps":
user=> (clojure.edn/read-string "#:mvn{:version \"123\"}")
#:mvn{:version "123"}
We're on an older version of clojure. That might be part of the issue.