This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-23
Channels
- # admin-announcements (3)
- # beginners (35)
- # boot (87)
- # cider (84)
- # cljs-dev (6)
- # clojure (70)
- # clojure-austin (3)
- # clojure-italy (11)
- # clojure-japan (6)
- # clojure-korea (16)
- # clojure-russia (87)
- # clojurebridge (1)
- # clojurescript (122)
- # core-async (112)
- # cursive (2)
- # datomic (46)
- # editors (6)
- # jobs (2)
- # ldnclj (8)
- # re-frame (1)
- # reagent (1)
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"
(deftype) does not implement identity properties (equals, hashcode) for comparison, but (defrecord) does, right ?
@borkdude I don’t know but why not use named parameters with yesql?
@colin.yates: what do you mean
@borkdude let me find an example….
@borkdude this thread has some info: https://github.com/krisajenkins/yesql/issues/29#issuecomment-56063808
but you need to use 5.0 beta
actually according to the git tags they are on 5.0-rc3 already
hello everyone I was wondering, is there an idiomatic way of returning the first truthy value in a sequence?
@tomisme: I think the function some does that.
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?
test.check is the Way
test.generative was written during the building of datomic, but is (mostly, as I understand it), dead these days
various high level folk from a certain company that clojure folk may hold in the highest esteem have said as much
Walmart? 😁
If anyone is knowledgeable about Prismatic Schema: http://stackoverflow.com/questions/31587590/prismatic-schema-removing-unanticipated-keys
Help appreciated
Hey everyone. I just noticed that (clojure.pprint/pprint #'somevar)
is not pretty at all.
while (print #'somevar)
prints the expected #'somevar
, using pprint/pprint
will yield the much uglier #<Var@16e56164: "some-value">
@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}
@colin.yates: thanks! Trouble is, I don't only need to tolerate the addtional keys, I need to remove them too 😕
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.
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..
let me try it out and come back to you
good luck!
@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"}]}
@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.
@val_waeselynck - I would say ‘glad to help’ but I’m not sure I actually did anything
@colin.yates: will do
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….
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)) ?
@colin.yates: FYI https://gist.github.com/vvvvalvalval/1269001937f91eb5fd8a . Also pretty good suggestion from nberger on Stackoverflow. Thanks again!
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?
@kardan: what are you trying to avoid? You can remove some of the duplication by moving the if
inside a set-attr
hey everybody
@sveri: It can migrate SQL - I've used it for that purpose before. It's been a while though.
@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")
What is :>>
in the clojure docs for condp? https://clojuredocs.org/clojure.core/condp
;; (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
ahh, I see. It's when it returns a result-fn. Sorry, I meant to post in #C053AK3F9.
@donaldball: every time you pmap a kitten dies
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?
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?
(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)))
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:
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?
@tcrayford: it’d be nice if the library was marked as deprecated if that’s how it is seen