Fork me on GitHub
#clojure
<
2019-09-03
>
valerauko02:09:18

i use manifold stuff for networking

naveen10:09:38

Is there a way to generate spec for a specific tag in multispec ?

roklenarcic11:09:08

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?

vlaaad12:09:49

I'd say first: (your-ns/query db-conn ["select * from users"]) feels right

roklenarcic12:09:24

Hm... the downside is that when operations return things you want to feed into the next operation you cannot just use -> macro

schmee12:09:51

but you can use the ->> macro instead 🙂

vlaaad12:09:41

(-> db-conn
    (your-ns/query ["select * from users"])
    (->> (filter #(< (:age %) 18))
         (map :id)))

Keith14:09:20

Wouldn’t it be more clear like this?

(->> (your-ns/query db-conn ["select * from users"])
     (filter #(< (:age %) 18))
     (map :id))

jahson15:09:58

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".

Keith16:09:45

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

Keith16:09:42

Better yet:

(sequence (comp
            (filter #(< (:age %) 18))
            (map :id))
          (your-ns/query db-conn ["select * from users"]))

jjttjj12:09:09

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))

borkdude13:09:58

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

dominicm13:09:33

Is it a game? Do I get a prize for guessing? 😛

borkdude13:09:22

I don't know the answer myself

borkdude13:09:35

but if you think it's a fun game, do participate.

dominicm13:09:40

@borkdude what's python --version for you?

dominicm13:09:49

@borkdude for me, changing python to python2 causes it to hang forever, which I think is the expected behavior 🙂

dominicm13:09:12

oh, it was hanging for a different reason. Nvm.

borkdude13:09:44

ah, @sogaiu discovered it: curl connects too early, Python isn't that fast apparently 😉

dominicm13:09:47

Adding a 50ms sleep does to the trick. So I think the problem is that you are curling before python has had

borkdude13:09:18

darn, timing 😛

borkdude13:09:28

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)

roklenarcic14:09:32

how to release a deps project to clojars?

manas_marthi15:09:28

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.

manas_marthi15:09:20

I want to iterate through the classpath, class loders, and all packages available from my namespace upwards..

manas_marthi15:09:35

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 ).

mg16:09:14

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?

4
manas_marthi16:09:08

Thanks.. Looks like clojure.tools.namespace sourcecode has the answers I need.

jaide19:09:21

How would you structure a function that takes a collection and may update it in 0-x ways? Conditionally I may update the first, last, and add an item.

jaide19:09:31

Oh wait. Is this what cond-> is for?

👍 4
jaide19:09:20

Yes it was! That's such an awesome macro.

skuttleman20:09:57

cond-> should have it's own emoji.

💯 4
henrik16:09:21

(def is-cond->awesome true)

(cond-> {:cond->awesome-counter 1}
  is-cond->awesome (update :cond->awesome-counter inc))

8