This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-21
Channels
- # announcements (1)
- # aws-lambda (62)
- # babashka (116)
- # beginners (67)
- # chlorine-clover (39)
- # cider (10)
- # cljs-dev (5)
- # clojure (30)
- # clojure-austin (2)
- # clojure-europe (2)
- # clojure-italy (6)
- # clojure-nl (24)
- # clojure-uk (28)
- # clojurescript (33)
- # data-science (6)
- # datascript (10)
- # datomic (5)
- # duct (39)
- # emacs (1)
- # events (8)
- # fulcro (9)
- # graalvm (29)
- # hoplon (7)
- # juxt (10)
- # malli (4)
- # off-topic (6)
- # pathom (10)
- # perun (1)
- # reagent (45)
- # shadow-cljs (5)
- # sql (14)
- # tools-deps (10)
- # xtdb (9)
Hello, how can I solve this?
> (def url "")
> (def file (net.cgrand.enlive-html/html-resource (.URL. url)))
Syntax error (SunCertPathBuilderException) compiling at (form-init5400902524976976728.clj:499:35).
unable to find valid certification path to requested target
If I recall correctly, lein ships with a helpful routine to download the HTML for a URL and print it in the REPL.
@potetm Hmm, not that I'm aware of... Happy to be proved wrong...
iirc @noisesmith might have been the one to point it out to me
Cider has an (anti) feature that it will slurp uris automatically. Not sure nrepl in general does though
That kinda makes sense. I mean, CIDER has every feature, right? 🙂
Still doesn't solve the OP's problem. I can only assume the cert on that .ni
site isn't in the default chain of trust for the JVM?
(I tried that code in a bare clj
REPL and got the same exception)
Is there a {:insecure? true} option for html-resource like in clj-http?
it looks like enlive just calls (.getContent) on a URL so no way to get that kind of info there.
@orlandomr27 The certificate of that site seems to be invalid according to openssl
too:
openssl s_client -showcerts -connect
...
Verify return code: 21 (unable to verify the first certificate)
I'd say it's best to import the certificate into java keystore manually (also safer then using some kind of "insecure" option forever)(let [body (:body (http/get url {:insecure? true}))
input (.ByteArrayInputStream. (.getBytes body))]
(soup/parser input))
the html-resource ns has a bunch of methods for retrieving an inputstream. but if you want to get it by other methods this is where you end up anyways
Anyone here use Aero? I have a property like this
:port #or [#env MONGO_PORT 27018],
But when I run in my terminal:
MONGO_PORT=27777
And then run in the same terminal:
lein with-profile test-profile test
The test that checks if the port is 27018 passes. Anyone know why the environment var is not being picked up?
Are you using io/resource
to read config file?
If you want an environment variable to be seen by subprocesses you need to set it with export or prepend it to your command. See https://unix.stackexchange.com/questions/130985/if-processes-inherit-the-parents-environment-why-do-we-need-export for more info.
There a way to write this, without [x times], I mean I don't need the variable x
Is there an idiomatic way to remove elements of a vector using destructuring? Say I have a list of vectors that have 6 elements but I want the data with the 4th and 5th elements removed, how would you approach that?
Well, not necessarily using destructuring, I just approached it that way at first because it would have been very nice and easy. haha. Something like (map (fn [[a b c _ _ f]] [a b c f]) coll)
Something like,
(keep-indexed #(when (#{0 2 4} %1) %2) [1 2 3 4 5])
;; => (1 3 5)
But your solution using destructuring is elegant. If you really need a vector, pass through (into [] ...)
.That said, vectors are not designed for this use case. They aren't efficient for it. Subvec with into is the fastest way
Also, vectors can't really have their elements removed. You need to construct a new vector which contains all the other elements.
subvec is fastest because it won't actually copy it all, it'll share the same vector as long as it can under the hood
------------------------- cljs.core/subvec ([v start] [v start end]) Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not supplied, defaults to (count vector). This operation is O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done.
But when you concat two or more subvecs, it does get copied, right? Or are there more magic?
You can iterate through elements of a vector v2, and conj each of them successively onto a vector v1, unit eventually all of them are, to concatenate, but that takes linear time (times some logarithmic factor) in the size of v2 to concatenate, and is essentially what (into v1 v2)
does (except it uses transients for better efficiency in the constant factors involved, although it stiill takes linear time in the size of v2)
The library core.rrb-vector
can concatenate two vectors in logarithmic time in the size of the larger one, using a different kind of tree data structure internally than Clojure's built-in vectors use.
It is still a little bit buggy, though, so I wouldn't 100% recommend it unless those remaining bugs are fixed.
Ya, I should have mentioned, while subvec is O(1), the following into
is what will slow the operation down, and why using a map or like @U0CMVHBL2 mentioned a more specialized structure built for this split/join use case like rrb-vector would be faster. You can also go down to Java and just use Linked list, but now you are entering mutation land.
Anyways, all these are probably some pre-optimization concerns that don't matter unless you have hot loops or are implementing algorithms.
yep but is the same, I asked for way for just use times
instead [something times]
I don't know of a way, except, (run! println (repeat times "Hello World"))
but this will create a sequence for no reason at all and is more wasteful.
@UJRDALZA5 I guess that the first method is the most common, well I just had curiosity if there a way to do it, thank you
In theory dotimes could be made to accept a binding vec that is only a number, but seems a bit silly, saves you one character to type
(defmacro dotimes
[bindings & body]
(if (= 1 (count bindings))
`(clojure.core/dotimes [_# ~(first bindings)]
~@body)
`(clojure.core/dotimes ~bindings ~@body)))
When I run lein repl
I get an exception saying it can’t find a class of mine. The class it’s complaining about is one where I use :gen-class
to subclass InputStream. If I compile the class explicitly in the repl, it works but I can’t figure out why it’s missing to start with.
I think you need to add a aot
path in your project.cj like
https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L272
this tells lein to pre-compile the namespace
The caveat being, you need to run compile again or restart the REPL if the file changes
you can try something like https://github.com/yogthos/lein-watch if this becomes a hassle