Fork me on GitHub
#beginners
<
2019-08-19
>
ashley00:08:18

How do you go about actually including that function though? It's not actually appearing if I do (my-comp)

ashley00:08:43

I got it, needed to be in a vector and not called as a function

neo255100:08:43

Tell us if this works :)

ashley00:08:57

(defn md-editor []
  (r/create-class
    {:component-did-mount
      (fn [comp]
        (println (r/dom-node comp))
        ;(js/SimpleMDE. {"element" (r/dom-node comp)}))
        ;(js/SimpleMDE. (r/dom-node comp)))
     :reagent-render
     (fn []
       [:textarea#foo.textarea])})) ;; this div will get returned by `dom-node` above
so the println prints the component, but neither the calls to SimpleMDE work

neo255105:08:51

You need to convert the argument of SimpleMde with clj->js

ashley10:08:05

Gosh yeah, you're right. I was so tired last night. Thank you!

andrew23302:08:39

πŸ‘‹ I'm learning spec atm, and I'm trying to model a pair of dates: βœ”οΈ earliest_departure can't be in the past βœ”οΈ latest_departure can't be in the past ❓ latest_departure can't be earlier than earliest_departure How can I model this last one? I need both values to make that check, and it's not clear to me how to do that with spec

vale03:08:00

I have specs like this, and they work as intended.

(s/def ::pass
  (s/and string?
         #(re-matches #"\S.+\S" %) ; must start and end with nonspace chars
         #(re-find #"[a-z]" %) ; must contain at least one small letter
         #(re-find #"[A-Z]" %) ; must contain at least one capital letter
         #(re-find #"[0-9]" %) ; must contain at least one number
         #(re-matches #".{8,}" %))) ; must be at least 8 characters long

(s/def ::pass-confirm ::pass)
(s/def ::pass-match #(= (::pass %) (::pass-confirm %)))
from https://github.com/valerauko/kitsune/blob/master/src/kitsune/spec/user.clj

schmee06:08:34

a relationship between two values is a property of the aggregate, not the values themselves. so you could do something like:

(s/def ::date ...)
  (s/def ::earliest-date ::date)
  (s/def ::latest-date ::date)
  (s/def ::foo
    (s/and (s/keys :req [::earliest-date ::latest-date])
           #(< (::earliest-date %) (::latest-date %))))

htarashion06:08:05

I have vector of maps and i want to send every map by specific time via http-kit. i did for one map like this and it did work. how can i do the same thing for vector of maps?

andy.fingerhut06:08:50

what do you mean "by specific time"? Do you mean that each map contains within it some start and/or end time by which you want the request to occur?

andy.fingerhut06:08:32

If the time issue does not really matter, and you simply want to do them all as quickly as possible, sequentially, you can use map of a function over the vector, where the function body will look like your code above, performing one of the requests. map will cause the function to be called once on each of your vector elements.

htarashion06:08:55

I mean for example by every 100 millisecond get first map of the vector.

alpox10:08:14

Is there a way to tests if a value is an async channel - for the use in spec?

alpox11:08:51

As I didn't find any better, I chose to test for #(satisfies? ReadPort %) (No WritePort as the user will not have to use the writing part of the channel) and I hope that is the best I can do. If there is something better i'm open for suggestions πŸ˜„

jamie96211:08:35

okay… macros…. I’d like to transform:

jamie96211:08:01

; I want to transform:

(defquery query-name [query & args]
  (query "blah"))

; Into:

(defn query-name [db & args]
  ((db/query db) "blah"))

jamie96211:08:52

I’d basically like to replace the db object with a prepared query partial function

jamie96211:08:32

(so i don’t have to call (db/query db), or so I don’t have to wrap everything in a let)

alpox12:08:44

@jamie962 I'm not very experienced but I gave it a try:

(defmacro defquery [name argv & body]
  (let [query-sym (first argv)
        fn-args (rest argv)]
   `(defn ~name [db# [email protected]]
     (let [~query-sym (db/query db#)]
       [email protected]))))
This should work as long as the namespacing for db holds. I'm not exactly sure how the namespace lookup for it works in macros but it should evaluate to a fully qualified symbol when db is available.

jamie96215:08:26

v helpful - thank you

linuss14:08:03

Hey guys, I have a Java-interop question: I'm trying to access an enum within an inner class. I've tried IndicesAliasesRequest$AliasActions$Type/ADD and all other variations I could think of, but nothing works so far. The java code can be seen here: https://github.com/elastic/elasticsearch/blob/c639cfece56d0db265efd104b6fb0746c1ef01f6/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java

alexmiller14:08:20

that's a private static, you can't access it

alexmiller14:08:48

oh sorry it's both a field and an enum value

alexmiller14:08:03

what you have seems like what I would use - what error do you get?

linuss14:08:32

Caused by: java.lang.RuntimeException: No such namespace: IndicesAliasesRequest$AliasActions$Type

linuss14:08:52

Oh, it seems like using the full namespace (is that the right word?) might actually work

linuss14:08:03

Not pretty, but no errors:

(def alias-action (-> (IndicesAliasesRequest$AliasActions. org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest$AliasActions$Type/ADD)

alexmiller14:08:05

do you have an import for the nested class?

linuss14:08:22

yeah:

[org.elasticsearch.action.admin.indices.alias IndicesAliasesRequest
            IndicesAliasesRequest$AliasActions]

alexmiller14:08:31

you need one for the Type too

alexmiller14:08:41

the inner class is a separate class

alexmiller14:08:04

so include IndicesAliasesRequest$AliasActions$Type there

linuss14:08:28

Ah, that's it! Thanks! πŸ™‚

alexmiller14:08:30

you actually don't need the others unless you're actually using them

neo255118:08:17

@alexmiller In your book, Clojure applied, you recommend to use core.async as the preferred fashion to communicate between components. In a talk, Timothy Baldridge recommended to avoid it whenever possible. What are the factors that should we consider for taking the decision?

alexmiller18:08:28

well, my opinions are in Clojure Applied :)

neo255118:08:37

ok I will follow them then πŸ™‚

alexmiller18:08:40

I don't have anything better to say than that :)

neo255119:08:08

It was just a check if you did not updated your view πŸ™‚

neo255119:08:31

Sorry for the dumb question

neo255119:08:06

Thanks a lot for your book by the way, it is a pleasure to follow

alexmiller19:08:36

no worries :)

rahul08032707:08:31

Hey there @! Welcome here, was nice to meet you in heart of clojure πŸ˜„

salaun.clement22:08:27

Ahah agreed! Nice meeting you too @ πŸ™Œ

salaun.clement20:08:28

Just found out that as maps, keywords can be used as functions

jaihindhreddy20:08:45

symbols act just like keywords in fn position. Vectors can be used as fns, they return value when called with an index. And sets when called with something return the thing if it's present in the set, and nil otherwise.

zane22:08:51

I've been working professionally as a Clojure programmer since 2013 and didn't know that about symbols until this year. πŸ™‚

salaun.clement20:08:35

Is one form preferred over the other to get a map attribute?

noisesmith20:08:08

my rule of thumb is if one is a literal or defined in scope such that you always know the type, use that one as a function

noisesmith20:08:17

if neither are, I'll often use get instead

noisesmith20:08:30

this way you can avoid pointless NPEs for unexpected nulls

noisesmith20:08:17

alternately, if the program isn't valid when foo is nil, use foo as a function to enforce that :D

noisesmith20:08:10

but this is mostly a style concern, and I'd go with the preferences of collaborators

salaun.clement20:08:00

makes sense! thanks for your help πŸ‘Œ

ashley22:08:37

Hey everyone! I am currently using https://github.com/yogthos/markdown-clj to convert markdown into html, and using reagent like so to render it (I don't like this method but struggled to find much else:)

[:div
                  {:dangerouslySetInnerHTML
                    {:__html (md/md->html (:post-summary p))}}]
I need an idea on how to make sure my data is safe - anything that isn't touched by markdown-clj just gets passed through to reagent, meaning that writing raw html gets passed along and then rendered. I would like to simply write the text of the HTML, rather than render it, as it'd be nice to be able to write HTML tutorials and what now in code blocks and instead of it being rendered allow the text to be passed through. Any ideas? I looked at regex, but this answer suggested that it wouldn't be a good idea: https://stackoverflow.com/questions/11229831/regular-expression-to-remove-html-tags-from-a-string