This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-10
Channels
- # announcements (15)
- # bangalore-clj (1)
- # beginners (207)
- # calva (22)
- # cider (4)
- # clara (73)
- # cljs-dev (7)
- # cljsrn (4)
- # clojure (125)
- # clojure-dev (38)
- # clojure-europe (2)
- # clojure-india (11)
- # clojure-italy (11)
- # clojure-nl (14)
- # clojure-russia (22)
- # clojure-uk (32)
- # clojurescript (30)
- # cursive (11)
- # datavis (2)
- # datomic (14)
- # editors (3)
- # emacs (3)
- # hyperfiddle (4)
- # juxt (13)
- # klipse (1)
- # luminus (5)
- # nrepl (7)
- # off-topic (9)
- # overtone (13)
- # portkey (1)
- # re-frame (15)
- # reagent (13)
- # ring (30)
- # schema (4)
- # shadow-cljs (108)
- # spacemacs (8)
- # specter (3)
- # sql (2)
- # testing (11)
- # tools-deps (21)
- # unrepl (4)
Hello all, I´ve got this from result #object[java.util.Optional 0x5c2aa319 Optional[2019-01-09T23:01-02:00[America/Sao_Paulo]]]
, what is that?
it has a .get
method https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html
in general, if you get an object that isn't familiar (especially a java.* object) the javadoc is going to be your best bet
you might also want to use one of the methods there to do some default action of it's empty, rather than throwing an exception as get will
some examples of playing with it in a repl:
(ins)user=> (java.util.Optional/of 1)
#object[java.util.Optional 0x319bc845 "Optional[1]"]
(ins)user=> (.get *1)
1
(ins)user=> (java.util.Optional/of nil)
NullPointerException java.util.Objects.requireNonNull (Objects.java:203)
(ins)user=> (java.util.Optional/ofNullable nil)
#object[java.util.Optional 0xe84a8e1 "Optional.empty"]
(cmd)user=> (.get *1)
NoSuchElementException No value present java.util.Optional.get (Optional.java:135)
using a default value instead of throwing:
cmd)user=> (java.util.Optional/ofNullable nil)
#object[java.util.Optional 0xe84a8e1 "Optional.empty"]
(ins)user=> (.orElse *1 0)
0
(ins)user=> (java.util.Optional/of 1)
#object[java.util.Optional 0x23d1e5d0 "Optional[1]"]
(cmd)user=> (.orElse *1 0)
1
I see an exotic regression between clojure 1.8 and newer versions. From 1.9 onwards this is now invalidated by clojure spec
(let [f (fn [] "hi")]
(eval `(defn foo [] (~f))))
In older versions this was possibleIs this a bug or a feature? 🙂
ah sharp
Thanks, sorry for the noise
Is there a channel on the slack for telling people that hey, I just published a library on Clojars in case anyone is looking for something similar?
is there a way to fully qualify symbols in a data structure that’s not a literal? e.g.:
(qualify (clojure.edn/read-string "{str #{:clj :cljs}}" ))
perhaps in conjunction with this https://stackoverflow.com/a/43722784/10667553
@borkdude @bronsa https://github.com/clojure/spec-alpha2/blob/639767ebe1491536ec7404d8b478628ecfe9200b/src/main/clojure/clojure/spec_alpha2.clj#L315-L326
full example for those interested:
(defn- explicate-1 [a-ns form]
(walk/postwalk
#(cond
(keyword? %) %
(symbol? %) (or (->> % (ns-resolve a-ns) symbol) %)
:else %)
form))
(comment
(explicate-1 'clojure.core (clojure.edn/read-string "{str #{:clj :cljs}}"))
;; => #:clojure.core{str #{:clj :cljs}}
)
Hey all, can anyone suggest how I can twist clj-http's
arm into sending such as request
curl -i -XPOST -H "Content-Type:application/octet-stream" -H "Authorization: Bearer blah" --data-binary "@/Users/me/Downloads/an-image.png"
I've tried
{:body (IOUtils/toByteArray (io/input-stream "Users/me/Downloads/an-image.png")
but get a 404 from the serverare you sure you're hitting the right endpoint with the right http method?
also I'd be surprised if clj-http couldn't just use an input-stream directly
Yeah, I believe so, I've tried the same ensuring same url with IntelliJ's http client without specifying the actual binary data, and again receive a 404, so I believe that's the servers behaviour.
Full request coming after I've stripped secrets 😉
are you sure you're doing a POST?
(->> (client/post
(str
" "
(System/getenv "CONTENTFUL_SPACE_ID")
"/uploads")
{:body (IOUtils/toByteArray (io/input-stream "/Users/will/Downloads/BP TUM Pictures PNG/TUM1 001K.png"))
:headers {"Authorization" (str "Bearer " (System/getenv "CONTENTFUL_MANAGEMENT_KEY"))}
:content-type "application/octet-stream"}))
Yeah, definitely a post.
@paulspencerwilliams did you tried using the input-stream
directly? (remove the IOUtils/toByteArray
)
Nope, still 404.
@paulspencerwilliams you might need a .trim
on the thing you get from getenv
, i've had that problem before
(->> (client/post
(str
" "
(System/getenv "CONTENTFUL_SPACE_ID")
"/uploads")
{:body (io/input-stream "/Users/will/Downloads/BPTUMPicturesPNG/TUM1001K.png")
:headers {"Authorization" (str "Bearer " (System/getenv "CONTENTFUL_MANAGEMENT_KEY"))}
:content-type "application/octet-stream"}))
Input-stream seems okay
(io/input-stream "/Users/will/Downloads/BPTUMPicturesPNG/TUM1001K.png")
=> #object[java.io.BufferedInputStream 0x36e4cf6f "java.io.BufferedInputStream@36e4cf6f"]
what about directly using the string instead of creating it using getenv (for now) - or at least verifying that CONTENTFUL_SPACE_ID is space-id
Um... removing the --data-binary
param from curl
command returns 400, not 404, so it definitely seems to be something wrong with my clojure code, and not server weird 404s when no file is uploaded :thinking_face:
Will do ✅
yeah -that would likely explain it
unless CONTENTFUL_SPACE_ID was spaces/space-id
of course
this is why people hate strings
Haha, yeah! that will be it! Thank you rubber ducks!
Yeah, that works!
It's funny when you're learning new tech, libraries, etc, how you assume failures are down to your lack of knowledge about that thing, rather than the basics!
there's a clj-http-fake lib, that is useful for separating this kind of issue from server misbehavior https://github.com/myfreeweb/clj-http-fake
Oh, and thanks for suggesting removing commons; it's great to remove dependencies!
It certainly hasn't for me either, in my 20 years commercial programming!
how does macroexpansion interact with laziness? For instance do I need a doall
around the for
here?
(defmacro defstyle
[style-id & styles]
`(defstyle* ~style-id
~@(for [style styles]
(walk/postwalk (fn [node]
(if (map? node)
(prefix node)
node))
style))))
the compiler is eager, so you shouldn't need doall
this all depends on what defstyle* does of course - some forms aren't eager of consuming their arguments...
but the absence or presence of doall wouldn't change this
Has anyone tried to write Kafka Streams code in Clojure? I have googled a few libraries, but haven't found any reports of what works and what does not in reality.
Dunno if this helps but this one was posted to the Clojure reddit a few weeks ago: https://www.reddit.com/r/Clojure/comments/aa12wz/ziggurat_a_stream_processing_framework_to_build/
my company open sourced our kafka-streams library recently, https://github.com/FundingCircle/jackdaw
interesting. I subconsciously used this as a feature in a test for months now…
user=> (str/includes? {:a 1} "1")
true
if only that worked in real life
“I put a chainsaw in my toaster and it accidentally came out as toast”
Instaparse question: I have an existing yacc/lex grammar; I assume the yacc one is the least strenuous to port over (there's no embedded code besides yyerror
), I'd like to use this with instaparse which takes EBNFs -- any chance someone has done something like that and has a converter laying around? I feel like as soon as I'm writign a file called yacc.cfg and lex.y I have taken a wrong turn
https://github.com/jrester/EBNF.cr claims to do this but doesn't work.
(the endgame here is being able to parse C headerifles and automagically generating the right Clojure bindings)
you might try using, uh, I forget, that tool that generates jni bindings, and then relective over the java to generate the clojure
I just checked (doc eduction)
and (source eduction)
and their doc strings differ. I didn't think this was possible?
user> (doc eduction)
-------------------------
clojure.core/eduction
([xform* coll])
Which lib is better for clojure selenium? https://github.com/komcrad/webdriver or https://github.com/igrishaev/etaoin or other
the arg list in the source is
[& xforms]
(Eduction. (apply comp (butlast xforms)) (last xforms)))
the arglists meta overrides
the override is trying to convey something impossible to say in the actual arg list
which is a leading vararg
(side note: :arglists
can confuse tooling that tries to use that information to check source code -- such as Eastwood -- since the :argslists
metadata doesn't have to represent a valid actual call)
@seancorfield it can also help it. 🙂
(defmulti ^{:arglists '([a-map])} do-thing :key)
Eastwood can't check defmulti
calls without a hint? I didn't know that.
defmulti
can’t attach :arglists
meta to the var because there’s no general way to derive it from the dispatch-fn.
Thought so. This result was confusing:
(let [xs [(iterate (fn [x]
(inc x)) 0)
(iterate (fn [x]
(inc x)) 0)]]
(map realized? xs))
=> (true true)
Guessing realized?
must be talking about something else here?yeah - I wouldn't trust realized? for lazy inputs - it's reliable for delay
or promise
objects
@U083D6HK9 - I had to play with this more - it seems like it kind of works but not for the head of the collection(?)
(cmd)user=> (def l (iterate println nil))
#'user/l
(cmd)user=> (realized? l)
true
(cmd)user=> (realized? (rest l))
false
(ins)user=> (realized? (nthrest l 2))
nil
false
(cmd)user=> (realized? (rest l))
true
that nil after calling nthrest shows one element being realized
oh! I'll try another thing to test that
yeah - you figured it out
(ins)user=> (def l (repeatedly #(println :realized)))
#'user/l
(ins)user=> (realized? l)
false
(cmd)user=> (realized? (rest l))
:realized
false
(cmd)user=> (realized? (rest l))
false
(cmd)user=> (realized? (nthrest l 2))
:realized
false
(cmd)user=> (realized? (rest l))
true
Yeah, the first value in a lazy sequence generated by iterate
has been “produced”, and thus the sequence vacuously satisfies realized?
I tested by adding println inside those function bodies - not even the first element is being produced