Fork me on GitHub
#clojure
<
2015-06-16
>
cmdrdats07:06:34

@seancorfield: Thanks, a standalone app sounds like a good idea - it always annoys me to have once-off patch code committed to a codebase

cmdrdats07:06:00

@arohner: I know exactly what you mean by the brittle thing - we currently use that in our php system and when a patch doesn’t work, have to tweak the live value and try run again after updating the code.. very touch and go. I like the idea of idempotent patch functions - I’d like to not have to rely on repl access though.

cmdrdats07:06:04

@meow: Ye, I could write a boot task, but I prefer not to run build tools like boot or leiningen on our production environments

cmdrdats07:06:41

@seancorfield, @arohner, @meow - thanks for the feedback! really appreciated.

ulsa08:06:52

@borkdude: not sure if an uberjar is packaged similar enough to a maven-shade-plugin jar, which they recommend

ulsa08:06:51

would be great if someone could get clojure working on lambda using maven-shade-plugin, and then we could compare uberjars

borkdude08:06:25

@ulsa: "shade - i.e. rename - the packages of some of the dependencies"... I never came across anything like that in uberjar

ulsa08:06:20

maybe boot can be coaxed to package it the way aws wants

ulsa08:06:41

just wish I knew what the problem was, and what the hard requirements were

ulsa08:06:00

interesting

ulsa08:06:29

trying lein pom

ulsa09:06:36

I'm so not friends with clojure on maven

ulsa09:06:58

How can I get maven-shade-plugin to understand that Leiningen has placed class files under target/base+system+user+dev/classes? Or better yet, how can I get Maven to compile them and place them somewhere that it actually knows?

martinklepsch09:06:15

I tried using it a couple of times but always got stuck with this error message:

java.io.FileNotFoundException: target/coverage/coverage.css
I created the file manually but no dice.

ulsa09:06:04

OK, I seem to get the same error in lambda when running a maven-shade-plugin jar as with a lein uberjar, so perhaps there's some intrinsic Clojure/Lambda class-loading issue?

Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath: 
	at clojure.lang.RT.load(RT.java:443)
$ jar tf target/lambdaclj-0.1.0-SNAPSHOT.jar |grep clojure/core__init
clojure/core__init.class

mdallastella09:06:40

Is there a better way to parse a String into a number than (Integer/parseInt “1”)?

mdallastella09:06:00

Ok, read-string does the job

dnolen09:06:42

mdallastella: you probably want (Integer/parseInt “1”), read-string is really for source so not safe. There’s also the clojure.edn ns, but honestly I would prefer Integer/parseInt in the case I know I’m just reading numbers.

niwinz09:06:57

Integer/parseInt is the most safe way for do it as far as I known

mdallastella09:06:15

@dnolen, @niwinz: I see, thanks. read-string is probably “too much” for the task.

ragge10:06:44

@ulsa: got clojure running using a java shim and some classloader trickery

ragge10:06:47

it's not ideal as class name is fixed

ragge10:06:03

but I believe you can get around it by possibly passing the var as an env variable etc

socksy10:06:50

but you can just create the überjar and upload this to lambda as is? I haven’t looked at the tech details of the java support for lambda yet

socksy10:06:08

or does it require a zip file similar to the node.js situation?

ragge10:06:38

nah, jar works

socksy10:06:54

reading now, you can do both (makes sense)

ragge10:06:56

but you don't want to replicate the java shim everywhere

ragge10:06:28

if you could tell the shim which clojure var to invoke (through some kind of env variable for example), it would be reusable

martinskou11:06:36

Is there a way to call a function when using deconstruction. I'm using something like (defn route-erp-customer [{{id :id} :params :as req}] , but id i a string and i would like to convert it to an int...

txus11:06:07

@ragge: nooooooiceeee! 😄 been waiting for something like this for a while

edipofederle11:06:52

Someone working with genetic algoritms in Clojure?

