Fork me on GitHub
#clojure
<
2018-12-10
>
Bravi12:12:55

Hi everyone. I have a ClojureScript (reagent) application and I would like to add some server side rendering to it for a better support for SEO and etc. Ideally, I’d like to create an isomorphic site. I was looking at http://blog.testdouble.com/posts/2016-01-21-isomorphic-clojurescript and most likely I’ll proceed with this. but just wanted to ask, perhaps there’s a framework already out there that solves this?

peter hull12:12:52

datafy question: If we datafy an object to produce a map, should the keys be symbols, keywords or namespaced keywords (or doesn't it matter?)

alexmiller14:12:59

all of those are data so doesn’t matter to datafy

ClashTheBunny14:12:43

Is there a convention?

alexmiller14:12:50

no, but I think a map with keyword keys is the most idiomatic way to represent information in Clojure

peter hull12:12:24

followup question: in the metadata, is there any reason why datafy marks the source object with a keyword (:clojure.datafy/obj) but extending protocols needs a symbol ('clojure.core.protocols/nav)?

alexmiller14:12:13

yes, and it’s a good question that Rich went back and forth for a while. :) Using the symbol key here is intentionally different than typical meta keys (which are keywords) and thus unlikely to collide. Also, symbols naturally refer to functions so there is sort of a semantic match here as well.

peter hull15:12:04

That makes sense, thanks.

bronsa14:12:18

@arohner I cut tools.analyzer 0.7.0 with support for injected locals for add-binding-atom

rickmoynihan14:12:30

Does anyone know of something that is the inverse of bean? i.e. takes a beanified map and converts into a POJO?

alexmiller14:12:11

the java.data library has some stuff like that https://github.com/clojure/java.data

rickmoynihan14:12:28

thanks @alexmiller will take a look

alexmiller14:12:31

I’ve hacked together macros to do stuff like that a few times but they were generally pretty customized to what I was doing

rickmoynihan14:12:03

I only have one pretty small bean, so I might just hand roll a function to do it

rickmoynihan14:12:13

unless there’s something generic though to-java looks like it might do what I need

pablore14:12:54

Is there a way I could access an atom’s previous state? I’m trying to build a simple time travelling debugger using the fact that the data structures are persistent

bronsa14:12:31

@pablore not without you explicitely doing some bookeeping

bronsa14:12:26

user=> (def my-atom (atom {}))
#'user/my-atom
user=> (def my-atom-history (atom [@my-atom]))
#'user/my-atom-history
user=> (add-watch my-atom :history (fn [_ _ _ new-state] (swap! my-atom-history conj new-state)))
#object[clojure.lang.Atom 0x292d1c71 {:status :ready, :val {}}]
user=> (swap! my-atom assoc :a 2)
{:a 2}
user=> (swap! my-atom assoc :b 2)
{:a 2, :b 2}
user=> (swap! my-atom dissoc :a)
{:b 2}
user=> @my-atom-history
[{} {:a 2} {:a 2, :b 2} {:b 2}]

rickmoynihan14:12:09

to-java works a treat

pablore14:12:15

@bronsa yeah this is waht I had in mind at the start, but then I remembered that the persistent data structures do indeed keep track of it’s history

bronsa14:12:27

they don't

bronsa14:12:20

"recording its history" would require keeping backreferences to old values, rendering GC impossible

pablore14:12:37

aren’t them a trie holding diffs it each node?

bronsa14:12:58

persistent data structures simply share common paths with old values, but they don't record diffs or anything like that

borkdude16:12:44

Has anyone got a good solution on the JVM for this? Does deleting a namespace have the effect that the data held on by the vars in that namespace will be garbage collected? https://github.com/borkdude/advent-of-cljc/issues/85

noisesmith17:12:08

surely that depends on whether anyone is carrying references to the vars?

borkdude17:12:29

not outside of those namespaces

borkdude17:12:38

they are isolated

borkdude17:12:54

except for the stuff it refers to at in other namespaces (utils)

noisesmith17:12:13

also, you could ns-unmap the var, or intern it to nil - maybe it's better since it's more direct?

borkdude17:12:17

something like: (run! #(alter-var-root % (fn [_] nil)) (vals (ns-publics 'aoc.y2018.d01.borkdude)))

noisesmith17:12:41

that seems about right, yeah

didibus19:12:16

It seems tools.cli breaks native-image compilation. Has anyone else encountered this?

taylor19:12:55

FYI there's a (pretty quiet) #graalvm channel

didibus19:12:06

I was trying to get cljfmt to compile. And I had to remove tools.cli and roll my own args parsing instead for it to work.

ghadi19:12:43

native-image is not a real JVM -- it cannot handle a bunch of corners of Java

ghadi19:12:03

not sure what specifically you ran into, but issues abound with graal native-image

didibus19:12:23

I'm aware of that. But I feel if its worth working around these issues it would be in tools.cli

taylor19:12:17

@didibus I've been able to compile native-image stuff with tools.cli as a dependency https://github.com/taylorwood/clj.native-cli/blob/master/deps.edn#L2

didibus19:12:16

You didn't get a DynamicClassLoader exception?

didibus19:12:06

I see that you defer errors to runtime.

didibus19:12:30

In my case, without tools.cli I don't need that setting

didibus19:12:01

And at runtime, tools.cli does throw the same error anyways, rendering the CLI useless

didibus19:12:26

I also found an online graalvm compiled version of cljfmt, but they also bypass tools.cli

taylor19:12:07

weird, I made this example project and it uses tools.cli and compiles and works just fine with CLI args https://github.com/taylorwood/clojurl

taylor19:12:50

are you on the latest RC?

taylor19:12:12

(although I was able to get above project working 2-3 RCs ago)

didibus04:12:55

I was. I wonder if its a particular use of tools.cli maybe

taylor19:12:51

also I think some other people have already compiled native images of different CLJ formatting tools

ghadi19:12:10

didibus did you AOT compile first?

seancorfield19:12:49

@didibus Feel free to create a JIRA issue for me to look at for tools.cli -- but make sure you include complete instructions to repro your issue (I haven't even looked at GraalVM, so make sure your issue includes all the tool setup steps too!).

didibus19:12:17

Ya, I did AOT. Ok, when I get a chance I'll see if I can repro and submit an issue.

NoahTheDuke20:12:17

Is it worth looking into server side clojurescript through node if I want zero-downtime deploys?

ghadi20:12:15

No. Deployment is orthogonal to the language used

ghadi20:12:30

Can do zero downtime with a load balancer pretty easily

NoahTheDuke21:12:55

If I have in-memory-only session information I want to persist through deploy, can a load balancer or blue-green strategy work?

ghadi21:12:47

in memory session is by definition ephemeral.... nothing you can do about that

ghadi21:12:57

need to use a shared session / db

orestis20:12:28

You might want to look into blue-green deployment strategies too.

emccue20:12:01

I'm having a bit of trouble getting nrepl installed on a gradle project

emccue20:12:55

its my first time using gradle for anything so I don't really know where to start

emccue20:12:29

this is what I have so far

emccue20:12:51

(99% template)

emccue20:12:55

for whatever reason It keeps failing to install

seancorfield20:12:34

Define "failing to install" -- what error do you get?

seancorfield20:12:45

(the Clojars repo URL should probably be https://clojars.org/repo/ -- https rather than http?)

tcrawley20:12:29

or https://repo.clojars.org to use the CDN-fronted repo

emccue20:12:45

Just a Could not resolve: nrepl:nrepl:0.5.0

emccue20:12:58

its not more descriptive than that

emccue20:12:37

ill try the https now

emccue21:12:13

Full output, though it doesnt seem all that specific

seancorfield21:12:27

buildscript {
    repositories {
        jcenter()
        maven { url = "" }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
    }
}
repositories {
    maven { url = "" }
}
Like that?

seancorfield21:12:59

(caveat: I have never used Gradle)

emccue21:12:03

appied change, running it now

emccue21:12:18

yep worked like a charm

4
seancorfield21:12:27

(and, as Toby says, you should use really)

datran22:12:21

Does anybody know of a (preferably mature) implementation of Shamir's Secret Sharing?

datran22:12:33

It involves breaking a secret into a number of "shares", and using some subset of the shares to reconstruct the secret

ghadi22:12:31

there are some java libs out there, none of which I can vouch for: https://github.com/timtiemens/secretshare

ghadi22:12:41

but you're not going to find a "native clojure" crypto library

ghadi22:12:04

it's easy enough to call java libs from clojure

dpsutton22:12:11

@lvh might be the person to talk to if he is still on the slack

dpsutton22:12:36

i think he was just elected to clojurists together so he's active somewhere

ghadi22:12:37

He's great - but again, I can't vouch for something I haven't evaluated

ghadi22:12:47

We used SSS at a previous life from python+C -- lots of libs there.

ghadi22:12:50

But yes -- wrap a Java lib.

datran22:12:19

Thanks! I had found secretshare yesterday but I haven't been able to get it to work the way I want, this looks promising

datran22:12:45

I guess while I'm at it, does anybody have any suggestions for public key encryption?

ghadi22:12:06

let's move to #crypto

datran23:12:16

how do you convert a java Map into a clojure map?

noisesmith23:12:35

clojure hash-maps are java Map instances, if you need clojure's version explicitly (into {} m) will do it

noisesmith23:12:15

but of course it will still be a Map :D

noisesmith23:12:26

for many things that conversion is never needed

user=> (get (System/getenv) "PWD")
"/Users/justin.smith/egret"

noisesmith23:12:28

(ins)user=> (def hm (java.util.HashMap.))
#'user/hm
(ins)user=> (.put hm :a 0)
nil
(ins)user=> (:a hm)
0