Fork me on GitHub
#clojure
<
2017-07-20
>
tjscollins00:07:29

But it does crop up again eventually as I'm reloading different files. I'll see if I can narrow it down.

hiredman00:07:01

you are reloading the file where the protocols without reloading the file where the record defined, or you are reloading the file where the protocols are defined and trying to call the new (because of the reload) protocol on a instance of the record type that had the old protocol extended to it

tjscollins00:07:49

But I don't understand why that's happening. The only file I ever require directly from cljs-ajax is ajax.core, as far as I know.

hiredman00:07:47

sure, but how are you requiring it and what tooling stuff are you using?

hiredman00:07:46

and core is importing the record class directly instead of using the constructor fns

hiredman00:07:05

I would just not use cljs-ajax

pandeiro00:07:26

Can't imagine cljs-ajax would work in JVM-hosted clojure

pandeiro00:07:50

"ajax" is a term only used in frontend programming afaik

bfabry00:07:31

and yet, that file imports quite a lot of java classes and ends in .clj 🙂

pandeiro00:07:51

Yeah looks like indeed the intent is there... interesting

tjscollins01:07:51

The docs for cljs-ajax really make it sound like it should work in both, and it almost did, except for this reloading issue. At any rate, I switched to using clj-http on the server and it's all working now. It just means I can't share the code between the client and server the way I wanted.

carocad07:07:15

does anybody uses eastwood together with clojure.spec. It is becomming really annoying that eastwood complains about the spec macros even though I cannot do anything about it. Or can I?

carocad08:07:32

@kurt-o-sys no, from what I understand it is about the macro expansion of the specs:

src/service/routing/spec.clj:40:17: suspicious-expression: and called with 1 args.  (and x) always returns x.  Perhaps there are misplaced parentheses?

src/service/routing/spec.clj:44:22: suspicious-expression: and called with 1 args.  (and x) always returns x.  Perhaps there are misplaced parentheses?

src/service/routing/spec.clj:38:20: constant-test: Test expression is always logical true or always logical false: 2 in form (if or__5058__auto__ or__5058__auto__ (clojure.core/or 0))

src/service/routing/spec.clj:38:20: constant-test: Test expression is always logical true or always logical false: nil in form (if nil (clojure.core/inc nil) 2)