borkdude11:06:24

@ulsa: maybe it's a good idea to stalk https://twitter.com/jeffbarr about it (author of the blog)

martinklepsch12:06:56

@martinskou: functions are not allowed in map destructuring

ragge13:06:01

@ulsa @borkdude Updated spike to allow specifying the var to invoke, updated readme to show sample invocation: https://github.com/uswitch/lambada#usage

bozhidar14:06:04

(responsibly)

borkdude15:06:15

what are you guys and girls' favorite in memory database for testing clojure apps?

Slackbot15:06:15

I think you mean pals...

sveri15:06:24

@borkdude: h2 or datomic

tcrayford15:06:04

@borkdude: what kind of database? sql?

borkdude15:06:41

I currently work on a project that already has a PHP+MySQL site and I'm building a web app on the side using Clojure/ClojureScript using the same database. I haven't used lobos for ddls, so I had to do some string manipulation to re-use the same ddls in the in memory database which was hsqldb. Also I bumped into some 'locking' problem that hsqldb has turned on by default. I wonder if H2 is a better starting point for next projects.

tcrayford15:06:14

@borkdude: reminder that the datomic dev transactor uses h2

tcrayford15:06:20

think they prolly picked that for a reason 😉

sveri15:06:09

@borkdude: I would go with the same db in dev that I want to use in production, just to make sure I hit problems early

sveri15:06:44

@borkdude: as mysql does not have a in memory version, IIRC, I'd maybe go with a docker env setup or something like that

borkdude15:06:07

@sveri: run against a mysql test db? could do that. I'd have to set it up in CI too then.

nikolap15:06:55

for what it's worth, there is a MEMORY storage engine in MySQL: https://dev.mysql.com/doc/refman/5.7/en/memory-storage-engine.html

nikolap15:06:38

quite a lot of limitations there, though

tcrayford15:06:56

@borkdude: it's tradeoffs imo. communicating with in memory stuff is often much faster than talking to a server. If you estimate you have 10 devs, each running tests once a minute, and the mysql build takes 15s, and the h2 build takes 1s, and the cost of shipping a bug to production is X, and the average dev salary is Y etc. You can run calculations based on that and see if it's worth it

mdallastella15:06:23

When I think about a sql database, mysql is not exactly the first thing that comes in my mind 😏

borkdude15:06:16

@mdallastella: I know right, it's a legacy decision.

borkdude15:06:57

@mdallastella: I'm extending a PHP/MySQL site with Clojure and ClojureScript simple_smile

mdallastella15:06:24

@borkdude: sorry for the digression, no flame intended 😃

borkdude15:06:51

for now I'll stay with HSQLDB. I didn't write all those string/replaces in vain today. I could of course have used InstaParse 😛.

sveri15:06:15

* what @tcrayford said. Maybe it is also worth to have multiple layers, having a second layer with a mysql db for cont. tests running every hour and a "first" layer using an in memory db

txus15:06:11

I was wondering if you could release a snapshot of https://github.com/metosin/ring-middleware-format ?

txus15:06:22

right now it’s broken with compojure-api stable and snapshot :S :S :S

txus15:06:40

there’s a fix in there from upstream

juhoteperi15:06:01

Interestring. I wonder why I haven't noticed the problem.

txus15:06:09

can’t wait to use compojure-api in a bunch of projects we have, it’s an amazing idea!

juhoteperi16:06:47

@txus: I'm not sure if that error would be fixed by that r-m-f change. It looks more like mismatched kwargs somewhere.

juhoteperi16:06:13

And at least Compjure-api example is working for me.

juhoteperi16:06:20

@txus: Are you setting the options in defapi (or api)?

txus16:06:03

strange. I realized that wrap-restful-params and wrap-restful-response have different signatures (-params takes kwargs while -response takes a hash), and they used to have the same signature

txus16:06:13

