This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-03
Channels
- # announcements (3)
- # beginners (114)
- # calva (42)
- # cider (90)
- # clj-kondo (3)
- # cljsrn (6)
- # clojure (40)
- # clojure-conj (4)
- # clojure-dev (3)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojure-nl (4)
- # clojure-quebec (1)
- # clojure-spec (3)
- # clojure-uk (130)
- # clojurescript (31)
- # cursive (3)
- # data-science (3)
- # datavis (1)
- # datomic (5)
- # dirac (3)
- # fulcro (16)
- # jobs (1)
- # joker (6)
- # music (5)
- # off-topic (14)
- # re-frame (19)
- # remote-jobs (8)
- # shadow-cljs (37)
- # slack-help (4)
- # tools-deps (22)
- # xtdb (8)
If I'm writing a bunch of functions which take DB connection as one of parameters, where should I put it, first parameter or last parameter?
Hm... the downside is that when operations return things you want to feed into the next operation you cannot just use ->
macro
(-> db-conn
(your-ns/query ["select * from users"])
(->> (filter #(< (:age %) 18))
(map :id)))
Wouldn’t it be more clear like this?
(->> (your-ns/query db-conn ["select * from users"])
(filter #(< (:age %) 18))
(map :id))
Clojure seems to have a distinction for threading macros — ->>
is used for collections (and the collection fns accept collection as a last arg), ->
is used when we're working with some kind of "entity".
I figured since the first call creates the collection that is then passed to subsequent calls, it made more since to just use ->>
instead of weaving ->
and ->>
together
Better yet:
(sequence (comp
(filter #(< (:age %) 18))
(map :id))
(your-ns/query db-conn ["select * from users"]))
Why not just put the db-conn in the first expression then thread the rest?
(->>
(your-ns/query db-conn ["select * from users"])
(filter #(< (:age %) 18))
(map :id))
who knows why I get connection refused here: script.clj:
(require '[me.raynes.conch.low-level :as conch])
(def http (conch/proc "python" "-m" "SimpleHTTPServer" "1337"))
(def curl (conch/proc "curl" ""))
(prn "ERR" (conch/stream-to-string :err curl))
(prn "OUT" (conch/stream-to-string :out curl))
(conch/destroy http)
(conch/destroy curl)
Invocation:
clj -Sdeps '{:deps {clj-commons/conch {:mvn/version "RELEASE"}}}' /tmp/conch_jvm.clj
@borkdude for me, changing python to python2 causes it to hang forever, which I think is the expected behavior 🙂
ah, @sogaiu discovered it: curl connects too early, Python isn't that fast apparently 😉
Adding a 50ms sleep does to the trick. So I think the problem is that you are curling before python has had
for the interested, this script works:
(defn wait-for-port [p]
(if (zero? (conch/exit-code (conch/proc "nc" "-z" "127.0.0.1" (str p))))
0
(do (shell/sh "sleep" ".1")
(wait-for-port p))))
(def http (conch/proc "python" "-m" "SimpleHTTPServer" "1337"))
(wait-for-port 1337)
(def curl (conch/proc "curl" "127.0.0.1:1337/README.md"))
(prn (conch/stream-to-string :out curl))
(conch/destroy http)
(conch/destroy curl)
how to release a deps project to clojars?
thanks
Hi all, how to define a custom class loader? I am trying to run ClassLoader.getPackages() by deriving a class from it as the method is protected one.
I want to iterate through the classpath, class loders, and all packages available from my namespace upwards..
I am trying to use gen-class but not sure how to use the generated class in the same repl.. (update: Looks like I need to define a public constructor ).
on a perhaps related question - anyone know of any good tricks for causing the compilation of every namespace on the classpath that, say, implements a given multimethod? Or is something like the method that clojure.tools.namespace
uses the only way to go?
Thanks.. Looks like clojure.tools.namespace sourcecode has the answers I need.