Fork me on GitHub
#clojure
<
2017-03-28
>
petterik00:03:46

(cond-> x (p x) f) ?

nathanmarz00:03:51

@alex.ter.weele that's one use case for if-path: (transform (if-path p STAY) f x)

nathanmarz00:03:50

@alex.ter.weele actually you can just do it like this: (transform p f x)

alex.ter.weele00:03:41

Perfect! I wasn’t attached to the argument order

bcbradley00:03:24

when is it appropriate to put ! on the end of a clojure function name?

bcbradley00:03:05

i get that it is usually used to represent that a function is doing something stateful

bcbradley00:03:04

is it used to indicate lack of purity?

bcbradley00:03:13

or is it less strict?

tbaldridge00:03:03

it's less strict, notice that volatile! is pure, yet has a !. Mostly to point out "you really shouldn't be using this unless you know what you're doing"

bcbradley00:03:49

do you think it would be a feature or a drawback to append ! on the end of all my gl/foos

tbaldridge00:03:05

and println is side-effecting and doesn't have one

tbaldridge00:03:39

drawback, not only does it break GL naming conventions, it's extra typing for no use

bcbradley00:03:47

yeah i think i agree

tbaldridge00:03:48

if you're using GL you know it's a mutating state machine.

bcbradley00:03:43

i did break a few gl naming conventions anyway though, but yeah it seems like extra typing (the reason I went to all this trouble in the first place was to get rid of the extraneous extra typing in lwjgl)

bcbradley00:03:35