@juhoteperi: tried setting them and letting it run with defaults

juhoteperi16:06:24

Yes, I changed it in the fork. Might have been a bad idea 😞

txus16:06:45

that’s alright though, ring-middleware-format HEAD uses the right signature

juhoteperi16:06:55

Ah, in the fork both should take maps.

txus16:06:59

but 0.6.0 uses the old one still, that’s why it breaks :S

juhoteperi16:06:06

Nope, thats a map.

txus16:06:37

oh true, destructured from the vector

juhoteperi16:06:53

R-m-f is unfortunately a bit of a mess currently, I've been trying to get ngrunwald to merge our (non-breaking) changes to upstream.

txus16:06:04

ugg i don’t really understand why it fails then.

txus16:06:30

that “No value supplied for key” I’ve gotten even going deep in the code and calling the functions manually with a map instead of kwargs :S

txus16:06:38

but could only reproduce it with the release versions

txus16:06:44

master branches seemed to be fine

txus16:06:58

(of compojure-api and r-m-f)

juhoteperi16:06:40

Do you happen to have both versions of r-m-f in classpath? Check lein deps tree or something.

txus16:06:59

no… weird :S

juhoteperi16:06:21

@txus: Try https://github.com/metosin/compojure-api-examples and if that works, try to see whats different with your project or create an example which I can use to reproduce the error

voxdolo17:06:07

is there a lib out there that does a good job of surfacing actual JDBC errors? I'm on postgres and half the time the error is inside nextException and the other half the time it just plainly complains about the transaction being aborted with no details. I, of course, can figure out what the issue is, but it makes it hard to surface that for UIs without writing a ton of special checking code around every insert/update.

ghadi17:06:03

can you say more voxdolo? clojure.java.jdbc just unwraps RuntimeExceptions if they're there

voxdolo17:06:58

So in the case of a conflict on a unique column, when run using the postgres adapter, I'm currently just getting a "transaction aborted" error which says nothing of the nature of the error. Other times when the transaction fails, I get an error message telling me to "getNextException" to see the actual error [which tends to be more descriptive ("such and such has violated a foreign key constraint")]

voxdolo17:06:54

I'd love it if the error messages were better and more uniformly presented… I don't ever want to have to write special handling logic to see if there's an error in nextException.

voxdolo17:06:22

just wondering if someone has done the work to try to surface the actual error messages rather than the sad state of affairs that currently is presented

voxdolo17:06:24

Perhaps a meta-issue is that I'd really rather not have to check that something like a uniqueness constraint hasn't been violated before hand by querying before inserting/updating. I'd rather fire off an insert, catch an exception with a sensible message and show an error to a user as derived from that.

ghadi17:06:40

The wonderful world of hiding information in stacktraces.

voxdolo17:06:03

yep simple_smile I wish things were a bit more easy to interrogate for useful information and in a standard manner.

ghadi17:06:21

So, a couple things. In our code base (mysql) we catch a DuplicateKeyException explicitly. You could do that, but it may be hidden in nested exception causes

ghadi17:06:42

Additionally, if you want something displayable, clojure 1.7 has Throwable->map

ghadi17:06:08

which turns it into data that you could introspect generically

ghadi17:06:45

neither is ideal

voxdolo17:06:07

I'll look into Throwable->map… not sure if we can make the 1.7 jump just yet though.

ghadi17:06:20

The insert/update could handle it directly too, similar to mysql's ON DUPLICATE KEY clause

voxdolo17:06:05

interesting. I'll have to see if postgres offers something along those lines.

tcrayford17:06:11

@voxdolo: it doesn't yet. It's hopefully coming in with 9.5

devn17:06:58

Well look who it is, @voxdolo and @ghadi right off the bat.

voxdolo17:06:00

Looks like people generally use it to support UPSERT

voxdolo17:06:17

@devn related: how'd you know I'd just gotten off a bat?

ghadi17:06:28

