Fork me on GitHub
#clojure
<
2016-03-03
>
matthavener00:03:21

mattly: fwiw I needed that once and never found a library, just ended up writing a function to generate query params manually

jethroksy05:03:29

can someone help me with my regex issues? I’m trying to extract out everything within square brackets into capture groups:

"hello" -> (“hello”)
“hello there” -> (“hello there”)
“hello there [foo,bar]” -> (“hello there” “foo” “bar”)

jethroksy05:03:55

java’s posessive quantifiers are not working like I expect them to

jonahbenton05:03:22

@jethroksy: what do you currently have?

jethroksy05:03:04

#"(.*)\s+?(\[.*\])?”

jethroksy05:03:31

right now I’m just concerning myself with separating the stuff in brackets from the stuff that aren't

jethroksy05:03:52

this doesn’t work for the first case: ”hello” -> (“hello”)

jonahbenton05:03:32

yeah, \s+? means one or more whitespace

jethroksy05:03:03

initially I wanted to make (\[.*\])?+ possessive

jethroksy05:03:26

but I don’t think the X?+ syntax is allowed here

jonahbenton05:03:32

it sounds like you want everything before [

jonahbenton05:03:59

though you might not have the [

jethroksy05:03:24

right, but the square brackets are optional

jethroksy05:03:18

May I ping you again later if I have any problems?

krchia05:03:30

despite the documentation on lein-migratus, i don’t seem to be able to understand what it does

krchia05:03:56

the only times i’ve gotten it to work is by deleting my old tables, then running $ lein migratus

krchia05:03:13

but a migration should keep my data and just change the schema, right?

krchia05:03:56

i don’t see any changes in my postgresql columns, so im confused

hiredman07:03:14

are you putting changes in a new file every time you run migratus?

casperc11:03:54

I am trying to load a bunch of files in a folder while in a jar. I found this: http://stackoverflow.com/questions/11012819/how-can-i-get-a-resource-folder-from-inside-my-jar-file

casperc11:03:14

They do this though:

final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());

casperc11:03:28

How to I call getClass() from Clojure? I assume it implicitly hits a class but which one?

casperc12:03:57

Basically i am missing a reference to “this” in Clojure, which is implicit in the above

dm312:03:44

that snippet is running inside some class

dm312:03:58

you just need to choose a class from the jar explicitly

dm312:03:58

(.getProtectionDomain MyClass)

shanekilkelly13:03:11

Anyone here using aleph/manifold in production for web servers? any comments on performance compared to the usual compojure/jetty/ring stack one would get with (for example) Luminus?

nha13:03:46

@shanekilkelly: you may be interested in #C0702A7SB also

shanekilkelly13:03:50

@nha, indeed, meant to mention yada in the post above simple_smile i’ve been looking at yada/bidi/aleph/manifold recently and would be curious to hear from anyone who has deployed a similar stack in production.

shanekilkelly13:03:54

I’m most interested in high-performance and massively concurrent clojure network servers, think the kind of thing Go or Node.js are commonly used for.

octahedrion15:03:37

what's the fastest way to concatenate 2 vectors ?

Chris O’Donnell15:03:59

What comes to mind for me is (reduce conj v1 v2)

octahedrion15:03:19

@rm I meant the fastest way performance-wise

rm15:03:55

performance-wise you don't want to concat two vectors

rauh15:03:52

@codonnell: (into x y) would use transients

rauh15:03:10

Sorry, I meant @octo221

Chris O’Donnell15:03:00

@rauh: nice, that is a better solution

rickmoynihan15:03:03

Does anyone know of a ring middleware to handle a file upload, where the file is in the body of the request itself; i.e. it's not multipart form encoded? I need it to also buffer into a tempfile; or at least not load the body into memory, because it may be several GBs

octahedrion15:03:20

@rm yes, that's why I'm asking!

octahedrion15:03:10

@rauh: thanks, that's what I wanted to know

octahedrion15:03:57

@rauh exactly what I needed to know simple_smile

jcromartie16:03:52

@octo221: you can use into

jcromartie16:03:00

oh, you got it

peeja16:03:56

What's the correct way to ask whether a var exists for a given symbol?

jcromartie16:03:37

resolve for the current ns, or ns-resolve with the ns as argument

peeja16:03:49

Ah, perfect, thanks

jonahbenton17:03:35

hey @rickmoynihan: by what means is your upload occurring- not through a file button on a web page? file uploads are included in request bodies; the multi-part form encoding is the format of the request body data.

rickmoynihan17:03:28

@jonahbenton: it's for an API - not a web form... not actually tried it yet but yeah it looks like ring just puts an inputstream in the :body for you - which is fine

liathit20:03:20

What is ^ symbol in Clojure? Example:

(defn get-elmt [activity elmt]
  (str (.getText ^TextView (find-view activity elmt))))

liathit20:03:25

hiredman: crucialrhyme thx 😉

jjttjj20:03:43

I'm using duct with a reloaded workflow. Everything was working great until I did a windows update and restarted my computer. Now when I attempt to start my system I get an exception

duct.component.handler.Handler cannot be cast to clojure.lang.IFn
i know it's a long shot but does this look familiar to anyone?

hiredman20:03:53

jjttjj: the full stacktrace will have more information about what line the error occurs on, but somewhere you have an instance of Handler that you are trying to invoke as a function

hugesandwich21:03:37

More of an opinion, but which do you feel is a better signature for an API that calls an underlying Java API with 3 different overloads, each with drastically different behavior (yes, the underlying api is badly designed). Bear in mind that this will be adapted to work on a protocol:

hugesandwich21:03:37

I personally feel the cond is a bit of an anti-pattern in a lot of cases, but there's a few libraries I've found doing similar things to support/prefer passing maps as args

jcromartie21:03:06

I think it would depend on how drastically different the behavior is

jcromartie21:03:18

are you talking the difference between a pure function and something with side effects?

hugesandwich21:03:23

they return the same result type, but consume different parts of an iterator

hugesandwich21:03:41

so essentially they filter out results from an iterator

hugesandwich21:03:00

If it were up to me, I wouldn't do that at all, but it isn't my lib

jcromartie21:03:22

we already have functions in clojure.core that are like a partial application when called with a lower arity

jcromartie21:03:39

not sure if it’s anything like that

jcromartie21:03:45

no, I guess not

hugesandwich21:03:56

nope simple_smile, but looking to clojure.core is always where I start

jcromartie21:03:59

you said they all have the same return type but do different things with the iterator

hugesandwich21:03:06

yup, that's right

jcromartie21:03:34

can you think of a single function name that describes all three implementations accurately?

hugesandwich21:03:02

well a comment will suffice and keep it close to the original api if I just use a 3 arity definition on a protocol

jcromartie21:03:27

if you’re never going to call it with apply or anything like that I would just use differently-named functions

hugesandwich21:03:52

also this may be getting called a few thousand/100k times a second

hugesandwich21:03:18

so I would think using apply would just slow you down considering this is for high performance

hugesandwich21:03:35

also the dispatch for 3-arity is a bit more efficient considering they each call a distinct java overload

hugesandwich21:03:49

just a bit of duplicated conversions in 2 of the arities I think

hugesandwich21:03:07

but 1 extra line of code shared between the 2, no big deal and probably the way to go for performance

ghadi21:03:54

the body probably dominates the invocation. don't forget to measure

hugesandwich21:03:48

on that subject, is there a significant overhead instantiating a collection of records vs maps, assuming the record is just a container, and probably the result set is immediately going to have 1-3 lookups on top-level keys?

hugesandwich21:03:27

assuming you'd be getting back say, anywhere between as little as a few, and as much as a few thousand per collection

lvh21:03:36

Are toplevel do blocks special to the Clojure compiler? It seems to confuse cloverage, and I could see how the compiler just elides them...

hugesandwich21:03:11

I would expect a more compact memory footprint for the records, but maybe other penalties I haven't thought about

ghadi21:03:47

hugesandwich: you should measure if you really care. Small maps are the most efficient because of PersistentArrayMap

ghadi21:03:00

it's just a flat array

hugesandwich21:03:15

@ghadi Yeah, planned to for sure, I always try to measure, but thought I'd ask if it's stupid to even waste the time

ghadi21:03:40

maps are really complicated unfortunately, so many factors

hugesandwich21:03:48

kind of hard to know because it depends heavily on the data volume of api users

ghadi21:03:54

size of maps, lookup patterns, etc.

hugesandwich21:03:04

and I can mess with batch sizes to further complicate things

hiredman21:03:30

lvh: they are, the compiler treats each expression in a top level do as a top level form

lvh21:03:49

well, that gives me somewhat of a hint why cloverage balks

lvh21:03:17

That doesn’t really explain why cloverage is ok with (do 1)

lvh21:03:20

(maybe it isn’t?)

chancerussell21:03:18

I think I’ve asked this before, but can anyone remind me why (#()) evals to ()?

hiredman21:03:38

is cloveraged used a lot?

mtkp21:03:47

@chancerussell: (macroexpand '#()) -> (fn* [] ())

mtkp21:03:52

and (type ()) -> clojure.lang.PersistentList$EmptyList

mtkp21:03:34

looks like clojure doesn't eval the form if its empty

chancerussell21:03:45

That would explain it simple_smile Thanks @mtkp

jasonjckn22:03:27

is it bad programming to have a lazyseq perform side effects to construct itself as it's read?

jasonjckn22:03:05

i'm scanning rows on a remote db

ghadi22:03:17

java.jdbc does exactly that

ghadi22:03:36

but you have to do it in the context of an open ResultSet

jasonjckn22:03:36

well I was going to write code using clojure's lazyseq macro that does net IO

jasonjckn22:03:16

maybe lazyseq / ISeq isn't expressive enough as ResultSet for this sort of thing

hiredman22:03:46

have I got a dated write up you

jasonjckn22:03:36

hiredman: sorry just scanned the text, that looks ok if i want to materialize the whole result set in memory, or aggregate the whole result set, but there's no reduction in my work, I'm doing db in -> map -> db out

jasonjckn22:03:11

i want to transfer contents between databases in small batches

jasonjckn22:03:16

need logic for retries, or missing records

jasonjckn22:03:30

so i'll just write stupid for loop i guess simple_smile

hiredman22:03:52

you should read it more carefully then, it is entirely about reducible collections being a better way to represent resources as collections that you don't want to be entirely in memory at once

jasonjckn22:03:13

k, taking a second look

hiredman22:03:15

db out -> map -> db out is reduce

(reduce  (fn [db row] (insert db (f row)))  db (query db)) 

hiredman22:03:50

the write up is dated, because 1.8 and 1.7 brought new useful reduce and transduce stuff, which you could use to improve in various ways what is in the write up, but what is in the write still works great, and is an improvement over representing resources as seqs

jasonjckn22:03:20

sweet, hmh, yah this is making more sense

jasonjckn22:03:28

half way through the article

jasonjckn22:03:37

hiredman: nice yah i'm going to start implementing this, i guess i lucked out you had a write-up to my exact question 😉

jasonjckn23:03:36

the only thing the abstraction doesn't necessarily handle gracefully, is the lifecycle of the db out

jasonjckn23:03:52

if i'm reducing db in, I can have coll-reduce easily manage the lifecycle of the db connection

hiredman23:03:01

you might want to look at the new clojure.lang.IReduce and IReduceInit interfaces (I think added in 1.8) instead of implementing the CollReduce protocol

jasonjckn23:03:01

for db out, i'll just reopen the connection each time, no big deal

jasonjckn23:03:38

will check that out

hiredman23:03:06

transduce lets you provide a reducing function with 3 arities, with which you can do something like

(fn ([] (open-db-connection)) ([conn] (close-db-connection conn)) ([conn value] ...))

hiredman23:03:28

but that isn't the same as a close in a finally, so it can be tricky

jasonjckn23:03:55

hmhm ok, i'll check that out too

jasonjckn23:03:41

hiredman: "When to use Use the reducer form of these operations when: Source data can be generated and held in memory Work to be performed is computation (not I/O or blocking) Number of data items or work to be done is "large""

hiredman23:03:14

that is nonsense

hiredman23:03:44

that reads like the kind of restrictions you would put on the reducers concept of "fold" because of the way it does parallel computation

hiredman23:03:03

if you look at http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html (linked from the write up) under the heading "More Opportunity (i.e. Work)" rhickey explicitly called it out as a mechanism for solving "the lazily dangling open resource problem"