Fork me on GitHub
#clojure
<
2016-06-23
>
flyboarder03:06:33

Hello everyone, I’m looking for feedback on a thing I did today, trying to get a basis for a real project: (Requires Clojure-clr dll in ‘clojure’ subfolder) Poshjure - Clojure in Powershell https://gist.github.com/flyboarder/40a7e25c89f6e5dcfb25da37be782037

mathias_dw08:06:57

Hi, not sure if this was discussed before, but I can’t find the answer: I’m using spec to validate the input data to a http json API, and I don’t want to ask the clients to use qualified keys. That’s easy enough with req-un at the top level, but I’d like to have the internal logic use the namespaced map. To be able to validate the external input, I need to use req-un throughout (which is not a nice solution, I would say), or somehow copy the spec (which is even worse). What I need is some kind of s/conform-un that takes a qualified spec and an unqualified map, tries to conform, and returns the qualified map if that worked. Does something like that exist?

jstaffans08:06:36

@mathias_dw: can you convert the unqualified map to a qualified one for use internally in your api?

mathias_dw08:06:22

yeah, I can do that “manually”, but I was looking for something that already does that generally

jstaffans08:06:13

I haven’t used spec, but when I get a JSON object like {“some_key”: “foo”}, I use https://github.com/qerub/camel-snake-kebab to convert it into {:some-key “foo”}

mathias_dw08:06:14

but you’re right, I didn’t mention that in the options above, and this is what I would do as well

jstaffans08:06:48

maybe you can write a little library to do something equivalent for spec

mathias_dw08:06:14

thanks, that’s a nice library I didn’t know about

mathias_dw08:06:55

yeah, it makes sense to create something like that for what I’m looking for, thanks! I’ll see what it would take and give it a stab if nothing similar exists

okal09:06:02

Is it possible to have actual carriage returns while pretty printing, instead of the ”\n” literal showing up? I’d like to print a map which has some string values containing newlines within them.

okal09:06:57

