This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-29
Channels
- # beginners (42)
- # boot (12)
- # cider (3)
- # cljs-dev (277)
- # cljsrn (44)
- # clojure (127)
- # clojure-austin (9)
- # clojure-austria (1)
- # clojure-brasil (14)
- # clojure-canada (1)
- # clojure-dev (22)
- # clojure-dusseldorf (1)
- # clojure-italy (4)
- # clojure-russia (24)
- # clojure-spec (33)
- # clojure-taiwan (1)
- # clojure-uk (21)
- # clojure-ukraine (8)
- # clojurescript (134)
- # core-async (41)
- # core-logic (8)
- # cursive (1)
- # datomic (3)
- # ethereum (1)
- # events (4)
- # funcool (1)
- # leiningen (12)
- # off-topic (21)
- # om (19)
- # onyx (45)
- # overtone (1)
- # parinfer (2)
- # pedestal (3)
- # proton (2)
- # re-frame (103)
- # reagent (48)
- # test-check (27)
- # untangled (51)
- # vim (3)
fenak that’s actually something I am doing right now, I am using migratus for now, as far as I know right now, I think migrations will run as a component for me at the beginning of everything else and bring the DB state to the most recent migration
so its actually a part of process bootup for me, or could be a separate bootstrap process that makes sure your db env is sane before it launches the nodes on a cluster or whatever
I use a component system, and I have higher level components depend on a database component that applies pending migrations on startup
spec question from someone who hasn’t yet personally used the library: in http://clojure.org/about/spec#_data_spec_registration , there’s this passage: "By convention, specs for data should be registered under keywords and attribute values should be registered under their attribute name keyword.” does anyone know what this means? i’m having trouble parsing it
I believe "attribute value" refers to a value in a map. If I'm interpreting it right, the idea is that you'd be able to define :my-namespace/width
as int?
and then say that a map has required keys :my-namespace/width
, and spec is able to figure out that the value of something with that key must conform to the spec.
(spec/def ::width int?)
(spec/def ::larger-thing (spec/keys :req [::width]))
spec sees that ::larger-thing
is a map with {::width <val>}
, and knows that <val>
must be int?
.
But #clojure-spec is probably a better place to ask.
@fenak I package migrations into the app in luminus, and then the app runs them when it starts if you give it a migrate
argument, can also be configured to do that automatically
so I would suggest a similar approach to what @verma outlines, where the app manages its own migrations
I have a query like this:
(db/query connection {} {} {:fetch-size 10 :auto-commit false})
which queries an enormous table. I want to test if this query is really lazy, as in, the result set is not in memory all at once. How can I verify this?assuming it has more than one row, also depends on chunking dunno how/if that lib does chunking or not or if it defers to some of core's defaults
Hmm, (let [result-set (db/query …)] (realized? result-set))
is true, count is 6673 (on my dev machine, but in production it will be a lot bigger
well seems like realized is broken for some stuff that used to work too... I am not sure it's realiable after all
I guess I could test it with :row-fn (fn [r] (println "hello”))
or some other side effect
realized? "Returns true if a value has been produced for a promise, delay, future or lazy sequence." - doesn't it mean that realized? will return true even if the whole seq was not realized but only at least one element ?
I posted the question here for further discussion: http://stackoverflow.com/questions/39765943/hugsql-clojure-java-jdbc-lazy-query
I had to do something like this:
(do
(def conn {:connection-uri "jdbc:})
(def conn (j/get-connection conn))
(.setAutoCommit conn false)
(def stm (j/prepare-statement conn "select * from mytable" {:fetch-size 10}))
(def row (atom 0))
(clojure.java.jdbc/query
{:connection conn}
[stm]
{:row-fn (fn [r] (swap! row inc))
:result-set-fn #(doall (take 100 %))})
@row)
overriding the result-set-fn was essential, because it defaults to eager evaluation.
but also I had to manually set auto-commit to false and prepare a statement, because both auto-commit and fetch-size are not handled by query it seems
if i had a map that contains vector values and i want to generate a map that has set values, how would i do it?
even (into {} ) with an xform that does the convertion, but that's equivalent to reduce-kv i believe
@bcbradley with specter, (transform MAP-VALS set my-map)
will also preserve the type of the map and be near optimal performance
@bcbradley specter is highly regarded, and its author is quite active in helping craft operations in it and helping people understand it and use it, as you may have noticed
thats interesting but i'd prefer to keep my dependencies low for this one specific thing. If i were working on an application or library I'd consider using it though, it looks quite powerful
@nathanmarz I see you want to reduce on graphs in topological order in the future work for specter
@bcbradley thanks, but I've actually already implemented all that graph stuff (on top of Loom)
it would be really really cool if you could search gist for clojure code use specs rather than text
for instance, instead of searching for keywords, use a spec to specify the constraints on the function you are looking for
for instance, you could have something that can integrate into your github-- it automatically generates gists and keeps them updated to match your github code and behind the scenes the gist is indexed according to its spec and other metrics
basically if someone has already solved a problem that you are working on in a library today, and they solved it 4 years ago, you can easily find their solution by doing the search.
Moreover, you don't actually have to do the search manually. When you specify the spec of your function, the search could be done on your behalf
whats more, if there is more than one solution they could be compared against other metrics
@seancorfield Should it be possible to pass down :fetch-size
from jdbc/query
so it will be passed down to prepare-statement
?
The docs say something like:
"The options specify how to construct the result
set (and are also passed to prepare-statement as needed)” but not all options that are relevant to it are accepted.
@borkdude: there's an open issue to fix that
hi guys, does anyone have familiarity with the ring-basic-authentication library? https://github.com/remvee/ring-basic-authentication/blob/master/src/ring/middleware/basic_authentication.clj
i'm trying to get my own wrapper working around it, but i seem to be by-passing the auth step
(defn mywrap [handler] (fn [req] (if (= (path-info req) "/ping") (handler req) (do (wrap-basic-authentication req authenticated?) ;; <------ this is where I'm trying to call authentication (handler req)))))
@bcbradley : There is a function often called map-vals that gets reimplemented or copy/pasted across projects, where your task would become (map-vals set registry) Example implementation of map-vals is in the (small) medley library: https://github.com/weavejester/medley/blob/master/src/medley/core.cljc
is there any way a can avoid calling if
in this snippet?
(if (= (type x) java.net.URI)
(.toString ^java.net.URI x)
(.toString ^java.io.File x))
pardon my javanese, but shouldn't toString be polupymorphic? that is, doesn't just (str x) or at least (.toString x) do the right thing?
definitely trying to avoid reflection
@jr your solution would probably work if this was a macro
I want to add meta to the symbol, not the URI object
@grzm I’m not currently using if
🙂
I’m using .toString
and getting a reflection warning 😛
in that case, what is the difference in speed? toString itself is not a speed demon...
@trptcolin that should work, yeah. let me try
yeah I’m gonna do that, thx all
oops, i see @blueberry already said that, sorry @blueberry!
str is the correct thing to do -- but if you're going to check class use class
not type
What is so special with clojure.data.json
, why it is excluded from AOT compilation? I'm packing my project into uberjar and AOT is used for it, uberjar won't load clojure.data.json
and raises ClassNotFound
.
@novakboskov I'm not sure what your specific issue is, but you do not need to AOT your project in order to uberjar it
@bfabry My issue is that my AOT compiled uberjar can't load clojure.data.json
, simple. 😄
@ghadi cheshire
?
App won’t build on heroku, need help quick:
-----> SSH app detected
-----> Installing ngrok... ! Push rejected, failed to compile SSH app.
! Push failed
@josh_tackett that’s from the heroku-buildpack-jmx. not sure what’s wrong, but you can remove it by running heroku buildpacks:remove
@ghadi re: clojure.data.json, I am using it for the first time, mostly because it’s in a namespace that starts with “clojure”. So I should go back to Cheshire?
Suits me. I’ve been using it for years. I’m only too happy to be shuffled back into my comfort zone 🙂
@quoll We had to switch from clojure.data.json to Cheshire a while back as we ran into some basic Java types that the former doesn’t handle (dates, I think, but don’t hold me to that).
Could be. Cheshire supports dates just fine and lets you control how they’re formatted.