This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-28
Channels
- # beginners (8)
- # boot (49)
- # cljs-dev (29)
- # cljsrn (9)
- # clojure (238)
- # clojure-dev (3)
- # clojure-gamedev (1)
- # clojure-italy (7)
- # clojure-norway (11)
- # clojure-russia (39)
- # clojure-sanfrancisco (3)
- # clojure-spec (116)
- # clojure-sweden (2)
- # clojure-uk (53)
- # clojurescript (90)
- # cursive (13)
- # datomic (12)
- # defnpodcast (2)
- # dirac (1)
- # emacs (11)
- # figwheel (2)
- # hoplon (15)
- # jobs (3)
- # jobs-discuss (48)
- # keechma (1)
- # klipse (4)
- # leiningen (16)
- # luminus (4)
- # lumo (49)
- # mount (10)
- # off-topic (1)
- # om (13)
- # onyx (15)
- # pedestal (67)
- # perun (1)
- # planck (16)
- # powderkeg (33)
- # proton (1)
- # protorepl (2)
- # re-frame (16)
- # reagent (4)
- # ring (9)
- # ring-swagger (10)
- # rum (5)
- # slack-help (1)
- # spacemacs (1)
- # uncomplicate (15)
- # untangled (19)
- # yada (58)
@alex.ter.weele that's one use case for if-path
: (transform (if-path p STAY) f x)
@alex.ter.weele actually you can just do it like this: (transform p f x)
Perfect! I wasn’t attached to the argument order
i get that it is usually used to represent that a function is doing something stateful
@bcbradley: https://github.com/bbatsov/clojure-style-guide#changing-state-fns-with-exclamation-mark. However, I’m not sure everyone abides by that particular convention.
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"
do you think it would be a feature or a drawback to append ! on the end of all my gl/foos
and println
is side-effecting and doesn't have one
drawback, not only does it break GL naming conventions, it's extra typing for no use
if you're using GL you know it's a mutating state machine.
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)
also, its was annoying to have to wrap lwjgl calls in a clojure fn
if i wanted to use it in things like (map...
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?
Not the purpose of it, I’d say. Use a date/time library for the coercion.
There’s date-clj
, clj-time
, and Java 8’s built-in Time stuff… and probably other options.
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'?
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
someone pointed me to a link showing that http://neanderthal.uncomplicate.org/ was just aout to release 0.9.0
Got it from The REPL (https://therepl.net/). Highly recommend subscribing to it!
@curly_braces : nice, thanks! look slike there's no release date, so I'll stick with 0.8 for now 🙂
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
Any recent experience reports or comparisons of Aleph, Immutant, Catacumba, http-kit etc? These are old: https://github.com/ptaoussanis/clojure-web-server-benchmarks
Actually I care more about programming against these and not about the performance.
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.
I already use manifold and in jetty I usually block on a deferred before responding.
Usually ztellman makes the state of his running code visible. I wonder if aleph or the others provide this visibility.
@qqq Neanderthal 0.9.0 release date is not fixed, but it is a matter of a few days. Probably Wednesday.
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 ?
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
what would i apply
? the incoming args or the args i’m giving it (`[ 1 2 3 ]`)
oh ofcourse
apply the function to [1 2 3]
🙂 silly me
thank you!
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"} )
what can I use to have a set that results as
({:name "john" :pet "cat" :color {"grey" "brown" "yellowish"}})
(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"}}
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.
For building a production ready and secure API service that also supports async: DIY ring middlewares, Pedestal, Yada?
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.
There may be a simpler algorithm, quite often I'll ask here and someone will blow me away with a one liner.
@borkdude not tried pedestal, but yada is great
@borkdude to get started (the "easy" way), take a look at https://github.com/juxt/edge -- juxt's yada template repo
it's #yada vs #pedestal 🍿
I'm quite pleased with #yada. I have yet to try #pedestal though so I can't say which would be better.
When he presented it in the clojure meet-up it was ‘closed source’ but maybe it’s changed in the mean time.
@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
when profiling things that involve looking into threads/gc/etc is visualvm the goto tool?
yourkit is good too, for a paid tool
quick question, is autolinting possible in clojure? (esp. when autotesting with repl) or we'll just have to do lein eastwood before committing?
I kind of enjoy this repl autotesting, but it would be more fun if it can also do autolinting 😄
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))
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)
do keywords created in java not get interned when the java library is imported?
@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
@avabinary Try this
is there a way to efficiently dispatch a function in clojure based on the type of the argument?
that works if you take exactly one argument
(not that it’s hard to adapt for different argument counts of course)
also, depending on what “efficient” means here, you might want a protocol with exactly one method on it rather than a multimethod
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?
in project.clj,
:resource-paths
should tell you where the file came fromlvh hmm - the printed representation of a resource shows the path inside the jar
gonewest818 but in an uberjar, you can’t get the project.clj directly and some of your resources didn’t come from that path
=> ( "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”]
so that’s promising - I bet there’s a method to get that path that it prints
=> (.getPath ( "clojure/core.clj"))
"file:/Users/justin/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar!/clojure/core.clj”
but you need to check if resource returned nil before calling getPath on the value it returns
perhaps (some-> resource-string io/resource .getPath)
- returns nil if the resource wasn’t found instead of blowing up
@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."
now that you say that, maybe I misunderstood, heh
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 😄
haha - my answer still might help you though
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
@noisesmith It did actually help though
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 forI 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
when you use reify to override the methods of an Object, can you override the static methods too?
i mean i know you can say instance.foo()
in java, but its preferred to say Class.foo()
if foo is a static method
I don’t think you can create static methods in reify
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
Does IntelliJ/Cursive look good at 4K? Considering a monitor upgrade, and I spend my life in IntelliJ 😛
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.
(not 4K, but it's higher rez than 1080p)
scknkkrer surely that would be per db and not a jdbc wide thing?
for example postgres handles 4 bytes with the utf8 encoding
@scknkkrer https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-charsets.html
can someone give me a quick example of destructuring the params in a post request with compojure?
(POST "/mixtape" [{{:keys [mx-name blurb urls]} :params}]
(create-mixtape mx-name blurb urls))
this isn’t quite right?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
yr making a mixtape api hell yeah
yeah im thinking like ripping audio from youtube vids and making a pastebin sort of thing for mixtapes
were you really using your pants for anything?
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.
i was thinking about http://mikstap.es but now that i compared it to pastebin, mixbin sounds nice
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
any ideas on things to try?
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?
it appears making a lazy laoder by hiding it behind a funciton call worked
@octopuscabbage example code for that?
you know, for future edification 🙂
(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))
i would bet gradle hadn’t copied the resources at compile time
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
i’m not using leiningen
or a repl
corporate ecosystem ¯\(ツ)/¯
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
?
(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@liamd I’m wondering if you are actually evaluating that map
, guessing it may simply be returning a lazyseq and doing nothing.
hmm, although maybe the println forces evaluation?
println does force evaluation
the other thing is, those URLs aren’t going anywhere regardless
but you're not catching exceptions
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
well, and looks like you’re calling map with the args in reverse order
no because you're not dereffing the future
i just want it to go off on a thread and do a thing and i don’t really care about the result
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: -
})
it does execute, but it swallows exceptions
I use this code for a "safe" way to execute a task in the background: https://gist.github.com/pesterhazy/c805676657dbe997dfed9e8792e66d23
every process argument needs to be a separate fn argument
I think sh
doesn't invoke /bin/sh
but uses execvp
directly
the last argument also shouldn't work 🙂
I mean "-f 140"
that's probably just ignored by youtube-dl
by the way, people should be aware of the shortcomings of clojure.core/future
everyone runs into this issue sooner or later
pesterhazy that code handles exceptions, but swallows errors
does ring or selmer add servlet context path anywhere convenient so you can properly prefix your URLs in views and the like?
@albaker I seem to recall useful data being present in the request map (though it can vary somewhat based on which adaptor you use)
Hey, clojurians! I am looking for “drop-in” middleware for transit between clj and cljs apps. Any suggestions? Thanks!
https://github.com/ngrunwald/ring-middleware-format has support for Transit, JSON, Msgpack and some other stuff
there’s a good wrapper for jna https://github.com/Chouser/clojure-jna