This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-01
Channels
- # 100-days-of-code (5)
- # adventofcode (234)
- # aleph (13)
- # announcements (2)
- # architecture (3)
- # bangalore-clj (1)
- # beginners (312)
- # calva (7)
- # cider (6)
- # cljdoc (3)
- # cljs-dev (30)
- # cljsrn (2)
- # clojure (40)
- # clojure-austin (2)
- # clojure-dev (65)
- # clojure-greece (1)
- # clojure-italy (29)
- # clojure-kc (1)
- # clojure-russia (2)
- # clojure-uk (26)
- # clojurebridge (1)
- # clojurescript (4)
- # cursive (11)
- # data-science (1)
- # datomic (43)
- # docker (1)
- # duct (7)
- # emacs (3)
- # figwheel-main (7)
- # fulcro (8)
- # garden (3)
- # graphql (8)
- # hyperfiddle (4)
- # off-topic (10)
- # other-languages (12)
- # pathom (4)
- # portkey (1)
- # remote-jobs (3)
- # rum (8)
- # shadow-cljs (40)
- # tools-deps (68)
- # unrepl (2)
- # vim (5)
So question.. when you wrap the request as shown here, how does the database handle the open/closing of the connection? Is the connection always open? This is a postgresql database, so it might be my lack of postgresql knowledge, but I was curious what happens to the connection for each user connecting and disconnecting.
I dunno where you are getting that code from, but I wouldn't be surprised if they assume a connection pool
but a lot depends on the value of db, and even what kind of db it is, what library you are using to talk to it
So I already stated that it was a Postgres database.
The value of db
is:
(def db (or
(System/getenv "DATABASE_URL")
"jdbc:))
The libraries used are:
[org.postgresql/postgresql "42.2.5"]
[org.clojure/java.jdbc "0.7.8"]
The code came from an Eric Normand video.
For future reference, just simply ask for the additional information needed. Obviously if I knew all the information needed for any one of the many people in here to assist, I would have posted it. Thanks.with-open closes the object you open when execution leaves that block
the point about connection pools is that the right place to manage reuse of connection objects is via some connection pool, not by replacing the usage of with-open (which in the case of a connection pool will close a connection-pool view of a connection but let the pool decide how many connections to keep open and how to use them)
hey folks, can you tell me if a set can be transformed in vector? if yes, one to achieve it?
@quieterkali sure!
user=> (vec #{1 2 3})
[1 3 2]
that’s strange, works for me:
user=> (require '[clojure.string :as str])
nil
user=> (str/starts-with? "abc" "a")
true
What operating system are you using, and what method are you using to start your REPL?
I'm not the best advisor on using Clojure on Windows, but I will mention that light table has not been updated in a while, and might lead to some rough edges that won't be addressed any time soon (if ever).
If you have Windows 10 with WSL, I have heard that can in some cases provide a more Linux-like experience, where Clojure environments tend to be a more tested and polished than on Windows.
I asked a question on stack overflow about rendering comment-trees. maybe if you have a second, take a look, I'd appreciate any help on the topiic ^_^ https://stackoverflow.com/questions/53571904/render-comment-tree-with-rum
it's a datastructure just one level deep, but some entries might require the addition of further entries...
{:content "hax" :id 33 :comments [34 35}
would pull out 33, 34, and 35, and potentially any comments 34 and 35 have...
accumulators... googles eagerly
@quieterkali 'set element" ?
i wanted to use reduce to go through each set values, and perform some oparation and store the result as accumulate avector
I don't know what set values is for, it sounds feasible
sure, maybe you do reduce-kv
@quieterkali Maybe just tell what you’re trying to do?
want to come up with best way to go over a vector where i will pass each value to a function which will return me another vector, the i will just use conj
add the vector to the reduce accumulator
sounds like a neural net o.O
when you say "`conj` add the vector to the reduce accumulator" do you mean the original reduce fxn's accumulator?
you could have a global atom store the accumulator state, and then toy with it from separate functions
(mapcat (fn [i]
(range i))
(range 10))
=> (0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 6 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8)
so take the vector, go through each values of it, retrieve the corresponding vector, then can use mapcat to concat
is there anyway to find out from code if the code itself is being ran with a specific leiningen profile? the only thing I came up with is to conditionally include a certain source directory, which can add namespaces which you can check for
I have
public abstract class KeyStoreKeyingDataProvider implements KeyingDataProvider
{
/**
* Provides a password to load the keystore.
*/
public interface KeyStorePasswordProvider
{
char[] getPassword();
}
How do I access KeyStorePasswordProvider
from clojure? Trying to extend this with proxy
I tried KeyStoreKeyingDataProvider/KeyStorePasswordProvider
but it does not find the classhey guys 🙂 , let's say i have 2 vectors [1 2 4 3 2 5 5 1]
and [1 3 4]
and want this output [2 2 5 5]
off the top of my head, without checking: (remove #(some (fn [x] (= x %)) [1 3 4]) [1 2 4 3 2 5 5 1])
for each element in longer-list, if it exists in smaller-list, remove it, otherwise continue
oh yeah, it's not good lol
computational science is mostly sequential math over collections
hey guys, it me again, need you to take a lokk to this and tell if there is a better way to acheive the same thing
so it’s a different return type, but what you’re asserting is that you need indexed access as well
(sort-by (fn [[k v]]
[v k])
(fn [a b]
(compare b a))
results)
matches your sort order exactlycurious why you need a sorted hashmap as opposed to a hasmap + sorted list of key-values
It seems like at point you don't need it to be a map. You just need to interate through the key value pairs in a sorted order
i am facing a problem with this snippet code. What is it suppose to give me back after finish running? A vector?
If you need to build up a result, I would use loop/recur
, an atom in a doseq
, or doall
I wasn’t sure what you meant, so I just stuck that in there as a placeholder for whatever you want to do w/ each user
I am so happy, I figured out how to nest comments like I was wondering earlier/forever.
Sure thing 😄
rum render of data. top half is "no comments for this entry, so print a dead-ended output of its contents, author" bottom half is: there are comments, print the relevant fields and when it gets to "comments" map the render-item function back over the cids you got [in that frame]
example rendering of output in html
my CSS for .padleft is also relevant: it's very brief
indent yo comment tree
So yeah! those 4 images can make a pro comment-tree maker out of anybody ^_^
So something to consider: it’s doing a linear scan for each render-item
— (filter ... posts)
You can eliminate that if you store your posts like so:
{77 {:id 77, :contents "" ... }
33 {:id 33, :contents "" ...}}
Neat. hmm
post-id {post-map}
Okay, and how would I alter my code to shortcut that lookup instead of using filter
But not (:pid @posts)
okay, that's a subtle distinction where you can use (get ..)
and the inverted syntaqs don't werk
because (pid @posts)
would kinda be absurd..
Haha! right!
i'll seven your web app to death
Ah. and not to dereference multiple times.
no mud no lotus
Interesting
thank you very much for pointing that out & other points
Here’s a bonus function for indexing by id:
(defn idx-by-id [id-key coll]
(into {}
(map (fn [{id id-key :as item}]
[id item]))
coll))
so that will make a map that looks like {"77" {:itemzzz...}} ?
Groovy.
wow that was painless
in my case :id and @posts
lazy eval: i only grow coffee beans when i want to drink coffee
why isn't (matrix)
in clojure.core
maybe a better example:
(let [myseq (map (fn [i]
(println i)
(inc i))
[1 2 3])]
(println "foo"))
and w/ side effects (e.g. looking up users in a db), you generally want to control when that happens
http://clojure-doc.org/articles/language/laziness.html looks pretty good
@quieterkali and @sova Since it seems like ya’ll are trying to skill up on clojure, I’d like to mention my stream I started last week: https://www.twitch.tv/timpote

I suppose it would be useful if I mentioned that on Monday I’m planning to cover a lot of clojure topics: imperative vs functional, loop/recur, reduce, transducers
What is an idiomatic way of waiting for multiple chans to finish?
Do you want only the first result back, or do you want the result of all chans?
I want the result of all chans
I’m looking for something like Promise.all in Javascript
a channel is not even close to a Promise in Javascript, are you sure you don't want a future instead? channels aren't really things where you get "a result" from, as they're supposed to be continously running
Do you need exactly one (or balanced) results from all channels, or is it okay to be unbalanced?
but yeah, to get one item from each channel you can simply do (map <! channels)
where channels
is your list of channels
Here is a snippet:
(defn call!
[db configuration]
(let [chans (map (fn [_] (async/thread (seed-db! db configuration)))
(range 0 (:times configuration)))]
(async/<!! (async/merge chans))
(println "All threads execution finished" chans)))
What I want to achieve is to wait for all threads to finish
I don’t care what is a result of execution since it only seeds the DB
So from a more abstract perspective, you have n tasks to complete asynchronously, and you want to know when they are all done. Right?
Exactly @UANMXF34G
pmap
might be a good approach that doesn't require core.async at all. https://clojuredocs.org/clojure.core/pmap#example-542692cdc026201cdc326cf4
pmap and map are lazy, so if you really want to use map you have to do (doall (map <!! chans))
(doall (pmap seed-db! db-configurations)
gives you the parallelism without using channels at all, as an alternative approach. If you also want to return immediately and check the result later you can wrap it in future
to get the asynchronicity.
Something about channels seems to imply that values need to be conveyed around, which isn't what's happening in this case so it doesn't seem quite right. Either will work just fine of course.
but I think I still prefer the doseq approach, as using map for side effects is discouraged
This is a funny case where the synchronous version doesn't return anything, but the asynchronous version kind of does in a way? The async version needs to return some signal that indicates the tasks are done, whether that's a promise, or nil
on a channel, or a collection of nil
s for each of the tasks. Synchronous code always has an implicit "I'm done doing the thing you said to do" signal in the form of the function returning execution control to the calling context. When a task is called asynchronously, this signal needs to be reified in some form.
For a single async task, the idiomatic thing is probably (future some-task)
. For the parallel collection version, I'm leaning towards
(let [futures (doall (map #(future some-task) task-configs))]
(doseq [fut futures] (deref fut)))
This doesn't feel terribly idiomatic, maybe because performing a bunch of side effects and returning nil
is not very idiomatic Clojure. 😉Nice guys! Thank you all 🙂