Fork me on GitHub
#clojure
<
2018-10-15
>
jaide03:10:38

Anyone familiar with Calva? How do you disconnect nrepl so you can do a clean restart + connect?

seancorfield05:10:37

@jayzawrotny There's a #calva-dev channel that might be able to help.

❤️ 4
seancorfield05:10:54

(I tried Calva but don't know enough to answer that question)

jaide05:10:11

Ah thanks!

jaide05:10:34

Visiting the folks on vacation, got some personal time so decided to play with as many editors for Clojure as I can get my hands on. Tried Atom + ProtoREPL, and a bit of emacs. Now I’m playing with spacemacs, Cursive, and Calva.

vemv05:10:57

hadn't heard about Calva! Looks neat. I'd never leave Emacs but how did you find the experience? Looks like something I can recommend to folks

jaide06:10:48

It seems to provide a pretty similar feature set to emacs’s offerings. Not seemingly as much variety in how things get sent to the REPL but still pretty solid. It was very easy to get started.

vemv06:10:58

Happy to hear that. So it's robust for things like not getting random disconnections/errors in general? (I tend to assume those from newborn solutions)

jaide06:10:44

Not sure I can answer that. So far only really used it on new projects with not a lot of files or state. I’ve not run into any issues with that in so far.

👌 4
jaide06:10:18

One thing to note is that the source of calva is cljs so that might help leverage better compatibility than its VS Code contemporaries.

jaide05:10:43

Hmm for emacs\spacemacs is there a way to get the output of evaluation (C-c C-c) to persist keyboard navigation?

vemv05:10:33

Assuming that C-C C-c sends its output to the echo area (I use different keyboard bindings), then no There are commands that send output to the repl instead. Recently discussed over #emacs

jaide05:10:18

Joined, thanks!

pauld05:10:29

I really like cider-pprint-eval-last-sexp (, e P - in spacemacs). It will put the result in a cider-result buffer.

jaide06:10:39

Hmm seems to be C-c C-p

pez05:10:39

@jayzawrotny , you're trying them all! 😀 If you find some time I would like to hear about what you found out. The #editors channel might be the best suited for that.

jaide06:10:33

Sure, I could write some notes and share my experiences. Are you a contributor to one of them?

jaide06:10:46

Oh haha I see your name all over the calva source. Guess that question answered itself 🙂

pez07:10:41

Haha, yes. I am the one trying to keep Calva servicable.

Geoffrey Gaillard07:10:44

My team is searching for a way to map user stories to functional specifications, to test plans and to namespaces. E.G. "this namespace contributes to this feature, this feature contribute to this use-case. So if a test for this namespace is failing, a report would indicate which high-level feature is impacted". My first idea was to put tags (metadata?) on ns, deftest. Is there a tool or library providing something similar in the Clojure ecosystem?

kwladyka13:10:40

spec (s/def ::form (s/keys :req [::password ::password-repeat])) Is a way to check if password-repeat is equal password using spec? AFAIK there is no way, but maybe something changed.

Jan K13:10:35

@kwladyka (s/def ::form (s/and #(= (::password %) (::password-repeat %)) (s/keys :req [::password ::password-repeat])))

🍻 4
kwladyka13:10:13

@jkr.sw but from ::password-repeat perspective

kwladyka13:10:15

This #(= (::password %) (::password-repeat %)) wouldn’t return me keyword in :cljs.spec.alpha/problems :via

kwladyka13:10:26

I need to know reason of fail

kwladyka13:10:05

so if not from ::password-repeat perspective, it can be additional condition, but I need to know what exactly fail during validation

kwladyka13:10:22

(-> (s/explain-data spec value)
        (get-in [:cljs.spec.alpha/problems 0 :via]))

kwladyka13:10:26

PS I know 0 is not right for map validation, but I want to show the intention

kwladyka13:10:41

oh maybe i confuse myself…. It should be possible to return keyword

kwladyka13:10:51

I messed with topics

Jan K13:10:19

it gives you the predicate that failed, you can give it a name

kwladyka13:10:12

Another thing which I need is custom message. Like I would like to know why exactly something failed. Is it possible? For example “failed because it is 13:45”. This one is not possible I guess?

kwladyka13:10:57

I am trying to not use functions directly during form validations, but it doesn’t look possible when I want to have custom messages for user depend on third party things.

kwladyka13:10:35

I am looking a way to put it into specs, but it doesn’t look like a right tool for this job

Jan K13:10:56

I guess you'd have to map the problems structure to user-friendly error yourself

kwladyka13:10:42

I will ask in different way: Is it possible to do for example ::user-exist and return reason with spec “User doesn’t exist. Did you mean user ‘foo’“?

kwladyka13:10:52

I think it is not possible, but maybe I miss something

kwladyka13:10:22

Then I have to make my own way to validate form inputs by functions instead of spec

kwladyka13:10:19

Exactly mix spec and fn

Jan K13:10:56

I think you could build something like that on top of spec

kwladyka13:10:42

I did, but I want to be sure I am not doing something which I don’t have to 🙂

mping13:10:36

How can I extend a class that has a package protected constructor using clj?

mping13:10:41

proxy generates a custom pkg

reborg14:10:40

Trickier but possible with gen-class (which is AOT only, but can be “convinced” to work interactively):

;; Assuming this is the source of the class you want to extend:

package mypackage;
public class ProtectedTest {
  String protectedField = null;
  ProtectedTest(String s) {
    protectedField = s;
  }
  public String getProtected() {
    return protectedField;
  }
}

;; This is from a repl at the root of your project (and "src" is
;; in the class path):

(spit "src/mypackage/protectme.clj"
      "(ns mypackage.protectme)
       (gen-class
          :name mypackage.ProtectMe
          :extends mypackage.ProtectedTest)")

;; trick gen-class into thinking  it's AOT time
(binding [*compile-path* "src"]
  (compile 'mypackage.protectme))

(import 'mypackage.ProtectMe)
(.getProtected (ProtectMe. "hey"))
;; "hey"

mping15:10:14

cool trick!

reborg15:10:47

np! You can also just leave the protectme.clj as part of the sources, provided you remember to regenerate the classes if you ever throw away your target folder or change the gen-class directive.

reborg15:10:22

During AOT (usually while uberjarring) that would be done automatically

kwladyka13:10:36

(s/def ::form (s/keys :req [::email ::password] :opt [::password-repeat])) Can I read from this spec keywords ::email ::password ::password-repeat? The best with split by :req and :opt.

taylor14:10:58

(apply hash-map (rest (s/describe (s/get-spec ::form))))
=> {:req [:sandbox.core/email :sandbox.core/password], :opt [:sandbox.core/password-repeat]}

kwladyka14:10:22

@U3DAE8HMG 🍻 thank you

🤝 4
danielneal15:10:15

I've got a big json file on the clipboard, and I'd like to pass it to clj command line tool as a variable and start a repl so I can parse the json and work with it. Is this gonna be awkward?

danielneal15:10:50

I guess I can just write it to a file and slurp it

cddr15:10:16

I'm trying out deps.edn on a multi-project repo. I'm wondering how the :paths key gets resolved in the context of a project with multiple sub-modules. So for example. If we had...

foo
  deps.edn
  foo-core
    deps.edn
    src/
    resources/
  foo-web
    deps.edn
    src/
    resources/
...what should I put in the root deps.edn to ensure that resources from both the sub-projects are on the classspath.

dominicm15:10:49

@cddr :local/root is always resolve relative to the cwd of the JVM. Even when it's in a dependency.

dominicm15:10:28

@cddr I should clarify that a bit actually. Does foo-web depend on foo-core?

cddr15:10:45

In my case yes

dominicm15:10:12

@cddr then what you're after is not possible currently.

dominicm15:10:33

Unless you add a dependency on both I guess.

dominicm15:10:56

If it's always going to be just 2, then the maintenance isn't heavy. If there's a number of inter-dependencies, then it becomes tricky.

cddr15:10:59

I can probably re-arrange the dependencies to suit

dominicm15:10:49

@cddr Edge has a similar problem, and solves it by having a folder named "main". Basically you need to have both modules and apps as siblings, rather than in a hierarchy.

dominicm15:10:25

Then you can add a :local/root on "../foo-web" which will transitively bring in "../foo-core".

cddr15:10:08

Ah ok yeah that's totally fine

manutter5120:10:17

I want to migrate an app from nodejs to clojure/cljs, and I’m running into an issue where the existing user accounts are encrypted with a node lib called credential, using pbkdf2. Does anybody know a clojure equivalent I can use to check passwords without requiring everybody to reset?

manutter5120:10:59

I’ve tried buddy and weavejester/crypto-password, but can’t get it to work. Also looked at friend but it doesn’t look like it has the functions I need for this.

dpsutton20:10:31

did you try with both pdkdf2 versions?

(def ^:no-doc algorithm-codes
  {"HMAC-SHA1"   "PBKDF2WithHmacSHA1"
   "HMAC-SHA256" "PBKDF2WithHmacSHA256"})

manutter5120:10:33

Hmm, I did with buddy but not with crypto-password, let me give that a try

manutter5120:10:06

darn sticky “s” key…

tbaldridge20:10:50

Is there a way to disable how Clojure prints generic objects?

tbaldridge20:10:14

if I have a (delay (range 100000)) it's trying to print the long seq of strings (once the delay is forced)

tbaldridge20:10:19

I want to stop that from happening