This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-25
Channels
- # bangalore-clj (5)
- # beginners (225)
- # boot (36)
- # cider (1)
- # clara (2)
- # cljsjs (1)
- # clojure (76)
- # clojure-belgium (1)
- # clojure-conj (1)
- # clojure-india (4)
- # clojure-italy (5)
- # clojure-korea (1)
- # clojure-russia (22)
- # clojure-spec (35)
- # clojure-uk (52)
- # clojurescript (67)
- # community-development (17)
- # core-logic (2)
- # cursive (2)
- # datascript (28)
- # datomic (44)
- # emacs (1)
- # funcool (3)
- # hoplon (14)
- # lein-figwheel (2)
- # leiningen (2)
- # luminus (3)
- # midje (3)
- # mount (2)
- # nyc (2)
- # om (54)
- # om-next (1)
- # onyx (30)
- # re-frame (57)
- # reagent (19)
- # ring-swagger (23)
- # slack-help (10)
- # spacemacs (2)
- # specter (1)
- # vim (23)
@oliv assuming you're talking about a Ring application, the recommended solution would be to add middleware that adds your global configuration to the Ring request. That decouples the dependency from the controller and from the service functions you call. It makes the entire call chain both more reusable and easier to test. And it doesn't change the signature of the controller either.
Hi, what's the performance of realizing an element in infinite sequence with many lazy functions stacked upon it. Take generating prime numbers for example, whenever a prime number is found, a remove function is added to the lazy remaining seq, e.g.
remove (fn[x] (= 0 (rem x primeNum))) remaining))
. To my understanding, when an element is realized, lot's of remove functions need to be called, e.g. for 10, remove function for 2, 3, 5 and 7 needed to be called. Do I understand it correctly?(defn save-explicit [file text]
(spit file text))
(def save (partial save-explicit “foo.txt”))
I’m, ahem, partial, to using to using partial
over anon-fns where the first param stays the same.
What’s the best way to have Clojure web servers communicate with each other?
@pupeno gnatsd has been working well for me, with clj-nats-async
@mccraigmccraig do you host a gnatsd server yourself?
@pupeno yeah, i have a gnatsd cluster deployed alongside the rest of my app components
I’m not sure how well that will work on Heroku.
ah, you might need to find a heroku addon then
Maybe I should use redis pubsub
i've never used it, but i heard redis pubsub was pretty good, probably given the usual redis caveats
@mccraigmccraig what redis caveats? I haven’t use redis yet.
have a read through https://aphyr.com/tags/Redis
problems are related to HA configurations iirc, so you are fine with a single-sever setup
There’s also PostgreSQL listen/notify
oh, yeah, that would def make sense if you are already using pg
Except that the PG JDBC driver doesn’t seem to support it. sigh
niwinz oh, does it?
hi all - quick Q - I am sure there is a more idiomatic approach than (map vector [1 2 3] [2 3 4])
to give [[1 2] [2 3] [3 4]]
but I can’t remember it - any ideas?
thanks @kauko
I always try to do (zip [1 2 3] [2 3 4])
just to find out that there's no zip
in clojure.core 😛
@pupeno we use redis here, happy with it so far (there are tradeoffs tho compared to the alternatives, ex wrt consistency). We have sort of "remote atoms" connected to redis, so we can "add-watch" etc etc, deref is local/cached, all updates are in the background.
@mpenet why watching atoms instead of pubsub?
it's pubsub, it's just has an atom like interface (it's a component you can deref and that has !! fns for all atom equivalent functions)
under the hood it's redis pub/sub for notifications of changes + normal keys for persisting stuff across restarts
I see. Interesting. I just need the pub sub though
if you use carmine for pub/sub on redis be aware it doesnt handle reconnections & failures
Oh, good to know.
@oliv: A very practical reason, rather than theoretical reason, why that code you pasted is bad, is that the save operation occurs when the namespace is read. If you take that code, and try and build an uberjar with it, you’ll see that the save operation actually occurs at compile time. Often these kind of side-effects can actually prevent the uberjar process from finishing too (e.g. if it fires off daeomon threads by maybe starting a web-server). If you want the code to execute when the script is loaded, just make it a -main
function or call it from the outside explicitly
also if that happened in a library, users of the library would have no control over when that side effect happened… it would complect that effect, with making the functions available to users.
thanks @miikka and @robert-stuttaford (and yeah, a map is most definitely not what I want here ;-))
thank you @seancorfield
hey @seancorfield thx for your answer (https://clojurians.slack.com/archives/clojure/p1480059591016898)
yeah, using ring, your are right !
let’s suppose my service function signup-user
1. verify if email/password are not blank
2. verify if email was already taken by someone else ( check agains database )
3. save the new user ( database )
4. send one message to the queue system ( signup.user ) with the step 3 persisted data
so, if I understood correctly, we are going to create middlewares to assoc with the request map the :database db-connection
and the :queue queue-connection
my service function signup-user
will receive the request and fetch everything from there
(defn signup-user [ { database :database queue :queue } request]
;; code here
)
is that correct ? @seancorfield ( and all others who want to join and talk about it )Something like that, yes. I’d use namespaced keywords, to avoid possible conflicts, and probably add a single :my.app/config
key with a configuration map.
In our Ring apps, we have a Component (Stuart Sierra’s library) added to all Ring requests as middleware.
And that Component contains all our DB connection pools, our “environment”, and so on.
that is cool ! and the service functions
will receive the component already started and the request
and inside the service function
you fetch what you want from the request and pass through the composed functions
In general, we only pass what a function needs but that might be the entire application component or just part of it.
(defn my-controller [{:keys [my.app/config] :as request] …)
That’s how we prefer to do the destructuring.
thank you @seancorfield
Does anyone know if there's a way to have compojure/httpkit call a specific function in case of a 404? E.g. the route is not defined in defroutes
, so call my function instead of responding with a default 404.
Whats the best way to persist a clojure data structure to disk? Like if I just wish to make a simple log that I keep appending to the end of but I want to have high throughput what should I do?
Do you use something like spit, or do you use FileOutputStreams, or FileChannels? And what is the recommended way of serializing the data so it can be written.
streams are byte-oriented, so generally you want to use something like a Java reader (character-oriented)
and you can use pr-str to get a data structure as a string
Ok, and what about reading from a file
is there a way to read and write simultaniously?
ideally I could have something which only has to write, but always writes to the end of the log
then separately I wan’t to read from that same log, but I was hoping to have many readers and then can keep track of their own place in the log
maybe after each read you return the offset in the file that you are on so you can pick back up where you left off