src/service/routing/spec.clj:38:20: constant-test: Test expression is always logical true or always logical false: nil in form (if or__5058__auto__ or__5058__auto__ (clojure.core/or 

kurt-o-sys08:07:19

Well, I guess eastwood is not clojure.spec compliant yet. You may add an issue to https://github.com/jonase/eastwood/issues ?

carocad08:07:17

jumm I was hoping to be wrong. The question is rather is eastwood at fault or clojure.spec? because those expanded expressions do look suspicious

yonatanel10:07:04

Is clojure.core/hash always non-negative?

bronsa10:07:33

it uses the full int range

scaturr11:07:18

this might be a dumb question - it likely is - but what is the best way to define a spec in clojure.spec for an argument that is a function of arity 1?

scaturr11:07:22

is that a thing?

scaturr11:07:39

Something that could be used to spec a function like take! from core.async:

(defprotocol ReadPort
  (take! [port fn1-handler] "derefable val if taken, nil if take was enqueued"))

scaturr11:07:52

for fn1-handler

danielgrosse11:07:31

How could I combine two images?

yonatanel13:07:44

What's the pattern in Integrant/Component REPL development to pick up an edited configuration file on reset? Do you make it a component in the system? I'm building my system object according to the config so I can't do that.

jcf13:07:56

@yonatanel I tend to read the config file each time and merge the result into my system map. Using Aero to read the EDN file I then do something like this: (merge-with merge system config).

jcf13:07:07

With a component like this:

(defrecord Datomic [uri]
  component/Lifecycle
  ;; ...
  )
And a config file like this:
{:datomic {:uri "datomic:"}}

jcf13:07:35

And a system map like this:

(component/system-map :datomic (map->Datomic {}))

jcf13:07:05

Integrant does things slightly differently I believe?

jcf13:07:08

Looks like Integrant will reload your config from this: https://github.com/weavejester/integrant#configurations

yonatanel13:07:57

@jcf Integrant config is the equivalent to Component's system, so it won't just re-read my external config file.

jcf13:07:10

Yeah, from a quick look at the Integrant README, there is no explicit system map in Integrant.

yonatanel13:07:36

That's what I like about it, the system map is data.

jcf13:07:10

Component's system map is data too. 🙂

jcf13:07:47

If you've got a config somewhere as per the README, and reloading is done via clojure.tools.namespace, I'd expect changes to the file to show up.

(def config
  (ig/read-string (slurp "config.edn")))

jcf13:07:10

Can't say I've used Integrant before though. Sorry.

yonatanel13:07:38

You've given me a direction. Thanks

danielgrosse13:07:29

How can I add java dependencies to my clojure project?

bfabry13:07:40

@danielgrosse same way you add clojure dependencies. the project.clj dependencies list is just maven artifacts

weavejester13:07:07

@yonatanel you might want to look at Integrant-REPL

oskarkv14:07:47

Does anyone know of a fuzzy finder lib for Clojure? By fuzzy finding I mean that you can, for example, search for "msd" and it would match, and give a high score to, "my/secret/dir", because the letters appear at word boundaries.

Arun16:07:23

Hi @weavejester, I was wondering if i could ask you a #duct related question?

oskarkv17:07:45

@kurt-o-sys Does that do what I want? All the examples look weird, e.g. (dice "healed" "sealed") => 0.8

kurt-o-sys17:07:30

@oskarkv oh, I must have misunderstood you. But it looks pretty easy to make it work as you expect: extract the letters at word boundaries and match it against one of the fuzzy string algorithms

kurt-o-sys17:07:02

so, the only thing to do for you would be: convert my/secret/dir to msd, right?

oskarkv17:07:09

@kurt-o-sys I want some more features, like "msod" would not match "my/secret/dir" but it would match "my/awesome/dir"

oskarkv17:07:41

But I have now written it myself. 😛

kurt-o-sys17:07:54

oh... that's different, right 🙂

kurt-o-sys17:07:18

So, you've written it in less than 3 hours, right? Nice 🙂

bfabry17:07:08

I wonder if you could rip off elisp from one of the emacs helpers that does that and convert it

oskarkv17:07:34

Ops, that last one should not have a score of 3 😛 I added it manually and did it wrong. 😛

oskarkv17:07:35

I accidentally put s and d next to each other in the string.

kurt-o-sys17:07:29

got it. 👍

mac0102117:07:23

Anyone have a pointer to a small-to-medium-size, open source codebase that uses clojure.spec in the ways that it is typically used?

kurt-o-sys17:07:11

I expect to have one next week 🙂. Well, it still needs some work, but the current state is: https://gitlab.com/kurtosys/lib/factoidic/

kurt-o-sys17:07:53

https://gitlab.com/kurtosys/lib/factoidic/blob/master/factoidic/src/clj/factoidic/config.clj - spec for config (will be lib boundary, that's why it's in a separate namespace; other specs might not be in a separate namespace).

kurt-o-sys17:07:05

I use it for: 1. lib boundary validation 2. generative testing 3. instrumentation during debugging

mac0102118:07:11

generative testing code is not in there yet, right?

kurt-o-sys18:07:51

right, that's one of the reasons why I keep it quiet and it's still in SNAPSHOT. I have to add more specs, testing and some benchmarking.

mac0102118:07:52

awesome. Thanks for the link

cjhowe17:07:01

is there a good clojure library for very simple GIS/map data visualization? or am I better off using something like Om with clojurescript?

wiseman18:07:57

may not fit your requirements, but https://github.com/wiseman/leaflet-gorilla could be relevant

Arun18:07:08

Okay @weavejester, right now i'm trying to integrate buddy's authentication middleware with ataraxy and duct, and looking at the ataraxy module docs, it says that for finer control i should use duct.router/ataraxy instead of duct.module/ataraxy. I was wondering if there was a way to add other middleware using the module instead of router?

weavejester19:07:13

@arundilipan you can use both. Use the module to create the routes, then add the middleware to the router key.

Arun19:07:31

@weavejester, oh what would that look like? Would duct.module/ataraxy and duct.router be keys in the edn file?

bradford19:07:35

Hi, how do I write a response directly in http-kit? I'm building a tunneling proxy and need the very first response to be exactly "HTTP/1.1 200 Connection established\r\n\r\n", but it seems http-kit renders that as a body, even if I do something like {:status "HTTP/1.1 200 Connection established"}

noisesmith19:07:47

sounds like what you want is to supply a :headers map? but I thought :status would automatically be lifted into the headers

bradford19:07:58

@noisesmith Oddly, it's not a header, it's a status-line in the HTTP spec

bradford19:07:38

status-line = HTTP-version SP status-code SP reason-phrase CRLF

noisesmith19:07:43

oh, OK - I don’t know how to override that via ring (assuming if you’re handing it a hash-map like that you’re using it via ring)

noisesmith19:07:20

sounds like you’d be better off using a TCP library rather than an http library if you want to specify that kind of thing by hand?

noisesmith19:07:25

I might be wrong

bradford19:07:55

Ya, I'm not sure it's possible with ring. I'd rather not have to use a TCP library, as I don't want to have to glue reqeusts and responses together. But you're right. I may just fork httpkit/ring and kludge something in there

noisesmith19:07:30

there’s also aleph which has an http server but also supports using tcp sockets in the same lib

noisesmith19:07:41

i’d hazard a guess it would be more flexible

trptcolin19:07:54

i’m surprised something is depending on that specific reason phrase and forcing you to not use “OK” 😿

mattly19:07:29

what an obtuse corner of the spec – you learn something every day

bradford19:07:59

Yup, oddly enough, Ring or every HTTP server hard-codes an [int string] pair

noisesmith19:07:12

@bradford also - thinking outside the box for a minute - it’s probably a good idea to reverse-proxy any jvm webserver behind nginx anyway, and I bet there’s a four line snippet to rewrite your status lines via nginx

mattly19:07:37

a quick web search reveals a lot of "why would you ever want to do that? lol" by library authors in general

bradford19:07:43

@noisesmith That's interesting. Hm...

chrisbroome19:07:55

looks like it could be for using http CONNECT requests?

noisesmith19:07:02

possible terrible kluges include “run server sockets through netcat / sed shell pipeline”

mattly19:07:09

I'm not saying anyone in clojure-land would ever give that response, just seeing it in general for searching "set status-line http" 😛

noisesmith19:07:11

(don’t actually do that)

weavejester19:07:03

@arundilipan Something like:

{:duct.module/ataraxy {"/" ^:foo [:index]}
 :duct.router/ataraxy {:middleware {:foo #ig/ref :foo.middleware/auth}}}

chrisbroome19:07:17

specifically: > Upon receiving such a request, the proxy is expected to establish a TCP/IP connection to the requested hostname and port and signal its success by returning a HTTP/200 response indicating that the requested connection was made:

HTTP/1.1 200 Connection Established
  Connection: close

weavejester19:07:37

Come to think of it, I think middleware of :foo assumes a key of :project.middleware/foo already.

Arun19:07:05

@weavejester so if i wanted to use a 3rd-party middleware i'd replace :foo.middleware/auth with <3rd party ns>.wrap-auth?

weavejester19:07:48

@arundilipan You’d need to create an init-key method for it. Say your project name is “foo”. What I tend to do is have a foo.middleware namespace where I dump all the init-keys for middleware.

weavejester19:07:48

(ns foo.middleware
  (:require [integrant.core :as ig]
            [buddy.middleware.auth :refer [wrap-auth]])

(defmethod ig/init-key ::auth [_ options]
  #(wrap-auth % options))

weavejester19:07:37

And then in my config:

{:duct.module/ataraxy {"/" [:index], "/private ^:auth [:private]}}

bradford19:07:43

Lol you have to set "Connection: close" but leave the socket open

Arun19:07:10

@weavejester ahh thanks, i'll give it a try!

bradford19:07:20

httpkit also forces you to add headers, tsk tsk.

if (!headers.containsKey("Server")) {
          headers.put("Server", "http-kit");
        }
        if (!headers.containsKey("Date")) {
          headers.put("Date", DateFormatter.getDate()); 
        }

bradford19:07:52

I guess the spec says you need these sometimes, and I'm a corner case anyway

hlolli20:07:14

I have a java.nio.HeapByteBuffer which I feed into this function

(defn- decode-UTF-8 [^ByteBuffer buf]
  (.toString (.decode StandardCharsets/UTF_8 buf)))
still I'm getting plenty of barbage, this is the return value before being applied the function decode-UTF-8
#object[java.nio.HeapByteBuffer 0x40b43b15 "java.nio.HeapByteBuffer[pos=0 lim=28 cap=32768]"]
and for the same object, after the application
/g_new,iii
Is there any possible way to trim this garbage away from the given information of pos, lim and cap?

hlolli20:07:10

there are two boxes (and invisible chars) that I don't want in my string.

hlolli20:07:02

mindblow, try it... 🙂

hlolli20:07:42

(defn- decode-UTF-8 [^ByteBuffer buf]
  (.toString (.decode StandardCharsets/UTF_8 (.slice buf))))
didnt do it, may be something more extreme here going on
#object[java.nio.HeapByteBuffer 0x1f6ad41a "java.nio.HeapByteBuffer[pos=0 lim=252 cap=32768]"]
/d_recv,b�SCgfovertone.studio.fx/fx-freeverb?�33???buswet-dry	room-size	dampeningControlInFreeVerb
      BinaryOpUGen��
ReplaceOut
some esetoric charset here in play, this is a buffer from clj-osc.

hlolli20:07:34

debugging charsets, I try all the combination until I get something working 🙂

gfredericks21:07:23

I love how clj-time.core/today's docstring says "LocalDate objects do not deal with timezones at all.", but it doesn't mention that the function is sensitive to the current timezone. I don't think programmers have a good vocabulary for discussing time[-zones]

avi21:07:57

My apologies if this is a FAQ, I did try searching here and in the Google Group… but I’m just curious, does anyone have a sense for when Clojure 1.9.0 might start making its way to beta and then final releases? I’m not stressed about it or anything, really I’m just curious. Thanks!

hlolli21:07:20

solved my shit above, someone from the past made osc message decoder that I could just use directly. This is what happens when I program without a beer.

weavejester21:07:22

@aviflax I get the impression sometime later this year. The hold-up is because 1.9 will include its own dependency management.

gfredericks21:07:44

dependency management?

weavejester21:07:20

@gfredericks There was a talk about it at EuroClojure a few hours ago. Because spec is now its own package, the idea is that Clojure needs to be able to download dependencies without requiring an additional build tool like Leiningen or Boot.

weavejester21:07:00

So Clojure will get a clj script that will use a deps.edn file to retrieve packages and construct a classpath. The classpath will be cached so that the shell script can use it directly the next time its called.

dpsutton21:07:46

huh. i wonder if stuart sierra was getting at this a bit in his recent article

weavejester21:07:01

It looks pretty nice.

dpsutton21:07:03

or was that in the comments about caching the jar deps

gfredericks21:07:30

so it's definitely user-facing then? the next question is how that composes with lein/boot

gfredericks21:07:26

and where do you get the script from

avi21:07:57

And thanks so much for all the excellent libraries and tools that you share with the community!

weavejester21:07:07

@gfredericks Script will be packaged up in brew, apt, etc. I believe it’s a script around a Java jar for performance, IIRC.

weavejester21:07:52

Lein and Boot probably won’t be affected at first, since it’s a separate system

weavejester21:07:28

But I can see a build tool being made that’s effectively just a bunch of clj aliases.

gfredericks21:07:45

please tell me deps.edn uses the [org.clojure/clojure "0.9.0"] syntax at least

weavejester21:07:31

@gfredericks Nope, it’s more like: org.clojure/clojure {:source :mvn, :version "0.9.0"}

weavejester21:07:51

So it’s a map of symbols to maps.

weavejester21:07:13

But the idea is that it’s not necessarily limited to Maven

weavejester21:07:08

Yeah, or raw Github for example. Funny you should mention npm, since ClojureScript is getting the ability to use that directly.

gfredericks21:07:31

via deps.edn or something different?

weavejester21:07:51

Via a compiler option I believe

weavejester21:07:02

I imagine that it’ll converge with Clojure

weavejester21:07:25

Advantage is that npm packages can be pulled into Google Closure, so you don’t need externs

weavejester21:07:30

As well as being convenient.

gfredericks21:07:12

computers are complicated

avi21:07:13

:thinking_face: probably naïve, but when you first mentioned dependencies I thought of Rich Hickey’s talk last year (?) about maybe radically changing how we manage dependencies… IIRC to boil it down reductively, to track dependencies at the function level rather than the “library” level, and to never change the contract of any given function… pretty compelling stuff!

weavejester21:07:16

It doesn’t go that far, yet, since it’s just for classpaths and only supports Maven currently.

weavejester21:07:32

But I get the impression it could go that way in future.

avi21:07:35

yeah that makes sense

avi21:07:42

gotta start somewhere

weavejester21:07:02

And it has the advantage of not using Maven’s dependency resolution algorithm.

avi21:07:02

I don’t know the details of why that’s compelling, but moving away from Maven sounds positive to me

gfredericks21:07:48

so transitive deps are all entered manually?

weavejester21:07:56

@gfredericks No, it’l resolve transitive dependencies, but I believe it all has to be unambiguous otherwise it’ll complain.

weavejester21:07:21

Presumably if the Maven artifacts lead to conflicts it’ll require that you resolve the dep explicitly.

weavejester21:07:38

Rather than the Maven resolution of just going with the “closest” dependency.

weavejester21:07:32

Same thing I heard with the cljs npm deps. They want the deps to be unambiguous and not subject to change.

weavejester21:07:45

Which I can get behind.

nwjsmith21:07:28

So there is no support for specifying version "ranges" then

nwjsmith21:07:10

or is there a lock-file type thing? a la Bundler/Cargo/Yarn?

weavejester21:07:48

No support for specifying ranges, I’m pretty sure.

weavejester21:07:08

There’s support for overriding deps, though, IIRC.

weavejester21:07:37

And (eventually) for excluding transitive deps, but the syntax for that is pending a talk with Rich

weavejester21:07:12

Take what I’m saying with a grain of salt, until the EuroClojure videos comes out 🙂

weavejester21:07:34

Since I’m a secondary source, and it’s late

seancorfield21:07:01

That's Alex Miller's talk today?

seancorfield21:07:17

Looking forward to the video ... hopefully tomorrow? 🙂

weavejester21:07:52

Yep, Alex’s talk was on the clj script, deps.edn thing.

weavejester21:07:36

I’m kinda thinking about a build.edn now…

weavejester21:07:36

Or a tasks.edn, either in the project root, or included in the resources path.

seancorfield22:07:55

We use deps.edn for regular coordinates today and load them from various subprojects and concatenate them (and then update them from a list of "pinned" versions in a versions.properties file) as part of our dynamic Boot-based dependency analysis.

j-po23:07:47

Is there a way to do something like map fusion on lazy seqs? Does it even make sense to do that (given chunking, or for some other reason I haven't thought of)?

j-po23:07:05

Thanks! I'd been under the impression that transducers only made sense in an eager context, but further research suggests that belief may have been oversimplified 😜.