also, its was annoying to have to wrap lwjgl calls in a clojure fn if i wanted to use it in things like (map...

bradford01:03:51

Does clojure.spec have a way to coerce a string like 2017-03-28 01:10:22 to a unix dt, or is that not really the purpose of spec?

seancorfield01:03:44

Not the purpose of it, I’d say. Use a date/time library for the coercion.

seancorfield01:03:20

There’s date-clj, clj-time, and Java 8’s built-in Time stuff… and probably other options.

bradford02:03:34

What's the best practice for doing stream aggregation? Like, a few hundred events a second, to a data set of probably no more than 64 gigabytes. Like "How many event_types for this user_id". Just a hashmap and the G1 garbage collector? Or is there something more 'efficient'?

bradford02:03:36

(reading a Kinesis shard into core.async channels)

tbaldridge02:03:14

a few hundred events a second? I probably wouldn't even bother tweaking the GC. It's always good to tweak a GC but I don't normally look to stuff like that until I have to handle 10-20k events a sec

bradford02:03:51

Cool, good point.

qqq03:03:14

someone pointed me to a link showing that http://neanderthal.uncomplicate.org/ was just aout to release 0.9.0

qqq03:03:21

I can't find that link; can anyone point me to the right link?

curlyfry05:03:45

Got it from The REPL (https://therepl.net/). Highly recommend subscribing to it!

qqq05:03:59

@curly_braces : nice, thanks! look slike there's no release date, so I'll stick with 0.8 for now 🙂

qqq05:03:21

err, @curlyfry ; slack autocomplete not working fo rme

qqq05:03:26

redis is a scriptable in lua; is there something like redis, but scriptable in cljs/clj? I'm not looking for a clj api to redis (I know about carmine); I'm lookin for things where I can write redis functions in clj/cljs

yonatanel08:03:25

Any recent experience reports or comparisons of Aleph, Immutant, Catacumba, http-kit etc? These are old: https://github.com/ptaoussanis/clojure-web-server-benchmarks

schmee08:03:43

I used Aleph last week and it was pretty fast 😬

mpenet08:03:31

any of these is not likely to be your bottleneck anyway

mpenet08:03:50

I personally just have reservation about http-kit stability under load

mpenet08:03:12

but that's quite an old experience, might not still be true

yonatanel08:03:32

Actually I care more about programming against these and not about the performance.

mpenet08:03:00

I'd say just use ring-jetty-adapter (the default in ring)

yonatanel08:03:29

Error handling, simplicity, maintenance, general trust in the lib etc.

boyanb08:03:35

In my opinion (shared by colleagues), the aleph + manifold experience is superior to the rest, but at the same time the learning curve is slightly steeper.

yonatanel08:03:27

I already use manifold and in jetty I usually block on a deferred before responding.

mpenet08:03:33

aleph is quite nice indeed

boyanb08:03:43

If you are familiar with manifold, just jump in with Aleph.

boyanb08:03:57

You can afford to see if it feels natural to you.

schmee08:03:08

what kind of server are you writing?

yonatanel08:03:58

Currently just a bunch of services.

yonatanel08:03:39

Usually ztellman makes the state of his running code visible. I wonder if aleph or the others provide this visibility.

mping08:03:51

is there an array-map in clj that supports duplicates?

mping08:03:50

I’d like {:a 1 :a 2 : b 3}

mpenet08:03:03

well, use a list?

mpenet08:03:23

or regroup value in single keys

mpenet08:03:42

seems like a modeling issue more than anything

mping08:03:54

its for a code challenge, so no big modelling issues here

mping08:03:55

well I guess I can use lists

blueberry09:03:40

@qqq Neanderthal 0.9.0 release date is not fixed, but it is a matter of a few days. Probably Wednesday.

jimmy09:03:31

hi guys, I love the idea that test file stay in the same directory with source file ( just like in golang and google closure ). I find the lib eftest can help me archiving that, but my concern is does the test code being compiled as well in uberjar ?

chrisetheridge10:03:36

if i have a function that has args as [& args], is it possible to pass it a vector of args, somehow? cause if i pass it [ 1 2 3 ] or similar, it won’t destruct them correctly, and treat it as 1 element in the args vector

chrisetheridge10:03:53

what would i apply? the incoming args or the args i’m giving it (`[ 1 2 3 ]`)

chrisetheridge10:03:39

apply the function to [1 2 3] 🙂 silly me

cycle33711:03:37

can you help me out a bit ?

cycle33711:03:45

I'm trying to learn about transducers

cycle33711:03:51

I have two sets named

owners 
( {:name "john" :pet "cat"} 
  {:name "mary" :pet "elephant"} )
and
pets 
( {:pet "cat" :color "grey"} 
{:pet "cat" :color "brown"} 
{:pet "cat" :color "yellowish"} 
{:pet "elephant" :color "green"} )

cycle33711:03:59

what can I use to have a set that results as

({:name "john" :pet "cat" :color {"grey" "brown" "yellowish"}})

cycle33711:03:49

I've tried using clojure.set/join

cycle33711:03:08

but that just repeats :name and :pet

cycle33711:03:30

(set/join owners pets)
#{{:name "john", :pet "cat", :color "brown"} {:name "john", :pet "cat", :color "grey"} {:name "john", :pet "cat", :color "yellowish"} {:name "mary", :pet "elephant", :color "green"}}

jstew11:03:35

First problem I see it that those are not sets, they are seq of hash-map. The clojure.set operations will only work on sets.

borkdude11:03:54

For building a production ready and secure API service that also supports async: DIY ring middlewares, Pedestal, Yada?

jstew12:03:25

Ah, I see what you're trying to do. Never mind my red herring.

cycle33712:03:18

@jstew thanks, I think I need a reducer of some sorts, maybe using distinct

cycle33712:03:50

i have no idea how though

jstew12:03:03

yeah, it's a tough one to think out on the fly, I have it in my head that you'll have to reduce the set of maps into a set of maps where name and pet are equal, but color is not, then conj the colors into a new set, and assoc. After performing that join.

cycle33712:03:08

so it's not as forthcoming as I thought

jstew12:03:10

There may be a simpler algorithm, quite often I'll ask here and someone will blow me away with a one liner.

mccraigmccraig12:03:45

@borkdude not tried pedestal, but yada is great

lmergen12:03:19

@borkdude yada, obviously! 🙂

borkdude12:03:14

Thanks 🙂

lmergen12:03:23

@borkdude to get started (the "easy" way), take a look at https://github.com/juxt/edge -- juxt's yada template repo

mccraigmccraig13:03:45

it's #yada vs #pedestal 🍿

snorremd13:03:52

I'm quite pleased with #yada. I have yet to try #pedestal though so I can't say which would be better.

john14:03:11

@thegeez is the source code for crepl out there? I couldn't find it.

gklijs14:03:24

When he presented it in the clojure meet-up it was ‘closed source’ but maybe it’s changed in the mean time.

novel14:03:15

ups, there is a spurious 1 in the fn “unpack-singleton”

timgilbert14:03:19

@avabinary: I think what you're looking for is using (group-by), maybe in a reduce, though I don't have a complete solution in my head

novel14:03:23

true, the ‘group-by’ solution might be easier than my ‘partition-by’ solution:

ghaskins14:03:20

hello all: is there an idiomatic way to express (if foo foo bar) ?

ghaskins14:03:31

i seem to recall there was, but now I cant find it

mtkp14:03:17

(or foo bar)

derwolfe14:03:54

when profiling things that involve looking into threads/gc/etc is visualvm the goto tool?

noisesmith15:03:12

yourkit is good too, for a paid tool

scknkkrer15:03:08

But I want to access district file destination.

ejelome15:03:44

quick question, is autolinting possible in clojure? (esp. when autotesting with repl) or we'll just have to do lein eastwood before committing?

ejelome15:03:36

I kind of enjoy this repl autotesting, but it would be more fun if it can also do autolinting 😄

brenden15:03:54

I'm looking to def a spec from inside a macro, could anyone tell me why something like

`(s/def ::person (s/keys :req-un ~fields))
would work but
`(s/def ~(keyword (str ":" (name keyword-name))) (s/keys :req-un ~fields))

brenden15:03:58

would not?

bronsa16:03:05

that's not how you make qualified keywords

brenden16:03:08

my error is

CompilerException java.lang.AssertionError: Assert failed: k must be namespaced keyword or resolvable symbol
(c/and (ident? k) (namespace k)), compiling:(form-init4421259825164979801.clj:78:23) 

bronsa16:03:19

you're creating a keyword that has ":foo" as name

bronsa16:03:38

(assming keyword-name is foo, that is)

bronsa16:03:51

:: is purely reader syntax

octopuscabbage16:03:59

do keywords created in java not get interned when the java library is imported?

brenden16:03:17

ok, i see, there is a fn for creating qualified keywords

bronsa16:03:48

you want something like ~(keyword (name (ns-name *ns*)) (name keyword-name))

brenden16:03:05

awesome, thank you

bronsa16:03:16

yeah keyword takes [name] or [namespace name]

thegeez16:03:58

@john no, at this time crepl is not open source

noisesmith16:03:08

@scknkkrer you can access files using http://clojure.java.io/file, you can access all the resources that the uberjar task put into your jar (including, by default, things under your resources/ directory and your source files) with http://clojure.java.io/resource

bcbradley17:03:35

is there a way to efficiently dispatch a function in clojure based on the type of the argument?

bcbradley17:03:17

i figured maybe something with multimethods but i don't know exactly what

mpenet17:03:20

protocols if it's on 1 arg

bcbradley17:03:33

i'll give it a look thanks!

jr17:03:32

(defmulti foo type)

jr17:03:55

(defmethod foo java.lang.String [s] (println s))

noisesmith17:03:04

that works if you take exactly one argument

noisesmith17:03:37

(not that it’s hard to adapt for different argument counts of course)

noisesmith17:03:07

also, depending on what “efficient” means here, you might want a protocol with exactly one method on it rather than a multimethod

lvh17:03:12

If I’m doing lein uberjar and there’s a resource (txt file) in the resulting jar; how can I figure out where it came from?

gonewest81817:03:51

in project.clj,

:resource-paths
should tell you where the file came from

noisesmith17:03:54

lvh hmm - the printed representation of a resource shows the path inside the jar

noisesmith17:03:23

gonewest818 but in an uberjar, you can’t get the project.clj directly and some of your resources didn’t come from that path

noisesmith17:03:43

@lvh

=> ( "clojure/core.clj")
#object[java.net.URL 0x532a3732 "jar:file:/Users/justin/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar!/clojure/core.clj”]

noisesmith17:03:52

so that’s promising - I bet there’s a method to get that path that it prints

noisesmith17:03:53

@lvh

=> (.getPath ( "clojure/core.clj"))
"file:/Users/justin/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar!/clojure/core.clj”

noisesmith17:03:19

but you need to check if resource returned nil before calling getPath on the value it returns

noisesmith17:03:56

perhaps (some-> resource-string io/resource .getPath) - returns nil if the resource wasn’t found instead of blowing up

gonewest81817:03:56

@noisesmith my bad. I thought the question was “I have a random file in my uberjar, how did it get there?” not “I have a resource but I need to know which thing in my classpath it is."

noisesmith17:03:42

now that you say that, maybe I misunderstood, heh

noisesmith17:03:20

but if you use my method in a project repl, asking for that file path, it will show you which jar it was in before it got to your uberjar 😄

lvh17:03:48

gonewest understood my question correctly 🙂

noisesmith17:03:04

haha - my answer still might help you though

noisesmith17:03:30

if you give your repl the relative path it ends up in in the uberjar, it should show you the m2 jar it came from

hiredman17:03:12

somewhere, I had a one liner for this

lvh17:03:22

@noisesmith It did actually help though

lvh17:03:48

(Apache httpclient pulling in "mozilla/public-suffix-list.txt")

hiredman17:03:45

for i in `find $HOME/.m2 -name \*.jar`; do; jar -tf "$i" | grep -q Mutex && echo $i ; done
replace Mutex with whatever you are looking for

lvh17:03:38

Yep; I did something similar too, but unfortunately it’s a popular file 😄

hiredman18:03:10

I was looking at artifacts built by some openid project a while ago, and their jars contained a huge overlap of classes (same name) that had different shas in different jars

bcbradley18:03:11

when you use reify to override the methods of an Object, can you override the static methods too?

bcbradley18:03:48

i mean i know you can say instance.foo() in java, but its preferred to say Class.foo() if foo is a static method

bcbradley18:03:57

does that mean you can reify over it?

noisesmith18:03:08

I don’t think you can create static methods in reify

noisesmith18:03:51

and in clojure the syntax is more explicit, to call static methods needs to be done on the class and doesn’t work on the object iirc

bradford20:03:54

Does IntelliJ/Cursive look good at 4K? Considering a monitor upgrade, and I spend my life in IntelliJ 😛

tbaldridge20:03:35

I use it on a MBP Retina and it looks great. There were InteliJ scaling issues way back in 2015, but I haven't seen those problems in years.

tbaldridge20:03:03

(not 4K, but it's higher rez than 1080p)

scknkkrer20:03:47

Guys, Isn’t there the utf8mb4 unicode support on jdbc driver for clojure ?

scknkkrer20:03:18

not only utf8, it’s utf8mb4 guys, it’s really a big problem if it isn’t there....

noisesmith20:03:09

scknkkrer surely that would be per db and not a jdbc wide thing?

noisesmith20:03:20

for example postgres handles 4 bytes with the utf8 encoding

scknkkrer21:03:52

Mysql support utf8mb4 ?

liamd21:03:15

can someone give me a quick example of destructuring the params in a post request with compojure?

liamd21:03:30

(POST "/mixtape" [{{:keys [mx-name blurb urls]} :params}]
    (create-mixtape mx-name blurb urls))
this isn’t quite right?

noisesmith21:03:11

do you have the middleware that keywordizes the keys from the post body and puts it under the :params key? if so that should be just fine

liamd21:03:58

yup that’s the piece i was missing, got it. thanks!

octopuscabbage21:03:22

yr making a mixtape api hell yeah

liamd21:03:09

yeah im thinking like ripping audio from youtube vids and making a pastebin sort of thing for mixtapes

liamd21:03:40

i’ll probably get my pants sued off but ¯\(ツ)

octopuscabbage21:03:04

were you really using your pants for anything?

qqq21:03:09

Does anyone here have OpenCL working with Clojure? 1. I am on Ubuntun 16.10 2. I have the nvidia-opencl-dev installed 3. I, from C, compile a sample OpenCL program and it runs fine. 4. When I try to use OpenCL from Clojure, I get "CL_INVALID_PLATFORM" Any info should be appreciated; feel free to directly message me.

liamd21:03:38

i was thinking about http://mikstap.es but now that i compared it to pastebin, mixbin sounds nice

octopuscabbage21:03:34

i’m trying to get the models to load for https://github.com/dakrone/clojure-opennlp it uses (input-stream ) internally. I want to have the models in my resources folder, how do i load the models from the resources folder. I tried (make-tokenizer “en-token.bin”) and (make-tokenizer (io/resource “en-token.bin”) i’m building with clojuresque in gradle

octopuscabbage21:03:45

any ideas on things to try?

liamd21:03:30

slurp it?

liamd21:03:27

i need to run background download/media processing jobs for this app. my first instinct is to reach for rabbitmq and have worker processes. that seem reasonable or am i overcomplicating this?

octopuscabbage21:03:27

it appears making a lazy laoder by hiding it behind a funciton call worked

tanzoniteblack21:03:16

you know, for future edification 🙂

octopuscabbage21:03:27

(def tokenizer-resource (io/resource "en-token.bin"))
;(def pos-tag (make-pos-tagger (io/resource "en-pos-maxent.bin")))
(defn get-tokenize [] (make-tokenizer tokenizer-resource))

(defn tokenize [s]
  ((get-tokenize) s))

octopuscabbage21:03:46

i would bet gradle hadn’t copied the resources at compile time

tanzoniteblack21:03:56

that or it only started working because you restarted your repl. io/resource can be finicky about the resource needing to exist when lein was started

octopuscabbage21:03:04

i’m not using leiningen

octopuscabbage21:03:38

corporate ecosystem ¯\(ツ)

tom21:03:41

If anyone uses compojure-api, has anyone seen an issue where a simple GET /thing/:thing-id route refuses to respond when using swagger ui (request turns red and says it stalled after 2ms)--but responds fine with curl?

liamd22:03:42

(defn process-youtube-urls
  "This will take a list of youtube urls as strings, then download their audio,
   concatenate the files and upload the new file to S3, then update the database
   with a link to that file"
  [urls]
  (println (map urls #(sh "youtube-dl" % "-x -f 140"))))

(defn create-mixtape [mx-name blurb urls]
 (let [uuid (str (java.util.UUID/randomUUID))]
  (future (process-youtube-urls urls))
  (mc/insert-and-return db "mixtapes" {:_id uuid :upload-status "pending" :mx-name mx-name :blurb blurb :urls urls})))
am i using future correctly here? nothing appears to be happening

ddellacosta22:03:32

@liamd I’m wondering if you are actually evaluating that map, guessing it may simply be returning a lazyseq and doing nothing.

liamd22:03:46

ah good point

liamd22:03:49

how do i make it go

ddellacosta22:03:50

hmm, although maybe the println forces evaluation?

liamd22:03:54

i would think so

pesterhazy22:03:00

println does force evaluation

ddellacosta22:03:07

the other thing is, those URLs aren’t going anywhere regardless

pesterhazy22:03:11

but you're not catching exceptions

ddellacosta22:03:35

you need to return those into…something if you want them. As it is you’re just going through them all and doing nothing with them, other than printing them out, in some thread somewhere

ddellacosta22:03:58

well, and looks like you’re calling map with the args in reverse order

liamd22:03:12

haha so it does

liamd22:03:36

shouldn’t i see an exception though?

pesterhazy22:03:56

no because you're not dereffing the future

liamd22:03:23

so does the future not execute until i deref?

liamd22:03:34

i just want it to go off on a thread and do a thing and i don’t really care about the result

liamd22:03:44

im just gonna have it update my database

liamd22:03:38

ah here we go switching the args gave me

({:exit 2, :out , :err Usage: youtube-dl [OPTIONS] URL [URL...]

youtube-dl: error: no such option: -
})

pesterhazy22:03:24

it does execute, but it swallows exceptions

pesterhazy22:03:51

I use this code for a "safe" way to execute a task in the background: https://gist.github.com/pesterhazy/c805676657dbe997dfed9e8792e66d23

liamd22:03:55

maybe i think i’m just not using sh correctly now

liamd22:03:45

youtube-dl '' -x -f 140 is what i want to execute

pesterhazy22:03:59

every process argument needs to be a separate fn argument

pesterhazy22:03:37

I think sh doesn't invoke /bin/sh but uses execvp directly

liamd22:03:31

#(sh "youtube-dl" % "-x" "-f 140”) did the trick, good shout

pesterhazy22:03:46

the last argument also shouldn't work 🙂

liamd22:03:55

hmmm but what if it does...

pesterhazy22:03:12

I mean "-f 140"

pesterhazy22:03:27

that's probably just ignored by youtube-dl

pesterhazy22:03:48

by the way, people should be aware of the shortcomings of clojure.core/future

pesterhazy22:03:04

everyone runs into this issue sooner or later

liamd22:03:14

yeah to get the args right i had to “-f” “140"

noisesmith22:03:27

pesterhazy that code handles exceptions, but swallows errors

Al Baker23:03:58

does ring or selmer add servlet context path anywhere convenient so you can properly prefix your URLs in views and the like?

noisesmith23:03:03

@albaker I seem to recall useful data being present in the request map (though it can vary somewhat based on which adaptor you use)

Al Baker23:03:26

cool, I'll poke around w/ that

alex-glv23:03:29

Hey, clojurians! I am looking for “drop-in” middleware for transit between clj and cljs apps. Any suggestions? Thanks!

schmee07:03:33

https://github.com/ngrunwald/ring-middleware-format has support for Transit, JSON, Msgpack and some other stuff

alex-glv09:03:32

Thanks, that did it!

liamd23:03:50

are there any ways to interop with C libs from clojure?

xiongtx23:03:54

@lvh obviously can provide more info

lvh00:03:32

I’m sure that wrapper is fine but I would generally recommend against JNA except in very specific cases

lvh00:03:37

unless you know you want JNA, you want JNR