This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-19
Channels
- # beginners (69)
- # boot (10)
- # cider (18)
- # cljsrn (6)
- # clojure (225)
- # clojure-austin (1)
- # clojure-dusseldorf (7)
- # clojure-france (2)
- # clojure-greece (3)
- # clojure-italy (9)
- # clojure-madison (6)
- # clojure-miami (1)
- # clojure-mke (2)
- # clojure-russia (58)
- # clojure-sg (36)
- # clojure-spec (25)
- # clojure-uk (54)
- # clojurescript (20)
- # core-async (15)
- # cursive (16)
- # datomic (71)
- # emacs (7)
- # hoplon (3)
- # jobs (5)
- # jobs-discuss (4)
- # klipse (3)
- # leiningen (2)
- # lumo (60)
- # mount (1)
- # off-topic (16)
- # om (6)
- # om-next (7)
- # onyx (21)
- # pedestal (15)
- # planck (1)
- # re-frame (3)
- # ring-swagger (4)
- # specter (33)
- # uncomplicate (31)
- # untangled (8)
- # vim (35)
@timok thanks, I saw that. I would like to see a real example how to use etc like other reps
i’m trying to write a web-scraping thing, and i think i’m shooting myself in the foot with my use of transducers, but i’m not 100% sure how to fix it
the site i’m trying to scrape has urls like “foo.html”, “foo-1.html”, “foo-2.html”, etc
there’s some number x
, such that “foo-x.html”, “foo-`x+1`.html”, etc., redirect back to (i think, it’s been a minute) “foo.html”
(defn redirect? [url]
(try
(let [redirs (> 0 (-> (client/get url) :trace-redirects distinct count))]
(do (println redirs)
redirs))
(catch Exception e true)))
(defn filter-redirected
"Takes a url string and returns it if it doesn't redirect
:param url: the address of the resource to retrieve
:type url: String
:returns: String or nil"
[xf]
(fn
([] (xf))
([res] (xf res))
([res url]
(if (redirect? url)
(reduced res)
(xf res url)))))
@swizzard I may be being a bit thick here, any reason to define your own transducer, and not use (filter redirect?)
?
unless there’s a bug in redirect?
(which there could be), the source of the problem might be my use of sequence
+ (range)
@swizzard Once you no longer use a custom transducer, it's much easier to check if it's in your redirect?
function.
i’ve been playing in the repl, and i think clj-http’s {:follow-redirects false}
might be the answer to my prayers
Hi everyone, I am just learning clojure for 2 weeks.
(defn get_videos [page-number order-by & query]
“Get videos”
(let [order-field-name (first (str/split order-by #“-”))
rank (second (str/split order-by #“-”))]
(if (not-empty query)
(select entities/videos
(with entities/artists)
(limit limit-by-page)
(order (keyword order-field-name) (keyword rank))
(where {(keyword (first query)) (second query)})
(offset (* (- page-number 1) limit-by-page)))
(select entities/videos
(with entities/artists)
(limit limit-by-page)
(order (keyword order-field-name) (keyword rank))
(offset (* (- page-number 1) limit-by-page)))
)
))
here is the code I wrote for a function to query data from database using korma.
Is there anything I can improve on that?
Thanks.how would you set up a projects architecture when you want to use reagent for clientside and plain clojure for backend?
@timok this is a leiningen template for exactly this: https://github.com/sveri/closp. I just put frontend code in src/cljs, backend code in src/clj and shared code in src/cljc
@timok I am currently reworking everything and stepped away from migrations. It will take some time until I make a new release and update the documentation. So, migrations are not supported anymore, sorry. If you need that, take a look at luminus: http://www.luminusweb.net/ which supports them AFAIK.
A lot of stuff, I removed korma and use plain clojure jdbc. I switched from selmer to hiccup. Switched to a different i18n library and added translation for german / english. Switched to immutant from http-kit, introduced clojure.spec and therefore use clojure 1.9-alpha xx. And some more. Currently I am totally rewriting closp-crud to be able to define entities differently and some more to come. The biggest difference between lumins and closp is that I provide one set of dependencies, I test everything on postgres, for instance, while luminus supports more databases, etc...
Luminus is pretty awesome even if you're not using it. You can get a lot of inspiration by looking at the set of libraries it uses + its architecture + the docs
While I agree with this in general (based my template on luminus more than two years ago) there are still decision which might not fit you. For instance, luminus is based on mount, while there are many that prefer component.
The disagreement between component and luminous is well-trod ground, but to summarize for new folk: luminous favors implicit, ambient state with a var for each stateful thing and provides fns to manage their lifecycle; component favors explicit state with at most one var for all stateful things and provides fns to manage such a system.
donaldball: Does luminous forces you into that? Or is that just the effect of Mount vs Component? Normally with mount you don't have to be implicit. You can write everything in a way where they take the state. Could you do that with luminous too?
Beg pardon, I should have said mount above, not luminous. And yeah, there’s nothing that forbids you from writing fns that are, if not pure, at least fns of their args, in a project in which mount manages application state.
Ah ok, ya I thought maybe because of some luminous conventions it forced you more so than just regular mount. Thanks for clarifying.
typically the role of a transducer is to isolate logic from context, so my gut feeling is that putting side effects inside one is a mess (even if it behaves correctly)
do you have any solutions for doing something like that without having to realize the whole sequence at once?
make a transducing context that writes to the db as its data destination, perhaps?
that might be silly
transduce is eager though
but you could leverage sequence, or make a new lazy transducing context with the behavior you need (maybe?)
this is very speculative, there's probably a smarter and simpler way to do this, sorry
seeing how you phrase the question on the #clojure channel, you can use sequence - sequence uses a transducer and is lazy, and you can decide how much of it to consume in your db-writing function
when I run something like (deref (delay true) 100 false)
, getting an error java.lang.ClassCastException: clojure.lang.Delay cannot be cast to java.util.concurrent.Future
no, it's because you're using a delay
and delays don't accept timeout derefs
hmm, say a delay is coded up to take an interminably long amount of time. are they un-timeoutable?
correct, since delays run on the thread that derefs them it's hard (impossible?) to code them in a way that they can be timedout.
(future ...) can be timed out however