This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-29
Channels
- # adventofcode (11)
- # aws (2)
- # bangalore-clj (8)
- # beginners (92)
- # boot (2)
- # calva (26)
- # cider (1)
- # clj-kondo (4)
- # cljs-dev (4)
- # clojure (54)
- # clojure-berlin (5)
- # clojure-houston (6)
- # clojure-italy (12)
- # clojure-nl (7)
- # clojure-uk (39)
- # clojurescript (12)
- # clojutre (6)
- # cryogen (1)
- # cursive (15)
- # datomic (11)
- # duct (1)
- # events (5)
- # fulcro (14)
- # jackdaw (1)
- # joker (2)
- # malli (15)
- # mental-health (1)
- # off-topic (35)
- # reagent (2)
- # reitit (24)
- # rewrite-clj (3)
- # shadow-cljs (19)
- # vim (11)
possibly dumb question, but why :keys
option map destructuring isn't allowed to be a map of bindings to default values? why repeat same names in :or
?
Hi, I have something puzzling me Iâd like to share. I wanna have reflection warnings always enabled on some project I am working on. To do so I have been advised to use the user.clj
ns as a way to set up this kind of config to be automatically loaded during development. Here is where I am a bit confused. In user.clj
if If (set **warn-on-reflection** true)
the reflection warnings are only enabled in the user
ns. If I (alter-var-root #'*warn-on-reflection* (constantly true))
reflection warnings wonât work in the user
ns but will work everywhere else... What would be the clean and proper way to have reflections warnings enabled for everything ?
So it is not sufficient for your purposes to have it enabled everywhere except in the user namespace?
Have you tried both the set!
and the alter
expressions in the user.clj file?
hi! It is perfectly sufficient for me to have it enabled everywhere but the user.clj file. I was wondering why this behaves the ways it does particularly the alter-var, and if directly fiddling this way with var state wasnât bad practice!
@U0CMVHBL2 also using both unables the warning really everywhere. I guess am just puzzled why the alter doesnât work in the ns itâs called in. Itâs interesting đ
I do not have in my head already a brief explanation why. I do know that warn-on-reflection is one of a very small number of Vars that are pushed/popped in the Clojure compiler in some basis, per file if I recall correctly. Also set! only changes the current threadâs value for a Var, not all threads. Alter-var-root changes the ârootâ value of a Var, which is independent of the per-thread values a var may have
Well, I think understanding it fully can be broken up, analyzed, and explained in simple steps, but I suspect the number of those simple steps might be a few dozen.
before using the user.clj trick actually looked a lot to find a way to specify those global values as argument to clojureâs main, or env variable... it turned out that there might be one global that can be set via java properties. It wasnât warn-on-reflect đ
@keymone hey mate, having :keys
as a map would force you to have default values for everything you destructure, with the :or
you supply defaults only where you want them.
also it allows for defaut values to be applied to nay binding you are creating not just the :keys
one {n :not-n :keys [a b] :or {n 1 a 2}}
i mean, it looks nice with :keys [a b] :or [a 1 b 2]
but in real world those are not single letter vars and repeating a dozen of them in keys and in or is quite verbose, i'd rather have a bunch of nil
s in the :keys
section instead
hey there is anyone experienced with the environ library? I'm not sure if the way i'm using it to return a default when an env var isn't found is wrong.
i'm not sure if this is correct, or, in the case where there is an :env-var, it simply adds an empty string and returns something like:
"the env var" ""
env
is just a hasmap, i would be surprised if (env :var "")
would have any side effects or change any state
hello,question: is there a way to call a defrecord method dynamically like (.f record)
where f
is passed as parameter?
@imparato.andrea you can treat records as maps: ((keyword f) record)
interesting! thx a lot
also see the examples section here: https://clojuredocs.org/clojure.core/defrecord
hey everyone! a few days ago, I had a question about changing the content-type header
to csv. I got some great help and was able to do it. Now, I would like to make some changes on the client side, so we get a prompt with a downloaded csv file as seen below.
I assume it's going to be the reg-event-fx
part, particularly in the :http-xhrio
:response-format
part. I tried looking through the docs but wasn't able to find how to change it to download prompt
@ablazevix Here's what I used recently in a project - it wasn't re-frame specific and I brought in an extra dependency, but hopefully it gives you a place to start
I brought in filesaverjs from https://github.com/cljsjs/packages/tree/master/filesaverjs
awesome, thanks for the lead! so, in your experience this was the most efficient way to do it?
(defn download-csv [filename content]
(let [mime-type (str "text/csv;charset="
(.-characterSet js/document))
blob (new js/Blob
(clj->js [content])
(clj->js {:type mime-type}))]
(js/saveAs blob filename)))
Then I used something like [:button {:on-click #(download "file.csv")}]
to trigger the download
Which you should be able to put in to your :on-success
function instead
ohhhh.. that's neat!!
I have no idea if it's the most efficient way, but it has been working well for what we wanted to do with it. Based on https://eligrey.com/blog/saving-generated-files-on-the-client-side/ it looks like there is a standard Filesaver interface in the W3C File API, so you could probably use that instead if you didn't want to bring in the dependency.
yea I read through the docs, and I realized that perhaps I don't need to figure this out on the client side, so instead I am trying to add a content-disposition
header.
(response/header (response/content-type base-response-map "text/csv") "Content-Disposition" "attachment/download.csv"))
Finally I have a question where I can provide some code. Iâm generating some mock data using existing mock data:
(def research-claims
(map (fn [id company-id user-id is-completed] {:id id
:company_id company-id
:user_id (:id user-id)
:is_completed is-completed})
(let [max-ids (count company-ids)]
(map rand-id (range max-ids))
company-ids
(take max-ids (mk-users basic-user-ids basic-role))
(repeatedly max-ids #(= (rand-int 2) 0)))))
The existing mock data are things like company-ids
and (mk-users basic-user-ids basic-role)
but those have different lengths so Iâm trying to generate my mock data based on the one with the smallest count (`company-ids`). Originally I had (count company-ids)
in place of max-ids
without the let
but I realized I could define max-ids
in a let
and reuse that. However, when I run that and eval research-claims
I get the following error:
Error printing return value (ArityException) at clojure.lang.AFn/throwArity (AFn.java:429).
Wrong number of args (1) passed to: my-app.utils.seed-data/fn--27217
My first question is; is there a trick to reading that error that will tell me which function Iâm passing the wrong number of args to? Barring that, can anyone see where my problem lies?When you get an exception like this, it can be really useful to do (clojure.repl/pst)
to print the stack trace of the most recent exception. In this case, the first line of the stack trace (after it prints the exception that youâve already seen) should point to clojure.core/map
, which would give you a clue that the function getting the wrong number of args is the fn being mapped.
you are only passing a single arg to the top level function you are mapping with. (fn [id company-id user-id is-completed]...)
expects four args and is receiving only one.
if you just eval
(let [max-ids (count company-ids)]
(map rand-id (range max-ids))
company-ids
(take max-ids (mk-users basic-user-ids basic-role))
(repeatedly max-ids #(= (rand-int 2) 0)))
in the repl you'll see that only returns the last expression not the four collections you are expectingdan@pop-os:~/projects/clojure/lsp4j$ clj
Clojure 1.10.1
user=> (map (fn [x y] (inc x)) (range 3))
Error printing return value (ArityException) at clojure.lang.AFn/throwArity (AFn.java:429).
Wrong number of args (1) passed to: user/eval1/fn--137
(user=> (map (fn my-function [x y] (inc x)) (range 3))
Error printing return value (ArityException) at clojure.lang.AFn/throwArity (AFn.java:429).
Wrong number of args (1) passed to: user/eval140/my-function--141
(user=>
and the error is difficult to read because you are using a function without a name. look at the error messages here
ahhh, so as it turns out, adding a :content-disposition
var to the header won't work with :xhrio
(noted)
Instead, I am trying to have add an anchor [:a]
that would link to the localhost:8080 and commence the download, but for some reason it is not working.. anyone knows why this would not work?
dumb question: does adding the "http://" at the front explicitly change anything?
because if that was on http://localhost, the link might resolve as http://localhost/localhost:8080 etc. - as if it were a relative link
we have a winner ladies and gents!!
thanks a lot @noisesmith
np, it was a shot in the dark
do you have night vision đ
years of suffering working on a front-to-back cljs / clj web app sold as a service - when finding an answer is painful enough you are less likely to forget the answer :D
so you sort of have night vision lol
for some reason the file comes back as a json though
that might need to be fixed on the server side in the headers coming from ring
hmm, I thought I had a fix from that before
(response/content-type base-response-map "text/csv")
aha - now I remember
yeah, that should have addressed that
yea it's weird because it does succesfully add the header, not sure what went wrong
I wonder if the multi-hop of xhr (maybe with csrf in there too) might cause the browser to use a different header than the one in your dedicated handler?
(just speculating here...)
will leave it up to the sr engineers! thanks for the help tho
there should be clues in the network history in the debug console if you have the right dev tools turned on, but if you have srs who can handle stuff easily that's always an option
yep, spoke to the chief, and he said json is a server default, will do some changes that should fix that
How can I make sure I am writing an integer to the atom and not string?
reset! vs assoc-in?
nested vals
Maybe http://clojuredocs.org/clojure.core/set-validator! will help @sova?
@seancorfield btw thanks to Slack the !
is not recognized as part of the link. đ
lol yeah
turns out i'm a genius and was saving strings
B-) caps lock is cruise control for cool
@gerred Thanks Slack đ