This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-10-22
Channels
- # admin-announcements (29)
- # aws (2)
- # beginners (25)
- # boot (110)
- # business (15)
- # cider (39)
- # cljs-dev (3)
- # clojure (90)
- # clojure-czech (28)
- # clojure-hamburg (1)
- # clojure-japan (24)
- # clojure-poland (149)
- # clojure-russia (46)
- # clojure-sg (9)
- # clojure-uk (6)
- # clojure-ukraine (1)
- # clojurescript (105)
- # core-async (37)
- # cursive (9)
- # dato (7)
- # datomic (6)
- # emacs (10)
- # events (1)
- # hoplon (22)
- # jobs (4)
- # ldnclj (38)
- # leiningen (4)
- # off-topic (17)
- # om (173)
- # onyx (134)
- # re-frame (46)
- # reagent (35)
@mbertheau: You could do something like (zipmap (keys ui) (map :shown? (vals ui)))
, but whether or not that is more concise is open to debate. I typically just keep a map-vals
function (`(fn [f m] (reduce-kv #(assoc %1 %2 (f %3)) {} m))`) in my utils.
map-vals
looks very nice. What are the chances of something like it ending up in the standard library?
mbektimirov: I’m probably not the right person to ask, but you’d be in good company using that name / signature (e.g. https://github.com/Prismatic/plumbing/blob/master/src/plumbing/core.cljx#L68).
Yeah, there’s a lot of a good stuff in there. And those functions look crazy, but (1) they’re hard to name, and (2) you come to appreciate the fact that the names are terse and that they nicely parallel the other threading functions.
I’m getting some bug reports with namespaces referring to mranderson045
- does anyone know what that is?
@mbertheau: I would like map-keys and map-vals to end up in the stdlib. The other ops are unlikely though.
I'm currently using pedestal but I don't know how to post params in it. I'm using the response-for
function from io.pedestal.test
. How suppose I test the routes in repl ?
@alexmiller Then do you know of a concise way to construct a seq or vec out of several parts, where parts may be omitted or have different lengths? Right now I'm using a (-> [] (conj foo) (into (when cond? [bar baz])))
style.
And (-> [] (conj foo) (into (when cond? [bar baz])) seq)
if I need a seq, which works but isn't very readable.
@mbertheau: how about
(cond-> [foo]
cond? (conj bar baz))
Are there any lein templates that have pedestal set up for code reloading from the get go?
mbertheau: From what you described it sounds like you could just use concat
: (concat [foo] (when cond? [bar baz]))
. If you really want a vector, call vec
on the result.
camdez: That should be it! Now I just wonder if I tried that and discarded it for some reason I don't remember now or if I missed it. Anyway, thanks! Very simple
mbertheau: No problem! The thing you may run into is that the arguments must be sequences, not scalar values. So make sure to wrap individual items into sequences.
or the transducer version of that :) (into [] cat [[foo] (when cond? [bar baz])])
I’m using environ, is there a way to get the name of the environment being used?
Hi, When I define a prismatic schema in a .cljc file, it does not get recognized from clojure side. Any ideas why that may be the case? Is this supported at all?
@sveri: are you using Clojure 1.7+?
pupeno: A couple months back I was waaaaay down this path and could have told you with certainty, but IIRC, the answer is no. But it might be worth pointing out that using knowledge of the environment (that is, ‘dev’, ‘prod’, etc.) is against the spirit of 12 Factor, environment based configuration.
camdez: but without knowledge of the environment, how will my exception tracker now whether to put the exceptions in the production or staging buckets?
pupeno: The environment’s configuration will have an EXCEPTION_BUCKET value (or similar) rather than using ENV to make the decision within the app.
Yes, it does make sense, but I think it can get a bit verbose. I’ll just add a :name to my environments and use that.
@alexmiller: Yea, 1.7.0
pupeno: I agree that it can get verbose. But it makes things less “magical” (i.e. easier to reason about), and you usually appreciate the fact that you did these things when you want to (say) set up a second staging environment and not have the two instances clobbering each other’s external data.
camdez: the couple of times I set up another staging environment, it was not called staging.
@alexmiller: When I restart the REPL the changes are recognized. However, resetting everything using tools.namespace they are not
camdez: I see your point. I just don’t want to end with 5 keys all pointing to :dev when they are more or less equivalent.
@sveri: sounds like it's past my realm of experience then - support for cljc was added to tools.namespace. Maybe you have an older version though?
pupeno: I certainly understand where you’re coming from, just presenting other considerations. To me, it feels a bit like using the convenience of global state assuming you’ll only ever have one of something. And often you get there and wish you’d used Component or something, ya know?
Yes, I know what you mean.
@pupeno I think Immuconf is a much more flexible config choice and it's not well known enough
alexmiller: does it integrate with environment variables?
kind of :)
it's really focused on storing your config in edn maps
one or more edn files that is
Sounds not very Heroku friendly.
but you can use environment vars to pick the ones used
example:
:uberjar-env-vars {:mongo-uri (System/getenv "MONGO_URI")
:db (System/getenv "DB")
:default-admin (System/getenv "DEFAULT_ADMIN")
:client-id (System/getenv "CLIENT_ID")
:client-secret (System/getenv "CLIENT_SECRET")
:oauth-callback (System/getenv "OAUTH_CALLBACK")
:auth-url (System/getenv "AUTH_URL")
:token-url (System/getenv "TOKEN_URL")
:profile-url (System/getenv "PROFILE_URL")}
:uberjar [:uberjar-common :uberjar-env-vars]})
I see.
alexmiller: Thanks for sharing that! I’ve never quite loved how environ did things, but I’d never heard of Immuconf.
Well, in this case, environ picks up the variables automatically. I like that environ does that. Other than that, I don’t know enough to compare.
yeah, Clojure Applied talks about both Environ and Immuconf and compares them
yay :) I think somehow I'm supposed to get a cut of that but who even understands royalties
Yeah I always wondered how that works. I'll send you some stats about how many times I access it so you can try to correlate it 😃
correlate it with what? it's not like I have any data. :)
every 3 mon a random amount of money flows into my acct, who even knows
actually, pragmatic gives us very good real-time data about direct purchases on their site
it's all the other stuff that is ambiguous and received at a great lag
I'm going to pragmatically assume it's enough to buy a tesla though
(probably closer to enough to buy a nice bike)
haha well I'll definitely buy a couple extra copies directly from prag to raffle off at my next clojure meetup. especially if part of the proceeds will be going toward the purchase of a tesla =p
+1 for immuconf. I have a single envvar now to choose which files to load
i find this pattern useful: https://gist.github.com/christianromney/229bcee58a1b8390482f
@gjnoonan: if you buy me a tesla, you can have a free book :)
@alexmiller: Thanks, I explicitly added the latest tools.namespace version and it seems to be working now
I have a middleware to force redirect to SSL in compojure. This should be the outermost middleware, right? to redirect as soon as possible.
has anyone encountered this error? Caused by: java.io.FileNotFoundException: Could not locate clojure/tools/reader/impl/ExceptionInfo__init.class or clojure/tools/reader/impl/ExceptionInfo.clj on classpath.
this is weird, it comes from a dependency that does not appear in lein deps :tree or :plugin-tree but gets automatically downloaded by lein repl/run
it's usually caused by libs pulling in older version of tools.reader than the one required
lein clean + commenting all dependencies and adding them one by one taking care of the exclusions suggested
just wanted to get some feedback on something. is it reasonable to put all database queries behind a protocol, then implement that protocol for sql queries. then also reify the protocol in tests to have total control over the query responses, so that they can be effectively mocked? Example here:
; all the db queries go here
(defprotocol DB
(create-user [x username])
(find-user [x username]))
; sql implmentation
(defrecord SQL-DB [conn]
DB
(create-user [x username]
(jdbc/insert! conn :users {:name username}))
(find-user [x username]
(jdbc/query conn ["select * from users where username = ?" username])))
; use in production code
(let [db (map->SQL-DB {:conn (get-conn)})]
(create-user db "steve"))
; use in test code
(let [db (reify DB
(create-user [x username] {:username username :id 1}))]
(is (= {:username "steve" :id 1} (create-user db "steve"))))
that looks quite a lot like @stuartsierra 's component usage @sashton, so I'd say yeah it's pretty standard