workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
clojurians
clojure
yeah, waiting for all the pings is weird if the pings are looping…
2017-12-11T16:25:37.000219
Margaret
clojurians
clojure
well, is there any way to pass reference futre itself to ping-host?
2017-12-11T16:26:43.000066
Lois
clojurians
clojure
so I have all futures references and kill them all from outside
2017-12-11T16:27:25.000016
Lois
clojurians
clojure
maybe you want core.async or something - it sounds like your flow of data / execution design is still fuzzy?
2017-12-11T16:28:22.000283
Margaret
clojurians
clojure
because if there’s a loop in a future, what does someone wait on when waiting on a ping?
2017-12-11T16:28:38.000715
Margaret
clojurians
clojure
It´s in that way because I have to compare all the results with each other
2017-12-11T16:29:21.000466
Lois
clojurians
clojure
but if it’s a loop you have multiple results to compare -
2017-12-11T16:29:55.000125
Margaret
clojurians
clojure
the loop is only when waiting ssh session until ends
2017-12-11T16:31:13.000437
Lois
clojurians
clojure
If I understand what you mean :slightly_smiling_face:
2017-12-11T16:31:49.000360
Lois
clojurians
clojure
so really what you want is one function that simultaneously opens an ssh connection and also loops on a ping, and then based on the ping time conditionally restarts the ssh connection?
2017-12-11T16:32:58.000034
Margaret
clojurians
clojure
so one thread does `(ssh host)` and the other does `(when (ping-takes-longer host reference) (restart-ssh host))` ?
2017-12-11T16:33:37.000723
Margaret
clojurians
clojure
this is happening already, I want to know how to stop it when it´s runnig, any time I want
2017-12-11T16:34:23.000720
Lois
clojurians
clojure
so the thread you want to cancel isn’t the ping, it’s the ssh
2017-12-11T16:35:23.000118
Margaret
clojurians
clojure
I´m saying ping and ssh because it´s remote ssh ping
2017-12-11T16:36:13.000156
Lois
clojurians
clojure
I have to ssh to some router/firewall and get the output ping from it
2017-12-11T16:37:21.000577
Lois
clojurians
clojure
this is working already, but I have stop control from outside
2017-12-11T16:38:04.000646
Lois
clojurians
clojure
that came from kill sign
2017-12-11T16:38:24.000705
Lois
clojurians
clojure
then store the future somewhere that the code that wants to cancel can call `cancel-future` on it?
2017-12-11T16:38:41.000132
Margaret
clojurians
clojure
yes, but how can I get the references of `futres` from that maps?
2017-12-11T16:39:33.000326
Lois
clojurians
clojure
`(-&gt;&gt; ["<http://www.google.com|www.google.com>" "<http://www.microsoft.com|www.microsoft.com>"] (mapv #(future (ping-host %))) (mapv #(deref %)))` using other function outside future?
2017-12-11T16:41:32.000006
Lois
clojurians
clojure
`(-&gt;&gt; ["<http://www.google.com|www.google.com>" "<http://www.microsoft.com|www.microsoft.com>"] (mapv #(store-future (future (ping-host %)))) (mapv #(deref %)))` ?
2017-12-11T16:41:56.000772
Lois
clojurians
clojure
you need a let block to get the future itself
2017-12-11T16:43:21.000163
Margaret
clojurians
clojure
`(let [hosts ["<http://www.google.com|www.google.com>" "<http://www.microsoft.com|www.microsoft.com>"] futures (mapv #(future (ping-host %)) hosts)] {:futures futures :results (mapv deref futures)})`
2017-12-11T16:44:35.000140
Margaret
clojurians
clojure
that way you can get results you can check, and also the futures
2017-12-11T16:44:45.000533
Margaret
clojurians
clojure
yes, you right, but I have to use some atom passed from outside to use it in other stoping function. Thanks alot
2017-12-11T16:47:04.000240
Lois
clojurians
clojure
``` (defn update-something [stack f] (conj (pop stack) (f (peek stack)))) ``` how should I name this function? neither -last nor -first makes sense since stack can either be list or vector
2017-12-11T17:18:14.000601
Berry
clojurians
clojure
update-top ? is that the best?
2017-12-11T17:18:26.000206
Berry
clojurians
clojure
<@Berry> poke?
2017-12-11T17:21:51.000394
Bibi
clojurians
clojure
or some combination of that with another word
2017-12-11T17:22:09.000293
Bibi
clojurians
clojure
In case anyone cares, I’ve submitted a pull request to `twitter-api` that adds support for `media/upload`, including chunked upload, which means you can now post tweets with images, videos and animated gifs from clojure: <https://github.com/adamwynne/twitter-api/pull/77>
2017-12-11T19:49:26.000290
Alline
clojurians
clojure
so i notice that my code has this pattern around quite a bit ```(if (some? x) (do-stuff x) x)``` what's the idiomatic way to address this more elegantly ? am i simply oblivious to a function that exists for this ?
2017-12-12T02:49:43.000040
Catharine
clojurians
clojure
i guess ```(some-&gt; x do-stuff)``` does the trick ?
2017-12-12T02:50:34.000019
Catharine
clojurians
clojure
`some?` returns true if its argument isn't nil … depends on whether you really care about nil or logical false. If logical false is ok: ```(when x (do-stuff x))``` also works
2017-12-12T03:32:12.000034
Buck
clojurians
clojure
it will return nil in the case where the test doesn't return logical true, so be aware of that ...
2017-12-12T03:32:51.000207
Buck
clojurians
clojure
Your else case always returns nil here I guess, so there's that.
2017-12-12T03:42:50.000062
Jodie
clojurians
clojure
yeah i think i gave a bit wrong example
2017-12-12T03:43:26.000167
Catharine
clojurians
clojure
<http://clojuredocs.org/clojure.core/when-some> This is useful if there's an expression involved
2017-12-12T03:43:53.000302
Jodie
clojurians
clojure
i think this better illustrates the pattern: ```(if (condition x) (do-stuff x) x)```
2017-12-12T03:44:03.000401
Catharine
clojurians
clojure
i ended up rewriting this as ```(cond-&gt; x (condition x) (do-stuff))```
2017-12-12T03:45:25.000242
Catharine
clojurians
clojure
Struggling to get `clj` / tools.deps to work, getting: `Error building classpath. Unknown coordinate type for org.clojure/clojure: {:type :mvn, :version "1.8.0"}` Anyone know why that could be?
2017-12-12T04:15:19.000164
Renata
clojurians
clojure
Yeah, I find myself doing that a lot, don't like it either.
2017-12-12T04:35:47.000372
Jodie
clojurians
clojure
<@Renata> what's your command line?
2017-12-12T04:36:18.000055
Fe
clojurians
clojure
and your deps.edn?
2017-12-12T04:36:38.000454
Fe
clojurians
clojure
There's a macro by a JUXTer called condas-&gt; which solves this a little I think.
2017-12-12T04:36:43.000053
Jodie
clojurians
clojure
<@Fe> just `clojure` or `clj`. I do have a deps.edn which contains this: ``` {:deps {clj-time {:mvn/version “0.14.2”}}} ```
2017-12-12T04:36:48.000283
Renata
clojurians
clojure
does it work from an empty directory?
2017-12-12T04:37:05.000143
Fe
clojurians
clojure
(which is copied from the guide)
2017-12-12T04:37:09.000076
Renata
clojurians
clojure
same error in empty directory
2017-12-12T04:37:29.000408
Renata
clojurians
clojure
is it the latest version? (`brew upgrade clojure`)
2017-12-12T04:37:31.000250
Fe
clojurians
clojure
I did reinstall / make sure it’s up to date
2017-12-12T04:37:54.000011
Renata
clojurians
clojure
what's the output of `clojure -Sverbose`
2017-12-12T04:38:04.000156
Fe
clojurians
clojure
(also `which clojure`)
2017-12-12T04:38:12.000085
Fe
clojurians
clojure
check the files in ```config_paths = /usr/local/Cellar/clojure/1.8.0.193/deps.edn /Users/me/.clojure/deps.edn deps.edn```
2017-12-12T04:38:31.000115
Fe
clojurians
clojure
you may need to delete `~/.clojure`
2017-12-12T04:38:40.000248
Fe
clojurians
clojure
that was it, thanks!
2017-12-12T04:38:56.000469
Renata
clojurians
clojure
:information_desk_person:
2017-12-12T04:39:01.000316
Fe
clojurians
clojure
I looked for the user config but didn find it (thought I never created one so probably just didn’t look hard enough)
2017-12-12T04:39:34.000328
Renata
clojurians
clojure
Would be nice if the error indicated which file the error comes from
2017-12-12T04:40:02.000393
Renata
clojurians
clojure
The config is an overlay of the 3 edn files laid on top of each other, so this might be difficult
2017-12-12T04:40:33.000042
Fe
clojurians
clojure
But maybe it could say "Error: ... - the config files used were x, y and z"
2017-12-12T04:42:18.000257
Fe
clojurians
clojure
yeah I guess that would already be a good improvement
2017-12-12T04:43:11.000026
Renata
clojurians
clojure
there's <https://dev.clojure.org/jira/browse/TDEPS>
2017-12-12T04:43:34.000156
Fe
clojurians
clojure
<@Fe> do you know if the `clj` command does any preprocessing of the deps.edn file?
2017-12-12T04:47:15.000348
Renata
clojurians
clojure
``` (tools-deps/resolve-deps (read-string (slurp "deps.edn")) {}) ``` trying this but getting `Unknown coordinate type for clj-time: #:mvn{:version “0.14.2”}`
2017-12-12T04:47:58.000060
Renata
clojurians
clojure
just running `clj` works fine
2017-12-12T04:48:06.000197
Renata
clojurians
clojure
is it because of the overlay effect I mentioned?
2017-12-12T04:48:56.000267
Fe
clojurians
clojure
Try using this instead: ```(-&gt;&gt; "/usr/local/Cellar/clojure/1.9.0.273/deps.edn /Users/me/.clojure/deps.edn deps.edn" split-by-space (map slurp) (map read-string) (apply merge))```
2017-12-12T04:50:06.000138
Fe
clojurians
clojure
(pseudo-code)
2017-12-12T04:50:20.000572
Fe
clojurians
clojure
not sure how that explains the error message though
2017-12-12T04:51:36.000091
Fe
clojurians
clojure
same issue
2017-12-12T04:52:07.000020
Renata
clojurians
clojure
not sure then
2017-12-12T04:52:43.000091
Fe
clojurians
clojure
FWIW all files seem to be using the same syntax as my local `deps.edn`
2017-12-12T04:52:49.000259
Renata
clojurians
clojure
There's <#C6QH853H8|tools-deps> as well btw - Alex is hanging out there
2017-12-12T04:54:30.000340
Fe
clojurians
clojure
``` (defn vec-&gt;map [v] (into {} (reverse (for [[i k] (keep-indexed vector v)] [k i])))) (vec-&gt;map [:a :b :a :d]) (comment {:d 3, :a 0, :b 1}) ``` is there a builtin for this/ it builds a map of "first of index" for each value
2017-12-12T07:59:46.000090
Berry
clojurians
clojure
I actually just wrote this code for a coercer.
2017-12-12T08:40:55.000026
Jodie
clojurians
clojure
<@Berry> ``` (vec-&gt;map [:a :b :c]) =&gt; {:c 2, :b 1, :a 0} (zipmap [:a :b :c] (range)) =&gt; {:a 0, :b 1, :c 2} ``` but I assume I'm missing some aspect of the requirement here?
2017-12-12T09:11:07.000244
Joette
clojurians
clojure
<@Joette> that will give you the last index instead of the first if you have duplicates in the array
2017-12-12T09:12:02.000474
Noella
clojurians
clojure
ah, ok just saw the second `:a`
2017-12-12T09:12:21.000430
Joette
clojurians
clojure
here’s my variation: ```(reduce (fn [m [i k]] (if (get m k) m (assoc m k i))) {} (map-indexed vector [:a :b :a :d]))```
2017-12-12T09:18:06.000432
Noella
clojurians
clojure
you could still go zipmap: ``` (defn f[v] (zipmap (reverse v) (reverse (range 0 (count v))))) ```
2017-12-12T09:21:24.000309
Joette
clojurians
clojure
that will be slow if you have large sequences though
2017-12-12T09:22:52.000155
Noella
clojurians
clojure
how about: ``` (defn f[v] (zipmap (rseq v) (range (dec (count v)) -1 -1))) ``` ? `rseq` is constant time, range is fast as it's bound and not explicitly reversed etc
2017-12-12T09:31:01.000859
Joette
clojurians
clojure
a simplistic bench seems to put them more or less on equal footing, though it seems that rseq is picky and &lt;edited&gt;only lkes vectors and sorted maps&lt;/edited&gt;: ``` (def my-v (mapv (comp keyword str) (range 1000000))) =&gt; #'user/my-v (defn f[v] (zipmap (rseq v) (range (dec (count v)) -1 -1))) =&gt; #'user/f (defn g [v] (reduce (fn [m [i k]] (if (get m k) m (assoc m k i))) {} (map-indexed vector v))) =&gt; #'user/g (take 2 (time (f my-v))) "Elapsed time: 504.559267 msecs" =&gt; ([:821597 821597] [:323982 323982]) (take 2 (time (g my-v))) "Elapsed time: 744.353442 msecs" =&gt; ([:821597 821597] [:323982 323982]) ```
2017-12-12T10:00:00.000047
Joette
clojurians
clojure
neat benchmark!
2017-12-12T10:19:48.000580
Noella
clojurians
clojure
can you give it a shot with a `transient` map for the `reduce` version?
2017-12-12T10:20:05.000809
Noella
clojurians
clojure
Might also consider using reduce-kv: ``` (reduce-kv assoc {} [4 3 2 1]) ```
2017-12-12T11:10:27.000862
Sandy
clojurians
clojure
I am trying to extend a Java class (add a new method) and call a private method of that class inside it. I tried with `proxy`, I can override an existing method (not a new one) - but can’t seem to access `this` in the overridden code. Is `gen-class` my only option?
2017-12-12T11:55:13.000168
Jonnie
clojurians
clojure
With this sort of OOP gook, it's often better to write your code in Java and then call that via Clojure.
2017-12-12T12:12:06.000619
Sandy
clojurians
clojure
Or use gen-class, but that's rather hard to get right
2017-12-12T12:12:18.000638
Sandy
clojurians
clojure
<@Jonnie> if you go the java route, I highly suggest trying this lein plugin: <https://github.com/ztellman/virgil> it autoreloads Java classes when the .java files change. Makes playing with Java/Clojure interop a lot faster.
2017-12-12T12:13:14.000684
Sandy
clojurians
clojure
Appreciate the advice, thanks :smile: (yeah gen-class doesn’t look like the most welcoming bit of Clojure)
2017-12-12T12:14:48.000610
Jonnie
clojurians
clojure
yeah stay away from gen-class
2017-12-12T12:15:30.000544
Kareen
clojurians
clojure
there's <https://dev.clojure.org/jira/browse/CLJ-1255> which would help in most cases where people now reach for proxy/gen-class
2017-12-12T12:16:25.000247
Kareen
clojurians
clojure
if you care, vote for it
2017-12-12T12:17:07.000704
Kareen
clojurians
clojure
it’s an option to define a protocol with the method you want to implement, then proxy the class and also that protocol
2017-12-12T12:19:49.000443
Margaret
clojurians
clojure
yes the real problem is access to `this` private methods (overriding an existing method is fine, performance is not a problem) I am actually considering a thin separate Java wrapper library now
2017-12-12T12:21:33.000178
Jonnie
clojurians
clojure
I would probably have used `CLJ-1255` if it was there already - so will upvote even though I can’t comment on the actual implementation (EDIT - will upvote once I find my login back)
2017-12-12T12:22:24.000788
Jonnie
clojurians
clojure
Thanks all :smile:
2017-12-12T12:22:35.000015
Jonnie
clojurians
clojure
bronsa: do you think you could write that as a macro and release it as a library outside of core?
2017-12-12T12:24:38.000389
Rebeca
clojurians
clojure
I could
2017-12-12T12:24:46.000648
Kareen