Fork me on GitHub
#clojure
<
2015-10-13
>
pupeno07:10:32

I have a hashmap representing a user, {:email …, :password …, etc} and when I run validations, I add :validation-errors to contain the errors. It kind of bothers me that fields, such as email, and validation-errors are at the same level. Is there a better design I could use here?

lfn307:10:44

So you’d rather have something like {:email {:value “” :valid false :invalid-reason “ is totally not a real domain”}}?

lfn307:10:18

If you’re displaying validation errors on individual fields that’s probably better but if you’re batching them up the top of a form or something then your initial approach might be better.

lfn307:10:38

@pupeno: you could also consider using metadata?

pupeno07:10:45

I’m happy having all the validation errors in a hashmap by field name. My problem is the mix of fields and a map of validation errors.

pupeno07:10:47

lfn3: I’m too new to Clojure to know whether that’s good or bad design. Metadata, as far as I could see, are used to tell the compiler stuff. I’m not sure how it’ll be serialized either through my API.

lfn307:10:53

Yeah metadata is probably a bad idea. I just like it cause it seems neat.

pupeno07:10:21

validation errors do feel like metadata (data about data), so, I’m very tempted.

pupeno07:10:14

I was also tempted to use something else than keywords for keys that are not fields.

lfn307:10:56

If it’s an api then serializing that might be tricky. I don’t think most serialization libs do metadata.

pupeno07:10:23

Yeah, I doubt it. From what I can see, not even keywords are respected.

lfn308:10:23

Well if you’re emitting json they’re gonna get turned into strings.

pupeno08:10:26

Yes. Something is keywordizing the keys on the server side. Not sure what yet.

thheller09:10:10

@cfleming: would it be possible to teach Cursive to start a nREPL it cljs mode? I'm working on an nREPL implementation but that currently has issues with Cursive attempting to eval some Clojure when connecting.

ul10:10:18

I want an object with arbitrary methods. IIRC, it could be done by using Object instead of protocol, i.e.:

(deftype ProcessingMock []
  Object
  (sketchPath [_ ^String fileName])
  (createInput [_ ^String fileName]))

ul10:10:37

but I get error

#error {
 :cause Can't define method not in interfaces: sketchPath
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message java.lang.IllegalArgumentException: Can't define method not in interfaces: sketchPath, compiling:(batofdanfa/core.clj:74:1)
   :at [clojure.lang.Compiler analyzeSeq Compiler.java 6730]}
  {:type java.lang.IllegalArgumentException
   :message Can't define method not in interfaces: sketchPath
   :at [clojure.lang.Compiler$NewInstanceMethod parse Compiler.java 8082]}]
...

thheller10:10:02

@ul that only works in CLJS, not possible in CLJ

ul10:10:00

aha, thanks. what is the best way to achive initial goal in CLJ? or I'm to write small java class for that?

thheller10:10:45

defprotocol or a java interface

ul10:10:54

if i use defprotocol, i guess methods will not be accessible from java code just by name. so, need to write some Java lines anyway. thanks for the help!

thheller10:10:32

yeah java interface then

chipf0rk12:10:14

Is there a good resource to really grok quoting-and-unquoting combinations in macros?

chipf0rk12:10:25

Still confused about it sometimes

pupeno13:10:48

Is buddy.hashers/encrypt good enough for storing passwords on a web site?

ul13:10:23

if i want to create an Java float[] array to pass it to Java function which will mutate it, is (float-array 1024) right solution?

ul13:10:16

okay, semms to be working

Alex Miller (Clojure team)14:10:41

thanks to all the contributors! :)

Alex Miller (Clojure team)14:10:27

since we are now in beta, the door is effectively closed on any enhancements and we will be finishing up a small number of remaining tickets targeted at 1.8. We hope to release around conj timeframe but depends on pace of the remaining fixes.

tcrayford14:10:12

