Fork me on GitHub
#clojure
<
2015-10-29
>
xeqi00:10:50

@martinklepsch: agreed. I don't remember it being something asked for by in the tooling circles I frequent. I will be interested to see how long it takes and how things migrate

xeqi00:10:25

I could see it being quite useful for runtime tools though

ghadi01:10:19

I thought we were over the whole global DB madness 😞

ghadi01:10:26

Do libs still do that?

xeqi01:10:55

yesql lets you set one if you want to, but I always just pass the db-spec

verma02:10:17

I am trying to start a http-kit server with reload and cors but for some reason I am unable to get it to work, I still get CORS failures from my browser. My server is a component component, here’s here I am trying to wrap the handller: https://gist.github.com/verma/a581e6425ad0b26d0b7e#file-server-clj-L51-L53

verma02:10:27

is there anything obvious I am missing here?

xeqi02:10:26

verma: are you using https://github.com/r0man/ring-cors for wrap-cors?

verma02:10:37

xeqi: yes

verma02:10:05

xeqi: my bad, I was unknowingly requesting data from a non-existant service 😕

tap03:10:37

What's clojure equivalent of ruby's caller method? http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-caller

tap03:10:35

To put it another way, if a function is call from multiple places, at runtime, is there a way to print out caller for debugging purpose?

Alex Miller (Clojure team)04:10:40

the Thread class has methods to inspect the stack

Alex Miller (Clojure team)04:10:00

(Thread/dumpStack) will just dump that thread's stack to stderr

Alex Miller (Clojure team)04:10:29

or (Thread/getStackTrace) gives you an array of StackTraceElement's that you can traverse and do whatever

tap04:10:50

Ahh, right. Thanks @alexmiller

timgluz09:10:32

@verma, i had similar issue with r0man/ring-cors - it just raised null-pointer exception or empty request, i switched to ring.middleware.cors ( https://github.com/jumblerg/ring.middleware.cors )

timgluz09:10:35

@rbxbx: i’m using yesql with hikari-cp and yesql - works very well

timgluz09:10:17

and i saw that someone was complaining about yesql pollutes namespace, there’s require-sql macro, i’m using it to prevent confusion between models function and yesql query - https://github.com/krisajenkins/yesql/blob/master/src/yesql/core.clj#L40

mbertheau11:10:05

Is there a let-cond? I.e. where I have the cond test expression available in the body?

martinklepsch11:10:16

has anyone considered writing an acme client in clojure/java? https://github.com/letsencrypt/acme-spec

verma12:10:17

thanks @timgluz I’ll take a look at it.

lvh14:10:06

Whoa. enlive is awesome. Seems to be less popular than I would’ve thought, though.

michaeldrogalis14:10:19

@alexmiller: It's really encouraging to see core.async come out with those new features. Thanks for moving that along. simple_smile

Alex Miller (Clojure team)14:10:44

happy to get it released finally!

Alex Miller (Clojure team)14:10:10

I know there are a pile of tickets there too and I would like to start whittling those down too

michaeldrogalis14:10:13

Already using both poll! and offer! in Onyx, yielding a real perf improvement since we're not doing blocking operations anymore.

Alex Miller (Clojure team)14:10:13

you're not actually polling are you? :)

lvh14:10:34

It makes manifold less necessary I guess

lvh14:10:38

let-flow is still the best though

michaeldrogalis14:10:48

@alexmiller: In some cases we're planning to, yeah. It's helpful for cases where you want to read as much data from an input source as possible and immediately process it without waiting - which is good when the time needed to process the payload is low.

michaeldrogalis14:10:12

Weird trick from the Mechanical Sympathy guy (Martin Thompson).

Al Baker16:10:49

@michaeldrogalis: there any write up on creating onyx plugins?

ul16:10:31

Does anybody have experience with rewrite-clj? i feel myself stupid. how to replace smth like [:div.row ...] with (row ...) in tree after i found it with zip/find-value? i've tried (z/edit (z/up (z/find-value x z/next :div.row)) (fn [x] (n/list-node (cons 'row (rest (n/children x)))))), but i get

java.lang.UnsupportedOperationException: 
  rewrite-clj.node.protocols/eval1689/fn                     protocols.clj:   60
rewrite-clj.node.protocols/eval1644/fn/G                     protocols.clj:   51
                   boot.user/eval4246/fn  boot.user7362033130061499799.clj:    1
                                     ...                                        
                      clojure.core/apply                          core.clj:  626
            rewrite-clj.zip.edit/edit/fn                          edit.clj:   34
          rewrite-clj.zip.edit/edit-node                          edit.clj:   25
                                     ...                                        
                      clojure.core/apply                          core.clj:  626
                        clojure.zip/edit                           zip.clj:  214
                                     ...                                        
               rewrite-clj.zip.edit/edit                          edit.clj:   34
                                     ...                                        
                      boot.user/eval4246  boot.user7362033130061499799.clj:    1
                                     ...                                        
                       clojure.core/eval                          core.clj: 2927

