Fork me on GitHub
#clojure
<
2017-01-25
>
lvh00:01:27

With a large set of examples for are, how do I know which one failed? I get output like:

FAIL in (required-args-tests) (refl_test.clj:66)
expected: #{}
  actual: :payne.refl/missing-args
    diff: - #{}
          + :payne.refl/missing-args

FAIL in (required-args-tests) (refl_test.clj:66)
expected: #{}
  actual: :payne.refl/missing-args
    diff: - #{}
          + :payne.refl/missing-args

FAIL in (required-args-tests) (refl_test.clj:66)
expected: #{}
  actual: :payne.refl/missing-args
    diff: - #{}
          + :payne.refl/missing-args

FAIL in (required-args-tests) (refl_test.clj:66)
expected: #{}
  actual: :payne.refl/missing-args
    diff: - #{}
          + :payne.refl/missing-args
which of course tells me zilch about what’s actually failing.

lvh00:01:01

the test is written like:

(t/deftest required-args-tests
  (t/are [fn-var expected] (= expected (#'r/required-args fn-var))
    #'amazonica.aws.ec2/describe-vpcs
    #{}

    #'amazonica.aws.ec2/describe-egress-only-internet-gateways
    #{}

...

lvh00:01:18

Obviously I could change the equals to include the fn-var input, but that seems silly

Alex Miller (Clojure team)00:01:59

this is a long-standing problem with are (but really with macros in general) - I think the infamous http://dev.clojure.org/jira/browse/CLJ-865 is related

Alex Miller (Clojure team)00:01:22

@mobileink btw, Cognitect does on-site Clojure intro training. let me know if you need any more info.

thug.nasty01:01:47

why am i now seeing the antiforgery token error when i run my luminus project locally?

yogthos02:01:39

@thug.nasty are you passing in the anti forgery token?

yogthos02:01:36

Luminus enables CSRF protection by default, so you have to provide the token in form submissions

thug.nasty03:01:36

@yogthos yes, the token is being passed around

yogthos03:01:37

what's the error you're seeing?

thug.nasty03:01:00

well, nothing now. I also just restarted the server

thug.nasty03:01:47

oh wait. does the system clock have anything to do with the generation of the token?

yogthos03:01:00

if you had a stale token on the page that would do it

yogthos03:01:12

for example if you reloaded the server and didn't reload the page

thug.nasty03:01:22

ahh that’s much more like it, thanks!

leena06:01:16

Hi, coding clojure since quite a while again. Was there a trick to make changes in code automatically be loaded when the app has been started with lein run?

leena06:01:20

Using compojure-api and couldn't figure out how to mangle headers with it without creating a separate namespace that gets the response and hacking the headers there

ikitommi07:01:39

@leena there is #ring-swagger for compojure-api related stuff, try there?

leena07:01:40

Does not work. If I put it before {:swagger ...} the application is not fired up, and if I put it after {:swagger ...} it does not add the extra headers.

leena07:01:09

`(defn wrap-add-always-headers [handler headers] (fn [request] (some-> request handler (update :headers merge headers)))) (def app (api {:swagger {:ui "/" :spec "/swagger.json" :data {:info {:title "Rest-invoice" :description "Compojure Api example"} :tags [{:name "api", :description "some apis"}]}}} {:middleware [[wrap-add-always-headers {"kikka" "kukka"}]]} (context "/api" []`

ikitommi07:01:25

the :middleware option in api is introduced 1.2.0-alpha1. You can use the latest alpha (not recommended for prod) or wrap the mw “normally”:

ikitommi07:01:24

(def app-with-middleware
   (-> app (wrap-add-always-headers {”kikka" “kukka”})))

nick07:01:06

Messing around and I have a map of name-spaced keywords generated by core.spec generator, and I want to return that from an api. Return JSON is all the namespaced keywords. Is there a way to easily turn all the namespaced keywords into just their regular keyword format?

nick07:01:45

clojure.walk/stringify-keys works

Pablo Fernandez07:01:31

Can I run another task whenever lein deps is run?

leena07:01:04

So the above does not add them.

psalaberria00210:01:28

Compojure related question. I have defined a route GET “/xxx/:id”. When sending a request to /xxx/123 I would like to have a middleware that prints “/xxx/:id”. Is there any easy way to do so? (:uri request) is not enough.

pesterhazy10:01:55

@psalaberria002 why is it not enough?

psalaberria00210:01:26

I want to get it with ":id”, the same way it’s defined in the route

leena10:01:45

For the hot realoading, I found this and it works: http://www.http-kit.org/migration.html So made a main namespace that gets routes from the handler namespace (using compojure-api)

pesterhazy10:01:47

what do you want to print?

psalaberria00210:01:19

I want a unique identifier for each different route

pesterhazy10:01:26

you want to print the string :id? why?

psalaberria00210:01:43

so /xxx/1 and /xxx/2 will both return xxx/:id

pesterhazy10:01:45

for that kind of thing I recommend bidi instead of compojure

pesterhazy10:01:02

with bidi you associate routes with handlers, which could be keywords

pesterhazy10:01:41

it's more "decomplected" than compojure

psalaberria00210:01:33

thanks for the tip. I was thinking there may be a function in compojure that does exaclty what I want. will have a look into bidi, but I am afraid it will take some time to change the api from compojure to bidi.

pesterhazy10:01:40

hehe yeah I understand

fatihict16:01:11

Hello folks, I am working on a Clojure project for my study. My school always forced students to design the system with UML before implementing the functionality. That was easy to do with Java as a language, but I am not sure how this is done with a functional language as Clojure. I have read the articles on the net about this and I am wondering if you folks can give me an insight on how you are tackling designing a Clojure application.

firezenk16:01:35

UML is for OO languages... since Clojure is not OO, UML does not fit...

Alex Miller (Clojure team)16:01:18

I don’t think that’s entirely true

bostonaholic16:01:35

it depends on how detailed you want your UML to be

Alex Miller (Clojure team)16:01:53

there are still probably entities in your system that are ~same as the noun-like objects you’d have in OO (but they’re maps or records)

bostonaholic16:01:54

to can model the sub-systems without the need to reference “classes"

Alex Miller (Clojure team)16:01:08

beyond that, I think it’s more useful to think in terms of data flow

7h3kk1d16:01:14

I would represent the data as components and functions as how they interact with each other

tom17:01:58

Does anyone know if Buddy or any other lib can do the same thing as verify_id_token as in python's oauth2client? https://github.com/google/oauth2client/blob/master/oauth2client/client.py#L1530

donaldball17:01:15

I have used the java lib [com.nimbusds/nimbus-jose-jwt “4.18”] to do that

dominicm17:01:33

I've seen a lot of things for benchmarking CPU & time taken. But I don't seem to be able to find anything about memory consumption, have I missed it, or is there a JVM limitation in this regard and JMX is what I must delegate to?

miikka17:01:16

What kind of things are you trying to measure?

agile_geek18:01:34

UML has more than class and package diagrams, what about communication diagrams, sequence diagrams, state models, etc.

agile_geek18:01:22

Communication diagrams fit really well with component/service design regardless of programming paradigm

jjfine18:01:46

sequence diagrams are great!

Alex Miller (Clojure team)18:01:52

and sequence diagrams are not bad for function invocation (although higher order is challenging in some cases)

agile_geek18:01:41

I flip flop between communication and sequence diagrams. Sequence for message order and communication to explore components/services

Alex Miller (Clojure team)18:01:43

I think among Rich’s many skills are his adeptness at capturing a complex architecture in a single diagram that includes the essentials and omits the rest

Alex Miller (Clojure team)18:01:37

these diagrams are typically a mixture of data and process

agile_geek18:01:47

I think that's possible but I don't have the intuitive insight to get there in one step...I need the intermediate diagrams to derive the final one

Alex Miller (Clojure team)18:01:48

that’s Rich’s talk from EuroClojure 2014

agile_geek18:01:49

I have been reminiscing about old fashioned Data Flow Diagrams (DFDs) recently....takes me back 25 years!

Alex Miller (Clojure team)18:01:08

DFDs are great for functional (but again, challenging for higher-order stuff)

talexxx19:01:03

Is there a quick/easy way to have the java build spit out the last piece of source it was on when it died? I’m looking for a needle in a haystack of markdown being parsed as a macro, and it’s painstaking

talexxx19:01:27

java.lang.ClassFormatError: Unknown constant tag 112 in class file is a little opaque.

talexxx19:01:35

Wait, never mind. I think the parser is dying on sheer length

7h3kk1d20:01:14

What do people use for generating documentation? I’m thinking of using swagger for apis but not so sure about for regular docs.

genmeblog20:01:04

try Marginalia

bostonaholic20:01:42

I use codox and spit them to /docs. Then, if you’re on GitHub, setup the repo’s GitHub Pages to point to /docs

bostonaholic20:01:24

then your docs are published to https://<user|org>.

alexbaranosky20:01:35

@lvh that's why I never use 'are'... haven't used it in years for this reason.

genmeblog20:01:36

I Codox you can also embed Klipse snippets

7h3kk1d20:01:07

That’s interesting

genmeblog21:01:37

Marginalia let's you embed Markdown everywhere and build html with side notes about whole source code

dominicm21:01:51

@miikka I guess a graph of memory consumption by a call.

7h3kk1d21:01:55

@tsulej That’s super pretty.

geek-draven21:01:29

@talexxx check out https://www.overops.com, I use it for keeping an eye on jars that I'm running - it's very handy for seeing what failed and why, especially as it displays the values of the parameters that were being used at the time. Must have saved me hours of scrolling through log files, it's free to use on a single jvm, then you pay if you want multiple ones

sova-soars-the-sora22:01:16

preferred way of sorting contents of an atom... ?

qqq22:01:37

(swap! atm sort) ?

arthur22:01:54

(let [a (atom [1 4 3 2])]
  (swap! a sort))
(1 2 3 4)

arthur22:01:24

guess it depends what's in the atom

sova-soars-the-sora22:01:18

How about an atom with a nested vector... such as

(def nf-atom (atom {
                                              :nf [{:not-used stuff}]
                                              :things-i-wanna-sort [{:id 1 :message "I could be first..."}
                                                                                               {:id 2 :message "... or I could be first"}]}))

sova-soars-the-sora22:01:26

pardon the horrendous formatting

qqq22:01:45

why is "atom" relevant here, is this question relaly "how do I sort this complicated sturcture" ?

sova-soars-the-sora22:01:16

Pretty much. I have an atom that holds a lot of application state, but I wasn't sure how to sort just a subset of it...

sova-soars-the-sora22:01:01

(def nf-atom (atom {
  :nf [{:not-used stuff}]
  :things-i-wanna-sort 
  [{:id 1 :message "I could be first..."}
     {:id 2 :message "... or I could be first"}]}))
(might be easier to read)

qqq22:01:31

you want to read up on swap!, update-in, and sort

qqq22:01:52

sort will let you specify the sort function, update-in will let you choose which subset of data to sort (leaving the rest unchanged), and swap! will let you update the atom

arthur22:01:59

(swap! nf-atom update :things-i-wanna-sort #(sort-by :id %))
{:nf [{:not-used stuff}], :things-i-wanna-sort ({:id 1, :message "I could be first..."} {:id 2, :message "... or I could be first"})}

genmeblog23:01:04

do you know maybe why I have an error in this case

genmeblog23:01:14

((comp int #(long 1234567890123)))

genmeblog23:01:37

but not in this case

(int (long 1234567890123))

genmeblog23:01:20

clojure.lang.RT.intCast checks the result of the cast and if it's different than passed throws exception. That's ok. But id doesn't in second case.

genmeblog23:01:37

*than passed argument

qqq23:01:38

I have a src/foo/bar.cljc -- there's someway to have the cljs version of foo/bar use a macro from the clj version of foo/bar

qqq23:01:44

how do I do that without getting a circular dependency error?

joshjones23:01:44

@tsulej I get an error in both cases -- the number is too large to be cast to an int type

genmeblog23:01:31

forgot to mention that unchecked-math was set to true

genmeblog23:01:48

user=> (set! *unchecked-math* true)
true
user=> ((comp int #(long 1234567890123)))

IllegalArgumentException Value out of range for int: 1234567890123  clojure.lang.RT.intCast (RT.java:1205)
user=> (int (long 1234567890123))
1912276171

hiredman23:01:10

you should set the unboxed math warning

hiredman23:01:17

I forget the name

hiredman23:01:51

anything the behavior of int is different there because the higher order usage isn't inlined by the compiler

hiredman23:01:08

with unchecked-math, the int inlines as unchecked-int

genmeblog23:01:43

aaaah, ok, thank you

genmeblog23:01:01

((comp unchecked-int #(long 1234567890123))) works perfectly

genmeblog23:01:11

and thanks for primitive-math this is the solution for my issues