@pupeno: if it's bcrypt then yes. Otherwise probably not. USE BCRYPT

pupeno14:10:01

@tcrawley: it’s bcrypt+sha512 with with a random salt and 12 iterations.

tcrayford14:10:59

Though you prolly only need bcrypt - it's self salting and such

tcrayford14:10:24

Wait is "12 iterations" the bcrypt setting or some weirdo sha512 thing?

robert-stuttaford15:10:04

bcrypt has a work-factor

pupeno15:10:01

tcrayford: I don’t know if the iterations apply to bcrypt, sha512, or both: http://funcool.github.io/buddy-hashers/latest/#advanced-options

pupeno15:10:13

How do I access session in a compojure-api handle?

juhoteperi15:10:36

@pupeno (GET* "" req ... (:session req))

pupeno15:10:17

I’m not using GET, I’m using GET*.

pupeno15:10:04

I don’t see how to get to the raw request, or how to add to the response either.

juhoteperi15:10:52

@pupeno GET* works the same as GET except for restructuring metadata

pupeno15:10:12

Oh… let me see.

juhoteperi15:10:29

So the second element is the req destructuring form

gtrak16:10:15

trying out 1.8.0-beta1, anyone seen: Reflection warning, clojure/pprint/pretty_writer.clj:419:12 - call to method write can't be resolved (target class is unknown). ?

shayanjm16:10:07

Has anyone used CLJ for quant trading type stuff here?

Alex Miller (Clojure team)16:10:20

@gtrak: that's an issue introduced in the pprint reflection ticket - there has been some discussion on it already and there (should) soon be a ticket to address

Alex Miller (Clojure team)16:10:56

there was some code drift between patch testing and patch application

gtrak16:10:44

Everything else works great, significant build speedup.

Alex Miller (Clojure team)16:10:16

from what prior version?

gtrak17:10:48

@alexmiller: upgrading from 1.7.0

ghadi17:10:50

@gtrak: have an application level gauge on performance?

ghadi17:10:10

as in something long-running, not just build time

gtrak17:10:02

nothing like that, no.

Alex Miller (Clojure team)17:10:37

probably just the compiler sync change mainly

ghadi17:10:27

Everyone: I am soliciting application-level performance data on 1.7.0 vs 1.8.0-beta1. Anything long-running or real services would be useful info.

audaxion17:10:02

anyone use the duct lein template?

viesti18:10:49

@audaxion: started couple apps with it, at least to me it feels neat simple_smile

pupeno18:10:22

Does anybody know how secure is Ring's cookie session storage?

viesti18:10:24

though I don’t use environ, just config.edn file (with additional config-loca.edn for local stuff) for configuration

cfleming19:10:57

@thheller: Yeah, that should be possible.

cfleming19:10:17

@thheller: I still have your email queued for a response too, sorry - things are a bit hectic

Alex Miller (Clojure team)19:10:20

@viesti: you might like immuconf for config if you're headed down that path https://github.com/levand/immuconf

Alex Miller (Clojure team)19:10:45

That sentence is a change in topic to talking about the transducer - it is no longer referring to the example above.

Alex Miller (Clojure team)19:10:09

maybe a para change is warranted there

martinklepsch19:10:19

@alexmiller: I see. I think that even with a separate paragraph it still has some potential for confusion.

martinklepsch19:10:56

@alexmiller: thanks for the great book besides the critique, really enjoying it simple_smile

Alex Miller (Clojure team)19:10:24

sure. if you feel strongly about it, there is an errata page where you can file it here: https://pragprog.com/titles/vmclojeco/errata

Alex Miller (Clojure team)19:10:44

not sure when there will be an ebook update but presumably that will happen eventually

martinklepsch20:10:19

@alexmiller: cool, filed simple_smile Thanks again. 👏

gtrak21:10:00

is this also known with 1.8?