(pprint "\n”)
"\n”
nil
(print "\n”)

nil

okal09:06:26

I’ve seen the pprint-newline function, but it’s not really clear to me how to actually use it based on the documentation.

lvh13:06:23

I’m sure I’m missing the nice way to express this, but… Suppose I have xs [:a :b :c] and ys [0 1], how do I get [[:a 0 :b 0 :c 0] [:a 0 :b 0 :c 1] [:a 0 :b 1 :c 0], …]? i.e. I want every possible combination, so (count ys) raised to the power (count xs) things. I don’t necessarily know the values of xs and ys statically ahead of time, so the obvious for doesn’t work, and a macro doesn’t seem very appropriate here

weavejester13:06:34

Your welcome 🙂

lvh13:06:26

Somehow I didn’t think of the word “cartesian prodct"

lvh13:06:39

I knew what that meant, just didn’t think to express it that way; silly in hindsight

gabe13:06:36

selmer question

gabe13:06:38

anyone know if there’s a way to get a handle on the variable name while processing a template?

lvh13:06:14

weavejester: so, that still doesn’t quite get me what I wanted, because it gets me every (x, y) tuple, but what I wanted was a set of all of the possible tuples of length (count xs) where the associated y value takes every possible value; more like a counter up to (count ys) (count xs)

lvh13:06:34

if it helps to reason about it, the xs are argument names, the ys are byte types (byte array, ByteBuffer)

lvh13:06:41

I’m trying to bind every byte type to a C library

lvh13:06:21

(it’s possible that the right answer here is “don’t do that” but I’m still running the necessary experiments to figure that out)

lvh13:06:12

(and yes I’ve already made sure I don’t end up with 64k methods that way since that would break the JVM ;))

weavejester13:06:24

But… hm, isn’t that a case of applying the combinations twice over?

lvh13:06:46

eh, maybe

lvh13:06:47

lemme check

lvh13:06:19

I guess selections and not combinations because I want them to repeat

lvh13:06:45

caesium.binding> (c/selections bound-byte-types (count [:arg1 :arg2 :arg3]))
((#function[clojure.core/bytes] #function[clojure.core/bytes] #function[clojure.core/bytes])
 (#function[clojure.core/bytes] #function[clojure.core/bytes] java.nio.ByteBuffer)
 (#function[clojure.core/bytes] java.nio.ByteBuffer #function[clojure.core/bytes])
 (#function[clojure.core/bytes] java.nio.ByteBuffer java.nio.ByteBuffer)
 (java.nio.ByteBuffer #function[clojure.core/bytes] #function[clojure.core/bytes])
 (java.nio.ByteBuffer #function[clojure.core/bytes] java.nio.ByteBuffer)
 (java.nio.ByteBuffer java.nio.ByteBuffer #function[clojure.core/bytes])
 (java.nio.ByteBuffer java.nio.ByteBuffer java.nio.ByteBuffer))

lvh13:06:48

That looks promising 🙂

lvh13:06:17

juxtaposing those with their respective arguments isn’t that tricky

lvh13:06:31

(since map takes multiple seqs)

weavejester14:06:26

Yeah, something like:

(map (partial interleave [:a :b :c]) (combo/selections [0 1] (count [:a :b :c])))

weavejester14:06:43

I think you just need interleave and combo/selections, @lvh

lvh14:06:58

Yeah. Technically I need to vary-meta (don’t ask) so I can just map with 2 seqs anyway since that fn is going to be something weird

lvh14:06:30

jnr-ffi really wants to be used from java so it’s an interface with some annotations

lvh14:06:04

however being able to do stuff like this makes me pretty happy that I did that from Clojure instead 🙂

jjfine14:06:30

I have a function that sends a bunch of emails out, mapping over a list of recipients to do this. Wondering if this is an ok place to use pmap... I'm asking because I think I remember hearing it's a good function to avoid using.

donaldball14:06:47

It’s the easier form of concurrency, but the number of threads isn’t under your control

donaldball14:06:11

You might want to use a j.u.c Threadpool, perhaps as wrapped by the claypoole library

dhruv115:06:36

I need a bit of help.

dhruv115:06:59

i cannot seem to get the cider debugger to work properly (i cannot inject a value)

dhruv115:06:01

nvm. to inject a value it’s j and not i

ddellacosta15:06:20

@dhruv1 there's a #C0617A8PQ channel btw, you may get help faster there

dhruv115:06:52

@ddellacosta: thanks! Didn’t realize there was a #C0617A8PQ channel

ddellacosta15:06:12

also an #C099W16KZ one which I see folks asking cider questions on, and I'm honestly not sure which is better—but could try both!

dhruv115:06:37

perfect. thank you

dominicm15:06:23

Also #C050AN6QW

m1dnight16:06:09

Im using HTTP-clj and I get a persistentHashmap back where a key is #error ?

m1dnight16:06:17

What kind of sorcery is this?! 😛

jswart16:06:57

is the key a string?

hiredman17:06:32

the key isn't '#error'

hiredman17:06:19

you are being confused by the way tagged literals have a space between the tag and the value

hiredman17:06:52

as of 1.8 exceptions are printed as a tagged literal by pr

hiredman17:06:27

user=> (Exception.)
#error {
 :cause nil
 :via
 [{:type java.lang.Exception
   :message nil
   :at [user$eval1 invokeStatic "NO_SOURCE_FILE" 1]}]
 :trace
 [[user$eval1 invokeStatic "NO_SOURCE_FILE" 1]
  [user$eval1 invoke "NO_SOURCE_FILE" 1]
  [clojure.lang.Compiler eval "Compiler.java" 6942]
  [clojure.lang.Compiler eval "Compiler.java" 6905]
  [clojure.core$eval invokeStatic "core.clj" 3177]
  [clojure.core$eval invoke "core.clj" 3173]
  [clojure.main$repl$read_eval_print__9412$fn__9415 invoke "main.clj" 240]
  [clojure.main$repl$read_eval_print__9412 invoke "main.clj" 240]
  [clojure.main$repl$fn__9421 invoke "main.clj" 258]
  [clojure.main$repl invokeStatic "main.clj" 258]
  [clojure.main$repl_opt invokeStatic "main.clj" 322]
  [clojure.main$main invokeStatic "main.clj" 421]
  [clojure.main$main doInvoke "main.clj" 384]
  [clojure.lang.RestFn invoke "RestFn.java" 397]
  [clojure.lang.Var invoke "Var.java" 375]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.Var applyTo "Var.java" 700]
  [clojure.main main "main.java" 37]]}
user=> 

pandeiro17:06:29

Anyone using clj-webdriver on Linux unable to connect to Firefox? Had this problem a while...

seancorfield17:06:09

Are you running it interactively, or in background? For the latter, you’ll need a virtual frame buffer set up for X11, as I recall.

pandeiro17:06:07

interactively

pandeiro17:06:46

It's not a $DISPLAY issue or anything like that; here's a snip of stacktrace: `NotConnectedException Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: me: Recursive scan of <mailto:[email protected]|[email protected]> 1466704056032 addons.xpi DEBUG Updating XPIState for {"id":"{972ce4c6-7e08-4474-a285-3208198ce6fd}","syncGUID":"f9DxnyTWFqZ2","location":"app-global","version":"47.0","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null, ...`

m1dnight18:06:41

Ah, that makes sense, hiredman, thnx

lwhorton18:06:54

am I being dum here trying to push an artifact to clojars? the error given is clojure.lang.ExceptionInfo: Could not find artifact org.clojure:clojure:jar:1.8.0 in clojars () …. and if I look through the clojars via the web interface, it doesn’t seem obvious that 1.8.0 is actually present. (clojure 1.8 is listed as a :provided depenency for my lib)

tcrawley18:06:10

@lwhorton: clojure itself isn't hosted on Clojars, but is served by Maven Central

tcrawley18:06:22

what tool are you using? lein, boot, mvn?

tcrawley18:06:38

Central should be in your default list of repos

martinklepsch18:06:12

@lwhorton: did you maybe set-state! the :repositories key? (overriding the old value)

lwhorton18:06:48

(set-env! 
 …
  :repositories [["clojars" {:url ""
                             :username (System/getenv "CLOJARS_USER")
                             :password (System/getenv "CLOJARS_PASS")}]]
…)

lwhorton18:06:15

i’m digging around bootlaces (seems to be used all over boot-adzerk) and it seems to be doing what I’m trying to do

martinklepsch18:06:23

@lwhorton: try (set-env! :repositories #(conj % ["clojars" ...]))

lwhorton18:06:48

so … boot has some of its own env :repositories already set somewhere (which presumably includes things like maven)?

tcrawley18:06:29

it (and lein) have default repo sets, which consist of clojars and maven central, yes

lwhorton18:06:59

thanks guys, I appreciate it…. one of these days I’ll actually be able to give back and not just take take take

tcrawley18:06:26

happy to help

twashing20:06:11

Hey guys, I've created a dead simple online tool to pretty print EDN: http://edneditor.com

twashing20:06:15

There's just a lot of times that I'll have a chunk of EDN that I want to pretty print, to get a better view of my data.

twashing20:06:19

Very rudimentary at this point - so a lot of TODOs. But have a look, let me know your thoughts. Hopefully it can help you out.

josh.freckleton21:06:03

@twashing: thanks, I find I use simple tools like this a lot! 🙂

josh.freckleton21:06:34

oo, it would be nice too if it indented a little deeper 🙂

peterschwarz21:06:58

In a similar vain as @twashing, I put made a simple tool for for JSON to EDN conversion (and back). Handy for taking examples (REST API post bodies, Javascript libraries,etc) and easily turning them into a Clojure data structure. http://pschwarz.bicycle.io/json-to-edn/

twashing21:06:48

@josh.freckleton Hmm, fair enough. I’ll make that a TODO 🙂

twashing21:06:26

@peterschwarz Niiice. Looks pretty slick.

lvh21:06:11

Hi! Is there a version of equality that also includes metadata? I am creating an interface that requires types and annotations, so using metadata is not optional (I understand why equality does not normally include metadata)

Alex Miller (Clojure team)21:06:40

no, but you could write one

lvh21:06:08

okiedokie, just checking. Thanks @alexmiller 🙂

lvh21:06:17

I ended up walking the data structure to replace everything with its metadata

lvh21:06:20

not ideal but eh