workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
haha, thanks, and no I'm still at it, brute forcing a bit ``` (-> (ok (str {:recording-url signed-url})) (assoc "Header" {"Content-Type" "text/html"}) (assoc "Headers" {"Content-Type" "text/html"}) (assoc "Content-Type" "text/html") (assoc :Header {"Content-Type" "text/html"}) (assoc :Headers {"Content-Type" "text/html"}) (assoc :header {"Content-Type" "text/html"}) (assoc :headers {"Content-Type" "text/html"}) (content-type "text/html")) ```
2017-11-21T20:02:28.000190
Lori
clojurians
clojure
as I pointed out in the link to the code, setting the content-type to "text/html" or anything else, will not effect wrap-json-response
2017-11-21T20:03:24.000039
Rebeca
clojurians
clojure
If you set `:headers {"Content-Type" "text/html"}` then `wrap-json-response` will not overwrite that -- as I showed in my screenshot.
2017-11-21T20:06:25.000117
Daniell
clojurians
clojure
<@Lori> Your code has weird indentation!
2017-11-21T20:06:57.000154
Daniell
clojurians
clojure
oh sorry, it's indented where it is, and when I paste it, I'm missing the whitespace before the first open paren
2017-11-21T20:07:37.000009
Lori
clojurians
clojure
Ah, ok :slightly_smiling_face:
2017-11-21T20:07:49.000066
Daniell
clojurians
clojure
and re your help, thank you, it must be something else in my code, I think I'll attack it tomorrow with fresh eyes
2017-11-21T20:08:04.000138
Lori
clojurians
clojure
But, anyway, as I showed in the REPL session above, `(-&gt; (ok {...}) (content-type "text/html"))` will "do the right thing" in that you'll get your desired content type and still get a body that is the JSONification of the data structure.
2017-11-21T20:08:50.000039
Daniell
clojurians
clojure
(so perhaps I'm not understanding what you're trying to do?)
2017-11-21T20:10:44.000114
Daniell
clojurians
clojure
well, i'm trying the same code as you, but within a big code base, and for some reason that `Content-Type: text/html` is getting replaced with `Content-Type: application/json`
2017-11-21T20:11:44.000023
Lori
clojurians
clojure
I'm sure it'll be surprisingly simple when I find it :face_with_rolling_eyes:
2017-11-21T20:12:07.000291
Lori
clojurians
clojure
Er, I thought you wanted it the other way around?
2017-11-21T20:12:12.000139
Daniell
clojurians
clojure
yes, oops (fixed)
2017-11-21T20:12:31.000219
Lori
clojurians
clojure
I'd write a little debugging middleware function that displayed a message and the content type and thread that into your stack of middleware in between each layer.
2017-11-21T20:13:31.000262
Daniell
clojurians
clojure
that's a good idea, that'll be a good place to stage round 2 of this battle :slightly_smiling_face:
2017-11-21T20:14:36.000051
Lori
clojurians
clojure
Middleware can be pretty sensitive to ordering -- so I tend to rely on the ring-defaults library for the basic stack.
2017-11-21T20:19:30.000254
Daniell
clojurians
clojure
when using predicates with clojure spec, is there a way, instead of just returning true/false, also return a error msg on false ?
2017-11-21T22:15:31.000187
Berry
clojurians
clojure
I can't do `#(apply and %)` since `and` is a macro. What is the idiomatic way to logic-and a list ?
2017-11-21T23:31:21.000110
Berry
clojurians
clojure
`every?`?
2017-11-21T23:31:54.000160
Jonas
clojurians
clojure
`(every? identity coll)` would work
2017-11-21T23:33:02.000035
Jonas
clojurians
clojure
About middleware ordering, I have been playing with middleware as data, just like Pedestal interceptors. I think we can solve most of the middleware ordering / debugging problems with data and a mw-composer. Plan: instead of just functions, mw are maps with `:wrap` key with the actual mw-function. In addition, they can have things like `:name`, `:spec`, `:produces` and `:requires`. Middleware-chain is vector of maps, which is composed into actual mw-function by the a composing function producing zero runtime penalty. The intermediate mw data format allows things like documentation extraction, automatic/manual re-ordering, adding debug-mw’s between all mw’s in dev etc.
2017-11-22T01:07:11.000116
Alla
clojurians
clojure
we are building up a new routing library, which supports this (for both mw &amp; interceptors), but I’m wondering could it be a more general solution for Ring in the future? ping <@Ramonita>.
2017-11-22T01:10:02.000218
Alla
clojurians
clojure
(and there is <#C7YF1SBT3|reitit> channel for the new lib if someone is interested in)
2017-11-22T01:11:12.000287
Alla
clojurians
clojure
And <@Lori> there is also Muuntaja, which does JSON content negotiation like ring-json, but also for other formats too (EDN, Transit). It has a lot of options that the endpoint can set to override the defaults. One can change just the response content-type, request a different response encoding, or disable the response encoding totally, see <https://github.com/metosin/muuntaja#response>. c-api 2.* uses this internally.
2017-11-22T01:22:18.000019
Alla
clojurians
clojure
When I'm working with XML and zippers, is there any way to tell if the point I've got to in the zipper is an Element (as opposed to a string or whatever) *without* converting to a node first?
2017-11-22T06:53:17.000356
Mallie
clojurians
clojure
At the moment I'm doing `(instance? clojure.data.xml.node.Element (zipper/node location))`. `(map? (zipper/node location))` also works for the cases I care about because an element is a map and other things aren't, but it'd be nice if there was some way I could do `(element? location)` without having to convert to a node myself
2017-11-22T06:54:44.000024
Mallie
clojurians
clojure
hi guys - what is the simplest way in a Clojure server to start new threads for some async processing? Preferably with threadpools, like using Java's `ExecutorService`. I am not expecting any return value from the submitted task. `future` seems tempting but I'm afraid that they are not cleaned up if I'm not dereffing them. Is there a convenient way achieving this? Or shall I use some interop to use Java ExecutorService with fns?
2017-11-22T07:15:22.000256
Mirna
clojurians
clojure
<@Mirna> what do you mean by not cleaned up ?
2017-11-22T07:36:39.000214
Rosia
clojurians
clojure
<@Mirna> <https://github.com/ztellman/manifold> uses an ExecutorService and will be there when you do need to use the return values :slightly_smiling_face:
2017-11-22T07:37:56.000247
Shameka
clojurians
clojure
is there any disadvantage to using `gensym` for making up arbitrary keys? my use case is that i have a list of strings and i want to remove certain ones after a pause. since strings can be duplicated i need to assign them some sort of identifier.
2017-11-22T07:44:54.000153
Zola
clojurians
clojure
Hi <@Rosia> I mean that the thread will remain in the memory, its stacktrace will consume the available stack and if I end up having too many, I could run out of memory
2017-11-22T07:49:58.000159
Mirna
clojurians
clojure
(with the understanding that gensym won't be unique across different instances of the same app, of course)
2017-11-22T07:50:52.000146
Zola
clojurians
clojure
`future` basically wraps the body in a `fn` and submits it to a unbounded thread pool Executor. If you don't use the result it will be candidate for GC as soon as it's done and the thread will likely be reused for subsequent computations
2017-11-22T07:53:46.000377
Rosia
clojurians
clojure
if you're familiar with java executors you should have no surprise with clojure.core `future`
2017-11-22T07:54:52.000400
Rosia
clojurians
clojure
<https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L6838>
2017-11-22T07:58:52.000027
Rosia
clojurians
clojure
thanks, awesome
2017-11-22T08:03:09.000080
Mirna
clojurians
clojure
Yes, executor here <http://aleph.io/codox/manifold/manifold.executor.html>
2017-11-22T09:00:47.000596
Lovie
clojurians
clojure
also cljs version <https://github.com/dm3/manifold-cljs>
2017-11-22T09:08:00.000022
Lovie
clojurians
clojure
:slightly_smiling_face: after a long while away from clojure, could someone benevolently remind me how do I stream process a file? e.g. reading one text line at a time without ever storing the entire file in memory?
2017-11-22T09:26:34.000629
Kalyn
clojurians
clojure
a reader + line-seq
2017-11-22T09:27:35.000016
Weston
clojurians
clojure
<https://clojuredocs.org/clojure.core/line-seq#example-542692cec026201cdc326de3>
2017-11-22T09:28:15.000261
Myles
clojurians
clojure
`with-open` a reader and `line-seq`
2017-11-22T09:28:33.000481
Myles
clojurians
clojure
Thanks guys. I must have encountered a severe form of programmer amnesia... even this simple adaptation of that source code which I was trying before posting here doesn't work for me ``` (with-open [rdr (<http://clojure.java.io/reader|clojure.java.io/reader> input-file-name)] (map println (line-seq rdr))) ```
2017-11-22T09:30:03.000018
Kalyn
clojurians
clojure
<@Kalyn> `map` is lazy
2017-11-22T09:30:43.000086
Cecilia
clojurians
clojure
ah right!
2017-11-22T09:30:48.000178
Kalyn
clojurians
clojure
I would use `doseq` instead for that
2017-11-22T09:31:32.000050
Cecilia
clojurians
clojure
`run!`
2017-11-22T09:32:10.000389
Myles
clojurians
clojure
I admit I used `doall`
2017-11-22T09:32:12.000112
Kalyn
clojurians
clojure
meaning: ``` (with-open [rdr (<http://clojure.java.io/reader|clojure.java.io/reader> input-file-name)] (doseq [line (line-seq rdr)] (println line))) ```
2017-11-22T09:32:31.000279
Cecilia
clojurians
clojure
but then again, if your real use case isn’t about doing side-effects then probably map is just fine
2017-11-22T09:33:28.000010
Cecilia
clojurians
clojure
why not `(run! println (line-seq rdr))`? :slightly_smiling_face:
2017-11-22T09:33:38.000309
Basil
clojurians
clojure
except presumably you want to force evaluation in order to read the file
2017-11-22T09:34:15.000690
Myles
clojurians
clojure
possibly because I’ve never actually used that :slightly_smiling_face: And it came in 1.7 it seems, wayyy too new stuff for me :oldman:
2017-11-22T09:34:19.000569
Cecilia
clojurians
clojure
I'll be stream writing a transformation of each line, so side-effects will be needed
2017-11-22T09:35:01.000094
Kalyn
clojurians
clojure
but is it only about side-effects?
2017-11-22T09:35:22.000175
Cecilia
clojurians
clojure
well writing an output file is (or entails) a side effect
2017-11-22T09:35:55.000265
Kalyn
clojurians
clojure
yeah right, well then either doseq or run! is your friend
2017-11-22T09:36:14.000284
Cecilia
clojurians
clojure
whereas `doall` will force the entire input seq and thusly the whole file into memory?
2017-11-22T09:37:02.000145
Kalyn
clojurians
clojure
yes, it forces the whole lazy sequence to be evaluated and keeps the head
2017-11-22T09:37:25.000725
Cecilia
clojurians
clojure
thanks, the doc for it makes much more sense now :slightly_smiling_face:
2017-11-22T09:37:53.000613
Kalyn
clojurians
clojure
thanks all
2017-11-22T09:48:27.000119
Kalyn
clojurians
clojure
ever had to re-learn a language yourselves? :slightly_smiling_face:
2017-11-22T09:50:25.000142
Kalyn
clojurians
clojure
Hi. Some one uses incanter? It shows empty windows instead of graphs. I tried to set different versions of it and clojure in project.clj. Also changed jdk7 to jdk8. Can't solve problem
2017-11-22T11:14:29.000538
Marcos
clojurians
clojure
This problem appears also on another computer, what I have
2017-11-22T11:15:01.000022
Marcos
clojurians
clojure
I found out what this happent when my wm is bspwm. With xfwm4 all works as intended...
2017-11-22T11:26:38.000510
Marcos
clojurians
clojure
Another apps on java awt and swing works fine
2017-11-22T11:33:31.000392
Marcos
clojurians
clojure
Where I should I write an issue? In bspwm repo or incanter repo?
2017-11-22T11:33:50.000639
Marcos
clojurians
clojure
Any idiomatic way of verifying a sequence is lazy? (e.g. in test code, or as an assertion)
2017-11-22T11:35:19.000004
Kalyn
clojurians
clojure
what's your use case? or what problem are you trying to solve
2017-11-22T11:45:34.000329
Willow
clojurians
clojure
I wish to make sure I've not accidentally yielded an unlazy collection after a lot of collection manipulations
2017-11-22T11:46:14.000328
Kalyn
clojurians
clojure
Otherwise my program would realize huge collections whereas it is supposed to do streaming work, to maintain a constant memory footprint
2017-11-22T11:47:01.000157
Kalyn
clojurians
clojure
Note that a LazySeq is usually Chunked anyway - check into transducers or core.async + transducers if you really want to do streaming work
2017-11-22T11:47:22.000209
Basil
clojurians
clojure
<@Basil> hmmm
2017-11-22T11:47:39.000111
Kalyn
clojurians
clojure
chunked?
2017-11-22T11:47:49.000906
Kalyn
clojurians
clojure
They evaluate a chunk of themselves (32 or so) items eagerly, for performance reasons.
2017-11-22T11:48:09.000566
Basil
clojurians
clojure
I don't care about a constant chunk size being realized behind the scenes
2017-11-22T11:48:15.000150
Kalyn
clojurians
clojure
Each item is small
2017-11-22T11:48:19.000122
Kalyn
clojurians
clojure
I guess I'm fine then
2017-11-22T11:48:35.000406
Kalyn
clojurians
clojure
But good to know, realizing by chunks makes more efficient
2017-11-22T11:49:21.000415
Kalyn
clojurians
clojure
i'm not sure how you could check this in general though. something could be fully realized and also a `clojure.lang.LazySeq`
2017-11-22T11:50:01.000340
Willow
clojurians
clojure
`(type (doall (map inc (range 0 2)))) =&gt;clojure.lang.LazySeq`
2017-11-22T11:50:48.000469
Willow
clojurians
clojure
<@Willow> there must be a way to know whether the type is lazy, regardless of its current state (realized or not)
2017-11-22T11:51:01.000010
Kalyn
clojurians
clojure
well lazyseq is a container amenable to lazy realization. but it does not change into a different type upon full realization
2017-11-22T11:51:31.000015
Willow
clojurians
clojure
well, maybe my answer is "check if the type is LazySeq" then
2017-11-22T11:52:02.000787
Kalyn
clojurians
clojure
but my example above shows that that is not sufficient
2017-11-22T11:52:12.000128
Willow
clojurians
clojure
the doall realizes the entire list
2017-11-22T11:52:18.000331
Willow
clojurians
clojure
if I assert this at a time where realization could not yet happen
2017-11-22T11:52:22.000605
Kalyn
clojurians
clojure
Such as before processing the sequence
2017-11-22T11:52:37.000285
Kalyn
clojurians
clojure
i guess so. but if the assertion is not falsifiable it does not introduce any confidence.
2017-11-22T11:53:07.000298
Willow
clojurians
clojure
well my point is to make sure a collection does not arrive at a certain function not lazy
2017-11-22T11:53:52.000389
Kalyn
clojurians
clojure
if it were to arrive as a non-lazy type, the assertion would falsify
2017-11-22T11:54:22.000119
Kalyn
clojurians
clojure
where is my line of thought wrong here?
2017-11-22T11:54:33.000058
Kalyn
clojurians
clojure
that would certainly be true, if something comes in as a vector is is guaranteed to be fully realized. the problem is that if something comes in as a LazySeq it is not guaranteed to _not_ be realized
2017-11-22T11:55:14.000046
Willow
clojurians
clojure
again, `(type (doall (map inc (range 0 10000000)))) =&gt; clojure.lang.LazySeq`
2017-11-22T11:55:24.000029
Willow
clojurians
clojure
oh I get what you mean now
2017-11-22T11:56:49.000808
Kalyn
clojurians
clojure
<@Kalyn> Do you mean something like this: ``` (let [x (map inc [0 1])] [(realized? x) (first x) (realized? x)]) ```
2017-11-22T11:57:11.000308
Randee
clojurians
clojure
my first thought ― I can check both the type is `LazySeq` and check `realized?` is false
2017-11-22T11:57:23.000184
Kalyn
clojurians
clojure
It'll tell you if it realized the *first* element of a lazy seq.
2017-11-22T11:57:32.000398
Randee
clojurians
clojure
nit: LazySeq is never chunked, it is possible that the underlying seq it wraps is chunked, but LazySeq itself knows nothing about chunking
2017-11-22T11:58:44.000297
Kareen
clojurians
clojure
`realized?` on lazy-sequences is practically useless, don't use it
2017-11-22T11:59:44.000043
Kareen