Fork me on GitHub
#off-topic
<
2019-10-24
>
jayesh-bhoot04:10:54

Hi everyone! I was looking for a good form validation mechanism for JavaScript/React, and thought the something in clojure would be the best inspiration. I found this: https://adambard.com/blog/acceptable-error-handling-in-clojure/ which is close to what I thought out on paper. Is this a good strategy?

kwladyka06:10:14

@jayesh-bhoot You can try my library https://github.com/kwladyka/form-validator-cljs using spec and fn I will update tutorial with better demo how to use it in this week.

jayesh-bhoot08:10:36

Looks interesting! Thank you. I will try to adapt the principles into javascript.

kwladyka06:10:03

it is interactive, so care about on-change and on-blur etc.

kwladyka06:10:21

It really works like it should and this interactive things are included in library. At the same time UI is 100% cusomizable. I will update demo to show it better soon.

kwladyka06:10:26

You define spec for form and then use spec names for messages:

(ns form-validator-doc.spec
  (:require [cljs.spec.alpha :as s]
            [clojure.test.check.generators]))

(s/def ::checked boolean)
(s/def ::selected not-empty)

(s/def ::email (s/and string? (partial re-matches #"^[a-zA-Z0-9._%+-][email protected][a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")))

(s/def ::password-not-empty not-empty)
(s/def ::password-length #(<= 6 (count %)))
(s/def ::password (s/and string? ::password-not-empty ::password-length))

(s/def ::checkbox-with-value (s/and ::checked))
(s/def ::checkbox-without-value (s/and ::checked))

(s/def ::select-one (s/and ::selected #{"green"}))
(s/def ::select-multiple (partial some #{"cat"}))

(s/def ::radio #{"red"})

(s/def ::form (s/keys :req-un [::email ::password
                               ::checkbox-with-value ::checkbox-without-value
                               ::select-one ::select-multiple
                               ::radio]
                      :opt-un [::password-repeat]))
{::sc/email "Typo? It doesn't look valid."
                   ::sc/password-length "Password has to be minimum 6 characters."
                   ::sc/password-not-empty "Password can't be empty."
                   ::sc/password-special-character "Need to have minimum one special character [email protected]#$%^&*"
                   :password-not-equal "Password has to be the same."
                   ::sc/selected "You have to choose."
                   ::sc/select-one "Accept only green."
                   ::sc/select-multiple "Cat is obligatory."
                   ::sc/radio "You have to choose red pill."}

kwladyka06:10:51

The best way which I found to validate forms in cljs

kwladyka06:10:41

for validation like password repeat (compare with another fields) use fn instead of spec. It is implementet also.

kwladyka06:10:54

(defn ?password-repeat [form name]
  "Example of validator using multiple inputs values.
  form - atom returned by form-init
  name - name of the input which call event"
  (let [password (get-in @form [:names->value :password])
        password-repeat (get-in @form [:names->value name])]
    (when-not (= password password-repeat)
      [:password-repeat :password-not-equal])))

akond07:10:57

i've been looking for an example plugin for intellij idea written in clojure, but found none. is it even possible?

borkdude07:10:43

@akond I believe @cfleming's Cursive is written in a mix of Clojure and Kotlin

akond07:10:42

@borkdude is it open sourced?

akond07:10:53

i mean, can i see the code?

andy.fingerhut07:10:02

There is a #cursive channel if you want to ask there.

sogaiu07:10:39

@akond it's old, but the following has some clojure bits: https://github.com/JetBrains/la-clojure -- may be it's worth a look?

akond08:10:57

yes, thank you. i've seen it. i though it would not work because it is outdated. but i will give it a go.

Samuel08:10:17

Any emacs users on windows? My organization's policy means I'm locked to windows at work, and emacs just runs so poorly - installed through scoop - by 'poorly', I mean everything from daemon startup times, decreasing performance over time, helm minibuffers hanging for seconds before anything happens - I use spacemacs as a matter of course, but even vanilla emacs is unbearably slow in all these areas

borkdude08:10:08

@accounts259 don't know about Emacs on Windows, but if you're looking for an alternative: VSCode + Calva works pretty well for Clojure I've heard

mloughlin08:10:37

you could try using it from WSL

borkdude08:10:09

ah yeah, I've got a colleague who runs Emacs with tramp on Windows, don't know the details

mloughlin08:10:46

I have to admit I've had no problems with emacs performance on Windows when I've used it

mloughlin08:10:32

(using the Portacle pre-packaged version with SLIME)

borkdude09:10:10

shoutout to the person who uploaded the clj-kondo emoji/icon to slack. I've now used this icon as the icon for the VSCode package: https://marketplace.visualstudio.com/items?itemName=borkdude.clj-kondo

borkdude09:10:09

Ah, it was done by @lee!

lread11:10:04

Ah, I was wondering when you would notice that! Glad it works for you! 🙂

borkdude11:10:10

Yeah. Maybe it would be good to save the SVG somewhere, in case there need to be square stickers some day 😉

lread14:10:10

The svg got lost in the shuffle during a clean install of Catalina. I'll recreate the svg and create a PR.

borkdude14:10:15

alright thanks 🙂

borkdude14:10:52

I guess the file can go into the logo dir. icon.svg + icon.png (128x128) if that's possible?

lread14:10:00

exactly what I was thinking for svg and I will add png as well.

lread14:10:51

my pleasure

lread15:10:09

PR submitted, I think the new version is a tad more accurate. (inc inkscape-skill-level)

borkdude15:10:20

kewl! I'll take a look tonight

Mno09:10:57

That's a really cool logo clj-kondo

1
Piotr Roterski11:10:44

it’s cool indeed and fitting but my subconcious need to fix linter errors gives me anxiety just by having this logo on my screen 😬

Mno11:10:53

Aww.. clj-kondo on't be that way. (to me it just looks like a capital D)

lread11:10:00

Hey, just a little spark of joy back at you!

henrik11:10:51

Try it now, punk:

[:div "Q: How do you annoy a web developer"]

😆 1
souenzzo12:10:06

[:div 
  "Q: How do you annoy a lisp developer?"
  ]

😂 2
alexmiller17:10:50

https://octolinker.now.sh/ looks cool. doesn't support Clojure (yet). maybe a fun project for someone to add. https://github.com/OctoLinker/OctoLinker/issues/288

dominicm17:10:58

has java support, so it should be within reach 🙂

papachan18:10:12

Hi @seancorfield i just wonder why there is no #4clojure channel here. it could help people who are stucked at some problems and be useful to share solutions.

papachan18:10:33

do you think i can create one channel?

Michael J Dorian18:10:46

would #beginners be appropriate?

papachan18:10:00

yes probably, but it will be lost with others messages

Michael J Dorian18:10:46

might get a wider audience though

papachan18:10:36

absolutely right.

seancorfield18:10:22

Feel free to create #4clojure but I think #beginners is probably a better choice since not only will opted-in Clojurians be around to help, other beginners might learn from those discussions.

dominicm20:10:42

The java support for OctoLinker is pretty weak, e.g. doesn't work on https://github.com/TheAlgorithms/Java/blob/master/Conversions/BinaryToOctal.java so beyond what I have the time to contribute

alexmiller21:10:27

works for me - did you add a github token to the extension?

dominicm21:10:29

I was using their development setup, it seemed to work for their package.json

dominicm21:10:26

@alexmiller just to check, what works?

dominicm21:10:29

Oh, I think I see what's up.

alexmiller21:10:56

It makes a link

dominicm21:10:23

on the import?