This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # bangalore-clj (11)
- # beginners (82)
- # boot (1)
- # braveandtrue (29)
- # cider (16)
- # cljdoc (2)
- # cljs-dev (2)
- # clojure (74)
- # clojure-dev (3)
- # clojure-italy (2)
- # clojure-mke (1)
- # clojure-nl (4)
- # clojure-sg (1)
- # clojure-spec (1)
- # clojure-uk (53)
- # clojure-ukraine (1)
- # clojurescript (33)
- # cursive (29)
- # datomic (59)
- # editors (4)
- # emacs (14)
- # fulcro (2)
- # graphql (12)
- # hoplon (2)
- # nyc (4)
- # onyx (5)
- # parinfer (10)
- # pedestal (22)
- # re-frame (11)
- # reagent (35)
- # ring-swagger (5)
- # shadow-cljs (150)
- # tools-deps (9)
- # vim (1)
- # yada (20)
i want to run--and rollback the changed db-- some function. what i have, that doesn't work, is below:
(clojure.java.jdbc/with-db-transaction [db-spec' db-spec] ;; create a separate db-spec (with-redefs [db-spec' db-spec] (sync-feed)) ;; inside this, there are jdbc/insert!'s (throw (Exception. "sql-test-exception"))) ;; want to rollback
(sync-feed)i change the db via jdbc. fails with
java.lang.RuntimeException: Unable to resolve var: db-spec' in this context
this doesn't work; it changes the db and doesn't rollback:
(clojure.java.jdbc/with-db-transaction [db-spec' db-spec] (sync-feed) (throw (Exception. "sql-test-exception")))
sync-feed does several things; the actual calls to
update! are nested in other functions still inside
sync-feed. this is just for dev-testing purposes.
with respect to advice "do not def a global connection"--this is a production system that was live long before me; i'm trying to--for dev purposes--do a db transaction and roll it back
@mfm for that the immediate problem is that you have your bindings in the wrong order in
(with-redefs [thing-to-redef temporary-new-value] ...)
ah thank you @michael.gaare. working on it. that at least runs. it still doesn't rollback for me....
ah, works! i had a misplaced paren. thanks very much, everybody! i have noted that db-spec should be a param.
Really dumb question 😕 I am trying to add a css file to my hiccup model. How should I prefer the path? The css is under
Hi everyone 🙂 Is anyone currently working through Clojure for the Brave and the True?
I’m working on brave and true. Just finished Chapter 3. I just joined #braveandtrue
Hey team, I am trying to wrestle with an interesting bug: - clojure has saved a string, which when printed looks like "foo ?" - but the "?" is actually a weird character. if do (-> x seq last int) -- I get the number 55357 - however, if i inspect the string in repl, copy the output, then paste it back, I get it as the question mark -- int value of 63
perhaps for unknown codepoints, when we print a string from clojure, it gets converted to a normal
clojure writes out the byte, and whatever display system you are u sing is then responsible for rendering it
and also makes it c&p as ?, instead of rending it as ? and making it c&p as the actual value
e.g. I have an xterm that is setup up properly to handle unicode characters, so the poop emoji is rendered in emacs in that xterm as just a weird space
but I can still in emacs copy and paste that character around, because even though it renders as a weird space, it copy and pastes as the actual value
So, one thing that makes think is the following:
- in our system, we took this string, and sent to to another service (i.e through http)
- the other service ended up saving the string a
? - codepoint 63
I am trying to grok what could have happened there. We have sent other unicode characters, which rendered correctly (i.e smiley faces etc)
Hi Clojure experts, Anyone know how to populate default content-type response headers for "OPTIONS" requests? in our code we enabled cors with below code
wrap-cors is from ring.middleware.cors but notice that
(defn add-cors [route] (wrap-cors route :access-control-allow-origin #".*" :access-control-allow-headers ["Content-Type"] :access-control-allow-methods [:head :post :get :options]))
OPTIONSrequest always missing
Content-Typein response header.
Assuming this is the library you're using, looking at the code at https://github.com/r0man/ring-cors/blob/master/src/ring/middleware/cors.clj#L165 it looks like there is no hook to customize the headers on the options response with that library
That is, if you're going with
wrap-cors; there's a lot more flexibility if you call
handle-cors yourself as you can supply a custom
As it's a function you can do whatever you want in there instead of the default
add-access-control (you'll probably want to still call that at some point, then do additional stuff)
@stopachka In memory, JVMs use UTF-16 to encode the characters of Unicode strings. UTF-16 is a variable-length encoding in general, while most Unicode characters are encoded with a single 16-bit character in memory, some are encoded as a pair of 16-bit characters in memory. These 2 16-bit characters are called a high surrogate and a low surrogate, and all of them fall within a particular numeric range. 55357 decimal is one of the values in that range. It would be less surprising to find such a character if there was another one just after it in the same surrogate range. One on its own seems weird. Search for occurrences of "surrogate" on this Wikipedia page if you are curious to read more about them: https://en.wikipedia.org/wiki/UTF-16#U+D800_to_U+DFFF
UTF-8 is more commonly used in wire protocols between systems. It is also a variable-length encoding, but a single Unicode code point can require anywhere from one to (I think) up to 6 8-bit bytes to represent. The Java libraries have methods for encoding in UTF-8 when writing strings to a socket/file/etc., as well as for decoding UTF-8 when reading.
As some wild guess, maybe one place where such conversion should be happening, isn't happening, but that generic comment doesn't necessarily help you find out where.
And, as a wrinkle on that, I believe starting with JDK 10 there is an additional optimization where if a string contains only characters in the ASCII set, it will now store that string as a sequence of ASCII bytes in memory, without doubling its size to 16 bits per in-memory character. Cool. That change is I believe transparent to anyone using the JVM libraries for strings, which Clojure does.
I need to apply a function to some of the elements of my vector, let's say I have
[1 5 10] and I want to apply
inc to only the first 2 values.
I thought of a possible solution of creating a vector of functions to apply so I could do something like
(mapfuncs [inc inc identity] [1 5 10]). But I'm having problems to find or to create a function like
Greetings clojurians! I’m working though the REPL namespace guide and it appears that switching to an existing namespace with
(ns foo.bar) is the same as
If that’s the case, why switch using
It seems to me that
in-ns carries a risk if the namespace doesn’t exist. I may assume that the
ns function will create a new namespace but vars I created in it are restored
ns does not create a new ns if it already exists it just switches to it (plus whatever require, import, etc. you specify)
Thanks @noisesmith, that was my observation. Not clear about the value of
in-ns since that functionality is duplicated by
You're right that for most "normal" use-cases there is no reason to call
in-ns, but there is also no strong reason for the core library to hide it.
Having said that I can't find the code for in-ns in clojure.core; I'm starting to doubt whether it is a function
eg. I often run a one liner like
(doto 'my.ns (require :reload) in-ns test/run-tests), it's easy to find this in my repl history and run it to reload and execute tests
I think in-ns might be bootstrapped before some of the other stuff that source needs in order to work
But it is a function; when I did not see it in clojure.core for a moment I wondered if it were a special form.
it's an instance of IFn which means it's a first class object and you can call it (see also maps, keywords)
Well apparently it's not a
fn? function, but it is a normal var with some callable object attached and no macro flag
Hi Everyone, in my code, i forward all unrecognized route to /public
and i would like to set a cache header in the response but i don't see there is API for static resrouce. https://weavejester.github.io/compojure/compojure.route.html is there any other way i can add a custom response header to all my static resource?
(undocumented (route/resources "/")))