Fork me on GitHub
#clojure
<
2015-07-23
>
bmay00:07:43

how do i debug a compojure app in cursive? i tried steps here (https://cursiveclojure.com/archive/1156.html) but am getting "unable to open debugger port"

pyr08:07:08

hi clojurians

pyr08:07:15

maybe someone can refresh my memory

pyr08:07:40

(deftype) does not implement identity properties (equals, hashcode) for comparison, but (defrecord) does, right ?

pyr08:07:20

yup, it's actually simple to test for, thanks!

borkdude09:07:34

is it possible to control the argument order with yesql?

colin.yates09:07:01

@borkdude I don’t know but why not use named parameters with yesql?

colin.yates09:07:05

@borkdude let me find an example….

colin.yates09:07:32

but you need to use 5.0 beta

borkdude09:07:04

good to see it's being worked on

colin.yates09:07:50

actually according to the git tags they are on 5.0-rc3 already

Tom H.10:07:05

hello everyone simple_smile I was wondering, is there an idiomatic way of returning the first truthy value in a sequence?

Pablo Fernandez10:07:29

@tomisme: I think the function some does that.

nblumoe12:07:52

is test.check the way to go for property based testing in Clj (or at least a good starting point)? others I should know about?

robert-stuttaford12:07:09

test.check is the Way

tcrayford12:07:29

test.generative was written during the building of datomic, but is (mostly, as I understand it), dead these days

tcrayford12:07:09

various high level folk from a certain company that clojure folk may hold in the highest esteem have said as much

nblumoe12:07:56

allright, thanks. let me see where this gets me

tcrayford12:07:21

@nblumoe: I'm sure many folk in here would be happy to help if you have questions simple_smile

val_waeselynck12:07:46

Help appreciated simple_smile

malabarba13:07:43

Hey everyone. I just noticed that (clojure.pprint/pprint #'somevar) is not pretty at all.

malabarba13:07:06

while (print #'somevar) prints the expected #'somevar, using pprint/pprint will yield the much uglier #<Var@16e56164: "some-value">

malabarba13:07:18

Is that a bug?

colin.yates13:07:46

@val_waeselynck I don’t know about coercion and you probably know this but adding a key/value pair of {s/Any s/Any} will accept any other keys. So {:a 10 :garbage :woot} is valid according to {:a s/Int s/Any s/Any}

val_waeselynck13:07:39

@colin.yates: thanks! Trouble is, I don't only need to tolerate the addtional keys, I need to remove them too 😕

val_waeselynck13:07:04

I'm thinking I could map s/Any to a custom FlaggedAsGarbage schema, then use coercion on this schema followed by a custom walk to remove those values.

colin.yates13:07:23

I really don’t know enough to help with coercion unfortunately. If I really needed to remove them and not simply ignore them then I might use clojure.walk or even a zipper maybe..

val_waeselynck13:07:12

let me try it out and come back to you simple_smile

val_waeselynck14:07:34

@colin.yates: seems to work pretty well 😄

(deftype Garbage [])
  (defonce garbage-const (Garbage.))
  
  (defn garbage-flagging-matcher [schema] 
    (cond (= schema Garbage) (constantly garbage-const)
          :else identity))
  
  (def MySchema {:a sc/Int
                 :b {:c sc/Str
                     (sc/optional-key :d) sc/Bool
                     sc/Any Garbage}
                 :e [{:f sc/Inst
                      sc/Any Garbage}]
                 sc/Any Garbage})
  
  (def flag-garbage (sco/coercer schema garbage-flagging-matcher))

  (defn clean-garbage [v]
    (cond 
      (= garbage-const v) nil
      (map? v) (->> v seq 
                    (reduce (fn [m [k nv]]
                              (if (= garbage-const nv) 
                                (dissoc m k)
                                (assoc m k (clean-garbage nv)))
                              ) v))
      (vector? v) (->> v (remove #(= % garbage-const)) (map clean-garbage) vec)
      (sequential? v) (->> v (remove #(= % garbage-const)) (map clean-garbage) doall)
      :else v
      ))

  (flag-garbage
    {:a 2
     :b {:c "hello"
         :$$garbage-key 32}
     :e [{:f #inst "2015-07-23T12:29:51.822-00:00"}
         {:f #inst "2015-07-23T12:29:51.822-00:00", :garbage-key 42}]
     :_garbage-key1 "woot"})
  
  => {:a 2,
      :b {:c "hello",
          :$$garbage-key #object[bs.utils.http.Garbage 0x16542e0f "bs.utils.http.Garbage@16542e0f"]},
      :e [{:f #inst "2015-07-23T12:29:51.822-00:00"}
          {:f #inst "2015-07-23T12:29:51.822-00:00",
           :garbage-key #object[bs.utils.http.Garbage 0x16542e0f "bs.utils.http.Garbage@16542e0f"]}],
      :_garbage-key1 #object[bs.utils.http.Garbage 0x16542e0f "bs.utils.http.Garbage@16542e0f"]}
  
  (clean-garbage *1)
  => {:a 2,
      :b {:c "hello"},
      :e [{:f #inst "2015-07-23T12:29:51.822-00:00"}
          {:f #inst "2015-07-23T12:29:51.822-00:00"}]}

colin.yates14:07:00

@val_waeselynck - nice. I would suggest you put that in a gist somewhere and contact the Prismatic guys who might include it in their documentation.

colin.yates14:07:13

@val_waeselynck - I would say ‘glad to help’ but I’m not sure I actually did anything simple_smile

colin.yates14:07:06

I am idly musing what a ‘reducer’ which took in a structure and a blob and returned just the blob that matched the structure would look like… so (reducer {:a nil 😛 nil} {:a 1 😛 2 :c3}) => {:a 1 😛 2}) but obviously for nested structures looks like. Protocols to define equivalency in terms of structures etc….

cfleming14:07:54

@bmay: Sorry for the delay, did you get the debugging working?

bmay14:07:19

i actually put it off because i figured out the cause of my exception

cfleming14:07:32

Ok, ping me if you have trouble when you try again

kardan16:07:52

In an Enlive snippet is there a way to not have to do [:form] (if errors (set-attr :class “has-error”) (set-attr :class “has-no-errors)) ?

val_waeselynck16:07:58

@colin.yates: FYI https://gist.github.com/vvvvalvalval/1269001937f91eb5fd8a . Also pretty good suggestion from nberger on Stackoverflow. Thanks again!

sveri16:07:28

Anyone here used joplin? I tried to run migrate-db from a test and it seems it only supports .clj files but not .sql files. Is that true?

jakemcc16:07:21

@kardan: what are you trying to avoid? You can remove some of the duplication by moving the if inside a set-attr

michaeldrogalis16:07:08

@sveri: It can migrate SQL - I've used it for that purpose before. It's been a while though.

kardan17:07:01

@jakemcc: just feels odd to have to add a dummy class

jakemcc17:07:27

@kardan: I haven’t tested it but something like this

(defn classed [pred classname]
  (fn [node]
    (if pred
      ((enlive/add-class classname) node)
      node)))

[:form] (classed errors "has-error")

jakemcc17:07:41

alternatively you can replace the second set-attr with identity

kardan17:07:39

ah, cool. Will see where that idea brings me. Thanks!

braai engineer17:07:09

What is :>> in the clojure docs for condp? https://clojuredocs.org/clojure.core/condp

braai engineer17:07:19

;; (some #{4 5 9} [1 2 3 4] 
;;  is the first matching clause, 
;;  the match value is 4 which is decremented
(condp some [1 2 3 4]
  #{0 6 7} :>> inc
  #{4 5 9} :>> dec
  #{1 2 3} :>> #(+ % 3))
;;=> 3

braai engineer17:07:02

ahh, I see. It's when it returns a result-fn. Sorry, I meant to post in #C053AK3F9.

ghadi19:07:10

@donaldball: every time you pmap a kitten dies

gtrak20:07:37

I don't think I've ever used :>>

alwaysbcoding21:07:57

Is there a simple way to just convert a string of transit data to a clojure data structure in Clojure? I'm pretty confused by the documentation. Why all the ceremony around Bytearray's and input streams, is there not just a simple way to just go from a string of transit to a clojure data structure in one function?

alwaysbcoding21:07:45

i.e. I have this string of transit ["^ ","resource","league","action","query","method","~:all","return","records","serialize","false"] and I just want a clojure map. Do I need all this stuff about bytearrays or is there another way?

arohner22:07:45

(defn to-transit [x]
  (let [baos (ByteArrayOutputStream. 4096)
        writer (transit/writer baos :json)]
    (transit/write writer x)
    (.toString baos)))

(defn from-transit [str]
  (let [bais (ByteArrayInputStream. (.getBytes str "UTF-8"))
        reader (transit/reader bais :json)]
    (transit/read reader)))

arohner22:07:22

it uses byte-arrays by default because they’re generally faster than strings

alwaysbcoding22:07:26

awesome, got it to work. Thanks @arohner . Ok I didn't realize the ByteArray stuff was for performance, I was so confused why all the examples were written that way. But now it makes sense, you convert the string to bytes and then you can parse it with the reader :thumbsup:

arohner22:07:01

completely off topic, but is there a way to repurpose a few bits in a UUID for my own purposes? like embedding a hash-code?

danielcompton22:07:07

@tcrayford: it’d be nice if the library was marked as deprecated if that’s how it is seen