Al Baker17:10:24

@michaeldrogalis: ah, didn't know there was one - thanks

aaelony19:10:07

When multiple developers work on a clojure project and build uberjars of the same project as it iteratively evolves, there is a risk that the version numbers in the project aren't updated. It would be great to hear other's experience with this and how this is dealt with. For example, should an autoincrement be added to the version? or should the initials of the last developer be added? e.g.

(defproject myproj "0.0.1-SNAPSHOT-AA-01" 
? if so, how best to make this automatic, slurp the project.clj file to make the changes and put it back? eager to hear thoughts on pros and cons...

dm320:10:59

something seems wrong with the way you develop/release if this is happening

dm320:10:16

could you elaborate on your development process a bit more?

aaelony20:10:14

the question actually is what should the development process be

aaelony20:10:18

I'm used to working on projects alone, but now have two others joining it. Want to craft a solid process.

roberto20:10:19

I don’t see how this would be an issue, unless each developer is deploying their own working branch.

roberto20:10:35

I might be missing something

roberto20:10:48

working on maven based projects is similar.

ecelis20:10:33

aaelony: just use git or any scms and don't add any .jar to it, only code files

aaelony20:10:33

we extensively use git. the issue is that we prefer end-to-end tests from different uberjar builds and want to make sure they have unique (informative) names

roberto20:10:06

run the tests on the branches

roberto20:10:21

have the ci build each branch when it is pushed

aaelony20:10:26

once the end-to-end tests are valid for an uberjar, then it is eligible for production (if desired)

roberto20:10:42

we run it on each PR instead of branch

roberto20:10:59

so, you create a PR, the CI runs the tests on that branch

aaelony20:10:11

this is exactly what I want to hear pros/cons on simple_smile

roberto20:10:38

end to end tests take long, so might as well have the CI do it, and you only worry about it when it fails.

roberto20:10:10

cons: if you have lots of PRs, your server can become slow and overwhelmed

roberto20:10:34

with jenkins you can limit the amount of builds it can do simultaneously.

roberto20:10:57

cons: it might take a while before you get any feedback, not sure if that is a cons anyway because e-to-e tests are by their own nature very slow to run.

roberto20:10:41

another cons might be that you need some jenkins expertise, if you are using jenkins, and you don’t have anyone inhouse with experience. But it is worth learning anyway.

dm320:10:55

for unique project versions you can take the git SHA

aaelony20:10:13

this is very true, some of the end to end tests do in fact take a long time.

roberto20:10:30

yeah, using the git SHA is a good idea. This is handy when you are building libraries that you use inhouse

roberto20:10:40

and you want to test a library currently under development

roberto20:10:49

and make sure it works with your own code.

aaelony20:10:54

using the commit as the project version would be cool. I wonder how that would work...

aaelony20:10:18

a library approach would indeed be cleaner

dm320:10:41

assuming you're on unixy systems - execute a shell and get the variable inside project.clj

ecelis20:10:42

aaelony: you could make use of a git hook to change the version to reflect the commit hash

aaelony20:10:55

centos, so no problem

ecelis20:10:08

mmm... dm3 solutions is better

aaelony20:10:26

thanks. this is quite good.

aaelony20:10:50

lein-sha-version looks awesome!

aaelony20:10:15

thanks for all the comments. perfect.

dm320:10:26

bonus - uses jgit, so portable

bradford21:10:35

Doing some work for a 30 y/o travel company in the UK. Replaced 1,000 lines of SQL with about… 15 lines of Clojure? Drinking cask beer to celebrate.

donaldball21:10:17

I don’t even want to think about how one would reliably analyze the effects of 1000 lines of sql

bradford21:10:42

Let’s put it this way … to start, there’s 17,291 columns in one table.

bradford21:10:14

The effects? I’m drinking. That’s an effect.

bradford21:10:54

The story is (gather round 🔥) they have a homebuilt web analytics thing. It lets you define any field/collection in JS, and it’s written to the backend. As a column. In the db. This company has 1500+ web properties and 900 employees.

bradford21:10:02

so…yeah

bradford21:10:07

normalize all the things

dot_treo21:10:48

Some time ago when they just started creating this thing someone probably has thought that it was a clever and elegant solution

bradford21:10:11

I fear clever.

dot_treo21:10:58

yep, whenever I think "oh what a clever solution" my next thought is "let's not go there, 'tis a silly place"

stig21:10:28

Sadness:

user> (=  (byte-array 0) (byte-array 0))
;; => false
— how do I compare two byte arrays?

stig21:10:06

(Sorry if that is a very noob question.)

donaldball21:10:43

Turn ‘em into seqs?

nullptr21:10:45

(apply = (map seq [(byte-array 0) (byte-array 0) ...]))

stig22:10:05

I suppose, but it’s not ideal. Obviously, the above was a simplified example to illustrate my confusion. I suppose I need two checks now; one that I’ve got a byte array back, and another that munges the array into a vec/sec and checks that it has the correct values.

nullptr22:10:23

(the unexpected behavior is because you’re getting reference equals semantics, aka identical? in clojure)

nullptr22:10:24

it’s ok to call seq on other seqable things, not just byte arrays — so, it may be safe to do w/o a special case check

mdaines22:10:58

You could drop down into Java …. (Arrays/equals

dot_treo22:10:52

or.. it does, maybe I misspelled something in my previous test

dot_treo22:10:52

yep, I definitely just spent 5 minutes figuring out why (byte-array 0) is not equal to (byte-array 1)

stig22:10:37

@dot_treo: Thanks, that looks like what I’m after!

user> (java.util.Arrays/equals (byte-array 0) (byte-array 0))
;; => true
user> (java.util.Arrays/equals (byte-array 10) (byte-array 10))
;; => true
user> (java.util.Arrays/equals (byte-array [1, 2,30]) (byte-array [1, 2, 30]))
;; => true
user> (java.util.Arrays/equals (byte-array [1, 2,30]) (byte-array '(1, 2, 30)))
;; => true

dot_treo22:10:16

there is also a deepEquals for two dimensional arrays

stig22:10:57

Cool. That might come in handy, but equals is enough for the simple problems I’m currently having simple_smile

stig22:10:53

(If anyone wonders: yes, I was stuck on the very first exercise in the Matasano crypto challenges: http://cryptopals.com/sets/1/challenges/1/ )

bradford22:10:03

My brain’s fried and I could use a hand. I’m trying to return a map filtered by a coll of nested keys. https://gist.github.com/LusciousPear/24a65467091c3caf3368 — In other words, return only the key/values in (decode test-2) that are in fields. I’m puzzled trying to find an elegant way to do it.

rickmoynihan23:10:20

@aaelony: We're in a similar boat to you, regarding CI and leiningen - and I've yet to find a good solution... The problem I have with things like lein-sha-version is that yes it gives you repeatable builds -- but it then means that your CI effectively stops doing integration - because all of your versions are locked... SNAPSHOTs give you this, but at the expense of not knowing auditably which SNAPSHOT ended up in an artifact. e.g. we have a clojure project B that depends on a project A... When I push a commit to A I want jenkins to first build A and run its tests, then trigger B to be built and tested and with the new A dependency. If and only if the downstream builds all pass do I want B to be deployed to my jars repository with the updated dependency on A I haven't figured out all the moving parts yet - but my feeling is that you could build this out of a middleware like this one: https://github.com/RickMoynihan/lein-build-env that only swaps out -SNAPSHOT versions - with an incrementing build ID then you can use something like lein ancient to update to the latest... Some other problems are that for the downstream builds to see the upstream deps you need to lein install them before you know if they're good... Because .m2 is global if the candidate is bad you've installed a broken jar which can contaminate other builds - so I suspect you might also want to set :local-repo and clean up if it fails

rickmoynihan23:10:24

Basically I think there are lots of moving parts required to do it properly

aaelony23:10:01

@rickmoynihan: agree. I my case though, I think lein-sha-version is sufficient. It will enable uberjars to be built and tested, and then another process can decide whether or not to make it production.

stig23:10:06

Oh boy, criterium doesn’t half eat battery simple_smile

aaelony23:10:21

We could even make a database table about the characteristics of each build 😉

rickmoynihan23:10:49

@aaelony: that works if you don't have lots of downstream project dependencies -- but we have about a dozen (and its growing weekly) -- and updating version numbers feels like a job the CI should be doing

aaelony23:10:00

that is true. we're at the end 😉 ... but if you can include the downstream project deps in your assessment of the builds... (??)

rickmoynihan23:10:43

Sorry - not sure what you mean...

aaelony23:10:59

maybe I misunderstood.. you said "downstream project dependencies -- but we have about a dozen", can you name that dozen as one thing and test it as one thing?

rickmoynihan23:10:36

they're a dozen different projects

aaelony23:10:46

I would hope however, that someone on this list has probably seen an effective solution for this though 😉

aaelony23:10:54

perhaps they can weigh in

rickmoynihan23:10:28

I've been hoping that too! simple_smile

rickmoynihan23:10:06

@aaelony: Another problem is that you effectively have to duplicate parts of the project.clj's as jenkins build triggers to get jenkins to automatically trigger downstream builds... maintaining this is a pain

rickmoynihan23:10:25

if you forget to keep it in sync, jenkins can end up triggering more builds than it needs to... and likewise if you forget to add a link then projects you were hoping would be built aren't... it doesn't happen often -- but when it does its a small but annoying inconvenience

aaelony23:10:31

well if jenkins is part of the problem...

rickmoynihan23:10:53

its not so much jenkins -- just that it doesn't have knowledge of how to trigger downstream builds based on information in the project.clj files

rickmoynihan23:10:05

I suspect any CI would have the same issue -- personally it feels more like leiningen/maven is the problem here

aaelony23:10:52

and it can't all be one build...

rickmoynihan23:10:38

not really - they're different projects for different clients / audiences