This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-20
Channels
- # announcements (5)
- # beginners (37)
- # calva (3)
- # cider (23)
- # clojure (98)
- # clojure-dev (16)
- # clojure-europe (5)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-spec (7)
- # clojure-uk (52)
- # clojurescript (14)
- # cursive (15)
- # data-science (1)
- # datomic (20)
- # emacs (7)
- # flambo (2)
- # fulcro (10)
- # jackdaw (1)
- # jobs (3)
- # joker (2)
- # juxt (3)
- # keechma (3)
- # leiningen (8)
- # luminus (3)
- # music (1)
- # off-topic (83)
- # pathom (19)
- # re-frame (19)
- # reitit (4)
- # shadow-cljs (76)
- # spacemacs (95)
- # tools-deps (16)
@emccue What do you want to know?
(sorry for the slow response -- dinner and feeding cats)
s/explain-data and then a heuristic algorithm to turn the explained failure back into an error code
i have a problem getting options preflight requests to work in clojure
im using wrap-cors
(run-server
(wrap-cors
(wrap-json-body
(my-routes db)
{:keywords? true :bigdecimals? true})
:access-control-allow-origin [#""]
:access-control-allow-methods [:get :put :post :delete :options]
:access-control-allow-headers ["Origin" "X-Requested-With"
"Content-Type" "Accept"])
apparently this doesnt work, so i cant make post requests :C
Just a heads up everyone, the behaviour of format
function changes between java 8 and java 12
(format "%.2f" (float 10000))
will produce 10000.00
in java 8 but 10000,00
in java 12 if your locale has ,
as decimal separator
is it possible to remove an element from vector by index?
Yes, you can use subvec
and into
. But it's not an efficient operation, hence why they left out a function for this.
If you're going to do this a lot and are worried about performance, you should probably use other (or additional) data structures.
remember that subvec
leaks memory (it's a view over other vector, so removed item won't be GCed)
If you need to do this, check out rrb-vector, it might be closer to what you're looking for with better Big O runtimes
Yes rrb-vector is better suited for such operations in terms of performance. I hope to create a new release of that library in the next week or two that should fix several existing bugs in that library.
With that library, you can do the remidx function above and it will run in O(log N) time.
Its one of my favorite libraries, excited to hear about the potential of an upcoming release for it 🙂
Ended up simply implementing this with arraylist
(for purposes of pinpointing which form was the issue and processing every form before it)
if you care, don't use seqs
use loop/recur
or in cheshire, don't use the lazy seq parsers
im having a really hard time getting a CORS middleware to return 200 on options requests, and was hoping someone might help walk me through it https://gist.github.com/patientplatypus/0e3defaf1cfeff3b6ca3f0910993ce10
It looks like you are attempting to invoke the preflight map as a function on line 95 of your gist. What if you just unwrap the parenthesis around that?
@U0CJ19XAM mentioned what seems like an obvious bug that would prevent your preflight from working. Have you tried raising the 200 map out of the parens that surround it?
i have not tried that yet
lemme give that a shot
im thinking it should look like this
(defn wrap-preflight [handler]
(fn [request]
(do
(println "inside wrap-preflight")
(println "value of request")
(println request)
(println "value of handler")
(println handler)
(if (preflight? request)
{:status 200
:headers cors-headers
:body "preflight complete"}
(handler request)))))
@U0CJ19XAM no...i get around the errors i was getting in the terminal logs, but im still getting 404s on get and post requests
i want to cry
Are you dead set on using ring middleware or would you be open to non-ring libraries?
@U0CJ19XAM I do get responses if i make a straight request in the browser (ie http:..../foo)
at this point i just want to make this work
huh? no, a curl get request and a browser request are the same
i cant cross domain request (ie request a get from the client to the server)
this is for my portfolio, so one day i can get a job and not die screaming in the gutter covered in my own filth.
not that that should matter
Otherwise, I would be happy to pair program with you on making a CORS respecting backend api either later today or within the next few days. We could go through a pretty deep dive and make the backend robust and built in an idiomatic clojure style. I hear you, I empathize with your frustration. I was just there 3 weeks ago with CORS and AWS Cognito/ API Gateway. I think the best thing may be to take a walk or step back from the problem. If you want a full sample project for how to set up CORS with pedestal I can grab one right now, but then you have to learn pedestal.
oh, well. thanks man. i might ask around.
if anyone has any ideas
@emccue take-until-throws:
(defn nums [n]
(lazy-seq (cons n (nums (dec n)))))
(defn take-until-throws [coll]
(try
(let [n (first coll)]
(lazy-seq (cons n (take-until-throws (rest coll)))))
(catch Exception e
nil)))
(map #(/ 10 %) (nums 10))
; =>
Error printing return value (ArithmeticException) at clojure.lang.Numbers/divide (Numbers.java:188).
Divide by zero
(take-until-throws (map #(/ 10 %) (nums 10)))
; => (1 10/9 5/4 10/7 5/3 2 5/2 10/3 5 10)
I discovered this by way of pasting a UUID, minus the last digit, into the REPL, then spending a long time trying to figure out why that UUID was no longer in the database :P
The thing is, I've written a function to create a UUID of all zeros, padding the last number, so the UUIDs are readable in tests. And now I can't figure out whether I like this or hate it.
So I'm now lost in the wonderous docs of UUID's. I never knew there were this many "versions" of them. Version 4 "random" is all I've really known. TIL.
@alexmiller Im given a bunch of space separated json forms, so the seq parser is the only one i've found so far that works
i am so lost
does anyone have any idea why this wont pass cors? i have been at this for hours and hours and hours
are your CORS headers being served ?
this shouldnt be this hard!
https://stackoverflow.com/questions/58030830/clojure-cross-origin-error-totally-lost
How can I parse "2019-09-19 18:09:35" into an #inst? I'v tried java.util.Date/parse and java.time.Instant but neither seem to work although I could be implementing them improperly
An "#inst" is not a type, it is the serialized form of a date, so many different date time types serialize that way
It doesn't make sense to parse something into an "#inst" because it isn't a specific thing
It is unlikely that anything will parse that string out of the box, because it doesn't contain enough information to make a good date object (no timezone info) but you can create a custome parse using DateFormat
I would prefer something like a java.time.Instant to a java.util.Date, but Instants don't serialize(print as) to #inst tagged literals by default. It isn't to hard to make them print that way though
You could also use Instant/parse
, but you would have to replace the space with a T
char.
If it's Clojure only (not cljs), I like this wrapper lib for Java8 time: https://github.com/dm3/clojure.java-time
I would prefer something like a java.time.Instant to a java.util.Date, but Instants don't serialize(print as) to #inst tagged literals by default. It isn't to hard to make them print that way though
There are also these two (similar) time literal libraries that provide this which you can either use or steal ideas from https://github.com/henryw374/time-literals https://github.com/magnars/java-time-literals
I have also collected a bunch of java.time
helpers here: https://cloojure.github.io/doc/tupelo/tupelo.java-time.html
Also see the embedded reply using DateTimeFormatter
and ZonedDateTime/parse