Fork me on GitHub
#clojure
<
2017-02-18
>
andrea00:02:09

@hiredman thank you! I'll have a go. I don't have much experience with clojure, let alone with interop but this seems like a good chance to try that out šŸ™‚

pesterhazy00:02:48

I thought http://socket.io was superseded by websockets?

andrea00:02:26

as far as I can tell it's some protocol defined on top of ws. Something like ws being just a dump duplex pipe and http://socket.io defining the stanzas and other concept on top of it. I didn't spend much time on it but I'm trying to connect to one of those from clj

hiredman00:02:30

http://socket.io as protocol van gover over different transports, websockets are, I think the preferred one now, the clients and servers support falling back to long polling if websockets don't work

pesterhazy00:02:01

(which it will these days in all modern browsers)

lwhorton02:02:09

with clojure.spec, is there a way to more ā€œhuman-readableā€ a nested spec?

(s/def ::my-domain-entity (s/keys :req-un [:a ...])
(s/def :a (s/keys :req-un [:c ā€¦ ]))
(s/def :c number?)

lwhorton02:02:42

My complaint is that it becomes hard(er) to read a spec if it has any sort of nested maps or any deep structureā€¦ because you are chasing keys up and down a file

lwhorton02:02:31

Rather than something like schema which would allow

(m/defschema my-entity {:a {:c sc/number}}
and ignoring all the other wins of clojure.spec, this one feature of schema is nice

hulunote02:02:22

How to clj->py like clj->js ?

hulunote02:02:05

Who can help me?

hulunote02:02:15

I search have one repository https://github.com/halgari/clojure-py-redux, but i donā€™t know how to work it.

hulunote05:02:45

šŸ˜Š Hi

qqq05:02:31

It looks like time stamp is from 4 years ago. Not sure if it's still active.

pbaille06:02:48

does fexprs integration has been considered for clojure?

tianshu07:02:40

not now which channel is correct for this question. how can I do on duplicate key update in mysql with clojure.java.jdbc/insert-multi!.

schmee08:02:36

doglooksgood no built-in support for that AFAIK

schmee08:02:39

what DB are you using?

tianshu08:02:02

@schmee MySQL, should I write raw sql for that?

schmee08:02:56

yeah, raw SQL or some of the many clojure SQL DSLs + db-do-prepared should do the job

tianshu09:02:49

@schmee Thanks, I'm going to write SQL for that

sveri09:02:38

@andrea By chance I just used the java library for socket io to connect to some service using that. you can find the code here, its not really much therefore pretty easy to do: https://bitbucket.org/snippets/sveri/geK8y#snippet.clj-33

gklijs11:02:50

Not sure if I can describe my problem well, but Iā€™m kinda stuck, so Iā€™ll give it a try. I have a hobby project where I followed the instructions on http://www.luminusweb.net/docs/websockets.md and got it working. But now I want to use it for a game, and I need to know which user is connected with witch websocket. As a solution I thought I would add a unique key to the connect! on-close and on-receive functions, but because itā€™s a macro I dontā€™t know how to get this done. What I use know is evaluated in the macro, causing the key to be always the same (and being some weird object).

gklijs11:02:30

this is my current function going wrong: (defn ws-handler [request] (with-channel request channel (let [key (unique-key)] (connect! channel key) (on-close channel (partial disconnect! key)) (on-receive channel #(handle-message % key)))))

gklijs12:02:36

I kind of solved it, but Iā€™m not happy with it

gklijs12:02:39

(defn ws-handler [request] (with-channel request channel (set-unique-key) (connect! channel @unique-key) (on-close channel (partial disconnect! @unique-key)) (on-receive channel #(handle-message % @unique-key))))

gklijs12:02:30

works, but it might be that two connection come in almost at the same time, and than '@unique-keyā€™ could already have a new value. I would rather have a let within them

andrea12:02:15

@sveri LOL. Accidentally that also contains the exact url I'm connecting to šŸ˜›

gklijs12:02:01

Iā€™m still wondering for a good answer, probably I need to prevent the let from being evaluated in the macro I think

sveri12:02:11

@andrea I almost suspected that. I am into the game for a few days now. Not much bots, so, it would be great if more could join šŸ™‚

sveri12:02:16

If you have questions, just go ahead

andrea12:02:38

I played it quite a bit, and I thought a bot for it was a good candidate to practice some clojure, so sure šŸ™‚

sveri12:02:49

I use this: https://github.com/aysylu/loom for pathfinding. One of the nice things about it is, you can put maps directly into it, as keys and values, makes pathfinding very easy šŸ™‚

gklijs13:02:56

Apparently the macro had nothing to do with it, it was some other problem, so the original syntax works fine, every cannection now get an unique ker :1, :2 etc. and all functions always get the same

kah0ona15:02:24

general question about locally installing a library (not really experienced with this): I forked a library (https://github.com/weavejester/clj-aws-s3/ ), and made some tweaks. Then I upped the version in project.clj and did lein install. When I run lein repl inside the library project, I see things working. But when I use it in my application, I get NoClassDefFoundError at runtime for the Java imports the library uses

kah0ona15:02:58

should I install it in a different way locally? What am I missing? Or should it work like this?

kah0ona15:02:59

(I get this error: [{:type java.lang.NoClassDefFoundError :message "Could not initialize class com.amazonaws.ClientConfiguration" :at [aws.sdk.s3$s3_client_STAR_ invokeStatic "s3.clj" 52]}])

jumar15:02:47

@kah0ona this should probably go to #leiningen - you can also paste the output of lein deps :tree there

brabster15:02:55

@kah0ona the deps on master for clj-aws-s3 are really, really old... that might be something to do with your problem

kah0ona15:02:17

yeah that's why i forked, I updated all those to the latest

kah0ona15:02:39

because without updating i had deps conflicts with other libs used in my app

kah0ona15:02:49

and i confirmed that the lib still worked

brabster15:02:02

cool, didn't realise

kah0ona15:02:03

from the repl in the project itself

kah0ona15:02:38

but then it should work if i just do a lein install and then include it in my application right?

brabster15:02:39

could be aws-sdk has changed structurally since the lib was written

kah0ona15:02:43

ie, are those the steps

kah0ona15:02:18

but wouldn't it crash than as well if I would use it from the repl inside the library project itself?

pesterhazy15:02:29

there's also amazonica.aws.s3, which may be more up to date

brabster15:02:46

it is, @pesterhazy - I use that

kah0ona15:02:57

ok i'll try that then

pesterhazy15:02:12

also you could do a lot worse than using the amazon java libraries using java interop

brabster15:02:03

that too... but amazonica's docs are pretty good for a quick result - also if jar size matters, there's instructions on the readme for excluding all the aws sdk deps and then selectively including just what you want, with the example being s3

pesterhazy15:02:08

amazon as a company runs on java, which ensures that aws's java libraries are always as good or better than their peers

brabster15:02:18

i.e. needs

[com.amazonaws/aws-java-sdk-core "1.10.49"]
               [com.amazonaws/aws-java-sdk-s3 "1.10.49"]

brabster15:02:13

I reckon adding that core lib might also fix your problem with the clj-aws-s3 deps, not sure why it works at the repl but maybe you have extra deps on your repl via your user profile or something

brabster15:02:49

but I'd stay away, it looks pretty much unsupported today šŸ™‚

kah0ona15:02:26

i'll switch to amazonica

brabster15:02:42

šŸ‘ good luck!!

kah0ona15:02:06

thx for all the tips !

danielsz17:02:33

I started to play with clojure.spec, and I like what I see, but boy those namespaced keywords are a pain to de/serialize. Forget JSON, and monger just drops the namespace because internally it uses clojure.core/name . Has the community gained wisdom on that topic?

danielsz17:02:53

As far I can tell, I'll have to pre-process the keys with pr-str and post-process them with clojure.edn/read-string. Any other ideas?

tbaldridge18:02:30

@danielsz Well if you really want to retain all your datatypes, I'd suggest starting with Transit instead of JSON. For large objects Transit can even be faster than JSON due to internal caching and the like.

tbaldridge18:02:27

Aside from that, I assume you've seen :req-un in s/keys? That looks for un-qualified keywords, and was pretty much added because of JSON like data structures.

ejelome19:02:10

hi, anyone using yesql here? I'm having a problem connecting to the postgresql database, it prompts an error:

...
Caused by: java.sql.SQLException: No suitable driver found for jdbc:
...
Here's the offending code:
(def db-spec {:classname "org.postgresql.Driver"
              :subprotocol "postgresql"
              :subname "//localhost:5432/testdb"
              :user "testuser"
              :password "testpass"})

(defquery users-by-country "../resources/sql/queries.sql"
  {:connection db-spec})
I have no Java background unfortunately.

dottedmag19:02:52

[^PersistentVector colors] is this type hint useful?

bronsa19:02:27

depends on how you use colors

bronsa19:02:44

type hints are only useful in the context of interop

bronsa19:02:19

that's useless

dottedmag19:02:24

@kgofhedgehogs So you can drop them šŸ™‚

tbaldridge19:02:34

and never mind that it's also wrong sometimes

tbaldridge19:02:47

(many things are IPersistentVector that aren't PersistentVector)

sveri19:02:32

@ejelome It seems like you need the dependency for postgres: [org.postgresql/postgresql "9.4.1212"]

ejelome19:02:02

oh right! thanks @sveri, now I can connect šŸ™‚

bradford19:02:21

Hi! Is Enlive considered "done", or "dead"? Is there something that's currently maintained? https://github.com/cgrand/enlive

bradford19:02:47

I'm using it for scraping

schaueho20:02:53

different lib, same question: what about Incanter? There is a recent reddit thread asking whether it's still en vogue or dead. The github repo doesn't look too promising AFAICT ...

danielsz20:02:17

@tbaldridge Oh, thank you! I actually hadn't seen :req-un. I really just started looking at spec. That's really good to know. Now whether I really want to retain my datatypes, don't we all šŸ™‚

danielsz20:02:20

@tbaldridge I mean, when you have a domain model enriched with specs, u want to retain it and leverage it to the maximum, right? You want to keep it intact when it travels in and out of the application boundaries. When you store domain entities in a database, for example. Isn't that the intention as well?

danielsz20:02:27

@tbaldridge Many interface libraries are unable to cope with the namespaced keywords. Monger, for example.

tbaldridge20:02:07

Yeah those libraries should be considered broken, imo. But I know that's rather drastic

danielsz20:02:13

@tbaldridge Right, no I get that. It's reasonable to say that some libraries are not yet prepared for clojure.spec.

tbaldridge20:02:20

So yeah req-un is fine if you have no control over the situation, otherwise I try to keep true keyword support as a hard requirement of my deps

tbaldridge20:02:13

Rest APIs are another case where you often have no control over the shape of the data

danielsz20:02:51

@tbaldridge Right. Hence the coercion mechanism in spec, right? Are people using it to restore namespaces to keys?

tbaldridge20:02:06

No, most things I've seen just use req-un

tbaldridge20:02:57

Maybe I'm misunderstanding the problem

danielsz20:02:48

@tbaldridge No, I think you nailed it. I guess I'm in the market for a persistence store that can take care of my spec'ed darlings and handle serialization for me.

danielsz20:02:23

Monger was a joy to use before spec. šŸ™‚

danielsz20:02:23

I'll look at other options.

danielsz20:02:15

Which seems to be a pattern anyway. Everytime I start a project, I look at the persistence solutions out there. I feel blessed with the Clojure ecosystem because most things have "perfect" solutions, but this is one area where I keep on looking.

nooga20:02:56

oh, good one, I was pondering on this yesterday

adambrosio23:02:27

Is there anyway to get case to work with two or more syntax-quoted symbols?

(case `foo/a `foo/a 1 `bar/b 2) 
;=> Duplicate case test constant '(quote quote)ā€™

danielsz23:02:49

adambros: From the docs: The test-constants are not evaluated. They must be compile-time literals, and need not be quoted.

adambrosio23:02:16

sorry my example might not have been the best, let me edit it

adambrosio23:02:24

Itā€™s more a convenience really, but I canā€™t use aliases to namespace more than one symbol

danielsz23:02:52

Are you writing a macro?

adambrosio23:02:19

om.next mutate, iā€™m just not wanting to use a multimethod

danielsz23:02:45

what is this case statement supposed to do?

adambrosio23:02:41

does different actions depending on the symbol

danielsz23:02:05

Ah, so they are symbols or namespaces or Vars?

adambrosio23:02:15

just symbols

danielsz23:02:32

then why use a backtick?

adambrosio23:02:48

namespaced and i would like to use an alias

adambrosio23:02:17

im simply curious about case, i think i have alternatives i can use

danielsz23:02:25

Let me know what you find out šŸ™‚

bradford23:02:13

I saw someone mentioned Loom earlier. It's very cool. I built a stream process orchestrator and simulator with it

mruzekw23:02:37

Does anyone know how to deal with environment vars with respect to a postgres DB? Iā€™m working with a luminus application and Iā€™m stuck

mruzekw23:02:01

Thanks Iā€™ll check this out

bradford00:02:35

+1, I use that. You can also make it play nice with Component, but I donno if people use that anymore (I have mixed feelings on it)

richiardiandrea00:02:37

I like so so like cprop as you can use either env vars or system properties