Fork me on GitHub
#clojure
<
2016-01-25
>
jplaza00:01:40

Is there something in Clojure like http://www.django-rest-framework.org/api-guide/exceptions/ that would validate models and respond with friendly messages like the ones in Django REST, probably Rails has something similar.

jplaza00:01:20

I’ve been using pedestal for a while but haven’t seen anything like that yet

jaen00:01:58

For validatiosn themselves you might want to use https://github.com/leonardoborges/bouncer for example

jaen00:01:08

Or any other validation library (or schema).

jaen00:01:35

https://github.com/metosin/kekkonen seems to have that built-in into the library for example

jaen00:01:15

https://github.com/juxt/yada also seems to have it, but I can't find a concrete example in the docs to be 100% sure

andrewboltachev02:01:11

Hi. Is there shorter equivalent for (merge m1 (select-keys m2 (keys m1)))?

jplaza02:01:34

Thanks a lot @jaen ! First time I see bouncer..

ikitommi07:01:12

@jplaza there is also https://github.com/frankiesardo/pedestal-swagger & https://github.com/metosin/compojure-api using Schema for validation (and api-docs). Schema doesn't produce 100% human readable errors thou.

jimmy08:01:01

hi guys is there any shorter way to implement contains for vector. Normally I use this one (some #{:a} [:a :b :c]). I can see that we can use native java method (.indexOf vector key)

jaen08:01:04

(some #{value} vector) is idiomatic, I would keep using it. It won't explode with NPE if vector is nil, like indexOf will.

jimmy08:01:13

@jaen: it's good to know simple_smile

slotkenov10:01:29

is it possible to inject a project version number into leiningen/boot from an external source (properties file)?

mpenet10:01:44

you can do ~(System/getProperty "foo.bar") in your project.clj

mpenet10:01:33

(I believe, actually never tested it, but I see no reason why it would fail)

mpenet10:01:53

same for env vars etc

jaen10:01:33

With boot it's easy as well, just do (task-options! :pom {:version (slurp "your-file")}) or something similar.

slotkenov10:01:36

@mpenet @jaen looks promising, thanks!

dm311:01:37

@mbertheau: (map-indexed vector ["dog", "cat", "bird"])

slotkenov11:01:27

never thought of it, but you can use clojure code in your project.clj file; (defproject my-project (slurp “version.file”)…

slotkenov11:01:19

I thought that was the advantage of boot; scripting your build tasks, but you can script leiningen this way as well, right?

mbertheau11:01:21

@dm3: Thanks. That seemed weird at first, but I understand it now.

dm311:01:28

@slotkenov: the advantage of boot is that your build file is a program operating on immutable filesets, not that you can hack some logic into the description of you build

jaen11:01:38

Also, you can't really "script" lein, at best you can produce a certain shape of a defproject arguments you want

jaen11:01:01

And I don't think you have your depenendcies available in project.clj yet; in boot you can have that.

slotkenov12:01:59

@dm3 can you elaborate on why it would be beneficial to operate on immutable filesets?

dm312:01:09

pretty much same reason immutable data structures are beneficial to mutable ones. In the case of filesystem you know that no one will change the files from under you, you have transactional semantics, you can treat the fileset as a value that can e.g. be cached, you don't have to interact with the actual filesystem at every step. Potentially, you can have a fileset implementation that is remote even.

jaen13:01:12

Namespaces compile to Java packages with the leaf namespace compiling into a class that is included in a package derived from namespace names leading to it, is that right or did I mess something up?

jplaza13:01:43

@ikitommi: I’m using pedestal-swagger but was wondering if there was something that could produce more human-readable error messages. It’s a public facing API, hence the need to have friendlier error messages for developers using it.

ikitommi14:01:56

@jplaza: would like to see that too. There is a start here: https://github.com/cddr/integrity/blob/master/test/integrity/human_test.clj - had plans to port/finalize that into our schema-tools lib, but haven’t had time.

octahedrion15:01:25

anyone know of an analysis of the frequencies with which core Clojure functions are used in code ?

jplaza16:01:09

@ikitommi: I actually did some work on that some time ago, but start-walker is not a part of Schema anymore. https://github.com/datil/schema-rosetta

ericnormand16:01:52

somebody called?

ghosss16:01:10

that might help

jplaza16:01:16

@ikitommi: I was using the code you referred to simple_smile .. and it worked great for schema 0.3.0

ericnormand16:01:27

thanks for linking

ericnormand16:01:40

the dataset and my results are linked to at the bottom of that article

octahedrion16:01:37

@ericnormand: @ghosss cheers exactly what I wanted

octahedrion16:01:13

although the results are puzzling

octahedrion16:01:31

@ericnormand: what I'm interested in finding out is which core functions are the most important to learn first if you're a newbie

octahedrion16:01:51

-- newbies seem to be intimidated by the apparently huge range of functions, and I want to reassure them that they only need to think about maybe 10 to begin with

octahedrion16:01:10

maybe comp, partial, list, eval, cons, concat, map...

octahedrion16:01:47

hmmm maybe the most frequently used functions in actual code aren't the best ones to learn first

octahedrion16:01:03

(huge images warning)

jaen16:01:11

You can remove the previews with the X next to them, I think.

jaen16:01:21

They kinda make my slack lag xD

octahedrion16:01:08

@jaen no X visible...searching

jaen16:01:17

Oh huh, it seems that's only for links.

jaen16:01:23

Kinda meh.

octahedrion16:01:46

the first two images from there

octahedrion16:01:52

the first shows the functions in clojure.core that most other functions depend on

octahedrion16:01:39

concat, apply, seq, let, list, vector, fn

pguillebert16:01:59

guys, I’trying to call a scala scala.BigDecimal.unary_- from clojure with classic (.unary_- bigdec) and for some reason clojure seems to try to call unary__ and fails with a No matching field found: unary__ for class scala.math.BigDecimal

pguillebert16:01:55

I suspect the magic name mangling is against me this time

pguillebert16:01:00

any thoughts ?

mpenet16:01:21

I guess you could use reflection

ericnormand16:01:30

@octo221: I think 10 might be too low

ericnormand16:01:39

that's why I recommend the top 100 expresinos

pguillebert16:01:09

(never mind, I dodged this one by using the .underlying java.lang.bigdecimal

mpenet16:01:11

for the record: (clojure.lang.Reflector/invokeInstanceMethod "foo" "replaceAll" (to-array ["f" ""]))

mpenet16:01:29

not sure how performant that is tho...

mpenet16:01:10

prolly better to write a thin java wrapper in those cases (when perf matters)

darwin17:01:55

is there any clojure function which would run my code later on the same thread (actually I need to run it on main thread)

conormcd17:01:16

A delay will probably do what you want.

conormcd17:01:37

(def code-to-run-later (delay ...))

conormcd17:01:48

Then @code-to-run-later when you want to run it.

darwin17:01:04

I ended up using TimerTask: https://github.com/binaryage/cljs-devtools-sample/blob/master/project.clj#L59, it executes on main thread for sure but unfortunately it didn’t solve my problem. I’m trying to launch cemerick.piggieback/cljs-repl and it does some magic with bindings. Executing the code from REPL works, but not running it from that :init code Can't change/establish root binding of: *cljs-repl-env* with set

immutableme20:01:18

I am new to clojure and would appreciate experience sharings

iwankaramazow20:01:49

has anyone connected cider to a clojure 1.8 socket server repl?

immutableme20:01:22

anyone knows how to find a perfect number in Clojure?

nullptr21:01:42

borkdude: not necessarily — downside is more repl reboots, probably :)

mikeb21:01:49

@amacdougall, a bit late but just saw your discussion yesterday trying to generate dynamic order by and sort for postgres. I’ve been working on a new library similar to yesql which should handle that. Here's the link describing dynamic queries, and any feedback is much appreciated. https://github.com/mikeball/foundation/blob/master/docs/dynamic-queries.md

amacdougall21:01:30

Oh, thanks! I’ll check it out tomorrow evening.