clojure.pprint.proxy$java.io.Writer$IDeref$PrettyFlush$4923d848
   cannot be cast to clojure.pprint.PrettyFlush

             pretty_writer.clj:  391  clojure.pprint/pretty-writer/fn
                           nil:   -1  clojure.pprint.proxy$java.io.Writer$IDeref$PrettyFlush$4923d848/flush
                      core.clj: 3602  clojure.core/flush
                      core.clj:   -1  clojure.core/flush
                      core.clj: 3613  clojure.core/prn
                      core.clj:   -1  clojure.core/prn

bronsa21:10:47

@gtrak: do you have a repro case?

gtrak21:10:00

will try to make one, I think I'm just calling pprint

gtrak21:10:02

(clojure.pprint/pprint "wat") seems to break it

gtrak21:10:09

will try with a clean project

bronsa21:10:28

@gtrak: that works for me

gtrak21:10:08

huh, it might be my fault, I'm doing the AOT-poststripping thing.

cfleming21:10:43

I’m having a really weird issue: java.lang.IllegalAccessError: tried to access method clojure.lang.RT.classForNameNonLoading

cfleming21:10:12

I’ve seen a few mentions of it, but no reliable solution.

cfleming21:10:32

Does anyone have any insight into what it means?

cfleming21:10:38

The method is public.

bronsa21:10:00

@cfleming: IIRC it was private in older version of clojure

bronsa21:10:20

probably AOT code running on an older version than the one used to compile it

cfleming21:10:54

@bronsa: That might be, yeah.

cfleming21:10:10

I’ll try recompiling with a different version.

cfleming21:10:34

@bronsa: As far as I can tell the versions should match.

cfleming21:10:38

It’s leiningen code that’s failing, and I compile the code using the lein standalone build. What’s weird is that one lein namespace loads successfully, but then a pomegranate one that it pulls in does not.

cfleming21:10:23

Adding to the weirdness, this works perfectly in my debug IDE instance, but in my main one it fails.

cfleming21:10:37

Aaaaaand… re-running it, now the leiningen ns fails too.

cfleming21:10:51

Actually, no, my error on the leiningen ns is different.

cfleming21:10:23

I’m going to try with non-AOT code to see if that helps.

bronsa21:10:07

classForNameNonLoading exists (and has always been public) since 1.7

bronsa21:10:00

the only way I can understand that error is a clj >=1.7 aot classfile loaded by clj <=1.6

cfleming21:10:49

@bronsa: Ok, thanks. I’ll see if I can figure it out. That class comes from lein 2.5.3, which I’m pretty sure AOTs with 1.6. I’m using the lein jar to compile against. That said, their build is pretty funky, I don’t know the details of how it works.

lfn322:10:20

@cfleming: Do you know if there’s a better way than reflection to get the arity of an anonymous function at runtime?

lfn322:10:00

(I figure this is totally something you’ve grappled with at some point…?)

cfleming22:10:54

@lfn3: I don’t think so. If you have a var you can get it from the var metadata, but if all you have is an IFn/AFn then AFAIK you can’t.

lfn322:10:34

@cfleming: Yeah that’s what it seems like according to google as well. Probably what I’m trying to do is silly in any case. I’ll give it some more thought.

cfleming22:10:34

@bronsa: One thing - in the case you describe (clj >=1.7 aot classfile loaded by clj <=1.6), wouldn’t that give a method not found error?

cfleming22:10:00

(I can’t remember the exception that it uses, but it’s not IAE).

cfleming22:10:18

NoSuchMethodError

cfleming22:10:52

@bronsa: Ok, that method was present pre-1.6, but was package private.

cfleming22:10:05

I must have something funky with my classpath.

gtrak22:10:20

I couldn't figure out my issue with PrettyFlush, giving up for now. Very weird.

gtrak22:10:01

PrettyFlush.class is in the clojure.jar, so I don't see why there can be a problem.

gtrak22:10:56

and it's in my app's uberjar as well

gtrak22:10:06

along with the proxy