voxdolo something like

(->> (iterate #(.getNext %) throwable)
     (remove (comp #{RuntimeException TransactionException} class))
     first)

devn17:06:54

I was pinging folks in the clojure IRC channel, but it's beginning to look like Slack has captured the hearts and minds of many.

voxdolo17:06:37

ghadi: thanks, I'll try something on those lines out

voxdolo17:06:32

devn: are you defn on clojuredocs? I'm guessing so and have been meaning to ask (and subsequently thank you for all your examples over there)

devn17:06:15

@voxdolo: yes i am, and no problem!

devn17:06:39

i found a lot of them by spelunking through my http://getclojure.org thingy

devn17:06:01

which is, btw -- horribly out of date

voxdolo17:06:26

Oh, nice. I remember you mentioning that some time ago… I'll add it to my resources simple_smile

devn17:06:28

i need to run the last year and a half through the sandbox on a new clojure version

voxdolo17:06:57

Thanks for making so many great resources available @devn simple_smile

devn17:06:44

aw shucks 😊

voxdolo17:06:52

we've all pretty much got you to thank for http://clojars.org too. so thanks again simple_smile

devn17:06:35

@voxdolo: only the redesign portion. @xeqi, technomancy, and weave are the real heroes

voxdolo17:06:48

Ah! well, thanks to them as well simple_smile I had no idea.

andrea.crotti18:06:13

what would be another way to accomplish this?

andrea.crotti18:06:14

(def sample {:x 10 :y (+ 2 (:x sample))})

andrea.crotti18:06:35

I just want a map with values that depend on each other somehow

andrea.crotti18:06:55

I guess maybe a let is the only way

andrea.crotti18:06:05

but then I can't produce a single map

devn18:06:24

i'm confused what you're looking for here

devn18:06:00

(let [x 10]
  {:x x :y (+ 2 x)})

andrea.crotti18:06:51

yeah I can do that true, I just thought I could access the map that is not created yet

andrea.crotti18:06:58

but it makes sense that I don't

devn18:06:14

i mean:

(let [m {:x 10 :y 0}]
  (update-in m [:y] + 2 (:x m)))

devn18:06:38

which in 1.7 can just be update with no []s around the :y

devn18:06:24

also @andrea.crotti -- #C053AK3F9 might be a better place to take this conversation

devn18:06:38

happy to help you over there

devn18:06:53

So, is anyone here using logback in their Clojure applications?

Lambda/Sierra18:06:57

devn: All the time.

bmay21:06:42

i'm considering writing a "web service" that continuously queries the twitter API and stores results in a db. i'd then like to display those results on web pages. can a single leiningen/compojure web app do both those things simultaneously?

alejandro21:06:14

yeah, you’ll probably want to kick off some working process / thread / agent on application start

bmay21:06:54

excellent. thanks

devn21:06:49

@stuartsierra: @moocar either of you have any experience pushing logs to logstash?

moocar21:06:48

yep! What’s the problem?

devn21:06:53

ever use that?

devn21:06:38

reason i ask is because there seems to be a fair amount of garbage required to get the data it's using somewhere closer to correct

devn21:06:10

for instance, when an exception is logged from my.namespace, the encoder and layout say it's from logging.clj

devn21:06:19

the line numbers are not correct, etc.

moocar21:06:09

We’re using the latter, though only the net.logstash.logback.encoder.LogstashEncoder

devn21:06:27

with tools.logging i assume?

moocar21:06:46

We’ve never noticed any incorrect line numbers or anything like that, though it does produce some fields we don’t care about

moocar21:06:51

no, we use slf4j directly

devn21:06:57

i bet that's the difference.

moocar21:06:13

could be, there might be some dynamic binding across threads or something

devn21:06:59

im thinking it might have to do with the fact that an agent is being used

devn21:06:17

@moocar: if you're logging directly with slf4j that probably wouldn't be an issue