Fork me on GitHub
#clojurescript
<
2016-11-07
>
eggsyntax01:11:38

I know cljs doesn't inherently support ratios like clj does -- is there a standard approach when you need to represent and work with them? Custom type? Some 3rd-party lib? Or just storing them as a tuple?

eggsyntax02:11:33

Lovely! I threw together a defrecord & have been using that so far, but I’ll definitely check exact out & very possibly switch. Thanks 🙂

gfredericks03:11:41

that's what I get for typing after I turn off the monitor

gfredericks03:11:32

Despite appearances, that's not actually a Super Secure Password, I was just very poorly trying to invoke dmenu from i3 and type "i3lock"

raaon04:11:32

anyone know the sitch w/ om.next -- what's it's future?

raaon04:11:40

good cos I just wrote a bunch of om.next code :)

raaon04:11:08

#om-next channel is as quiet as a yoga class

keatondunsford04:11:31

I think #om is where most everybody is at.

keatondunsford04:11:46

DN is in #om and not #om-next

raaon04:11:13

ah ok thx!

keatondunsford04:11:28

You got it champ.

vigilancetech06:11:47

how do I pre-compile fragments of cljs for execution at run time, i.e. why does this: (js/eval #(+ 3 5)) return [Function "function () {return ((3) + (5));}"] instead of 8 and Uncaught Syntax Error: Unexpected token ( if its converted to a string before being given to js/eval?

vigilancetech06:11:48

IOW, does JS have a reader as separated from its eval and if so, what is its eval called (because as above, its apparent that the js/eval is both reader AND eval)? I've tried using "." all around that and get nothing but errors

thedavidmeister07:11:16

hey, if i have (def x 1), how do i get 1 from 'x?

rauh07:11:31

@vigilancetech You don't have a JS runtime during compilation, you do however have all of Clojure available (in macros). So you can use that to do arbitrary complex pre-computation during compilation. Otherwise you can hope on Google Closure to optimize your code if it's not too difficult.

vigilancetech07:11:52

@rauh so you are saying just include bootstrap eval and hope for the best?

rauh07:11:21

Bootstrap eval? What are you actually trying to do?

vigilancetech07:11:42

it seems to me that a #(function) gives me js and I don't see why I can't execute that with something like a js eval at run time.

vigilancetech07:11:17

I have some variant JSON fields I need to extract and I want to de-complect that from the layout, because it may very well be changing fairly often

vigilancetech07:11:51

when I convert them into cljs maps some have maps within maps and some have maps within vectors within maps

rauh07:11:21

If you want to massage your data you can use a macro to do that an export cljs data

rauh07:11:01

For instance, some people have (my-macros/config :foo :bar) for reading config from you config file.

vigilancetech07:11:06

I just want to have a list of lists with the field name and then a fragment of code to extract its value right next to it

vigilancetech07:11:07

then I can just walk the list displaying the field name and evaling the code to give me the value

vigilancetech07:11:29

seems the most elegant way. I'm kind of surprised this isn't something commonly done with cljs

vigilancetech07:11:12

the [Function "function () {return ((3) + (5));}"] looks like something I should be able to pass off to js at runtime

rauh07:11:42

Functions are first class, you can just assign them in your data structures

rauh07:11:14

and then call them. Like ((get-in your-data [:foo :bar]) :args-to :fn)

vigilancetech07:11:18

I thought them being first class meant you COULD do stuff like that with them. Store them, pass them around, etc...

rauh07:11:44

Well you probably can't "store"/serialize them, not sure if I'd do that

rauh07:11:01

But yes, you can assign them to anything and then use them just like you'd use a number of any other object

vigilancetech07:11:38

right, so it escapes me why I can't have the cljs compiler convert them to js and then call them later at runtime.

vigilancetech07:11:00

without having to bring a whole cljs compiler with me into the end product

vigilancetech07:11:07

I've also tried that, to just add a set of parens around the extraction code

rauh07:11:13

The cljs compiler will def convert all your cljs code to js.

rauh07:11:28

Just don't do code as strings.

vigilancetech07:11:01

right. Unfortunately js/eval wants a string, so its both reader and eval

rauh07:11:07

Don't use js/eval

rauh07:11:16

(#(+ 3 5))

rauh07:11:26

will call the function, no need for eval

vigilancetech07:11:43

that's what I would have thought.

rauh07:11:13

(def xyz [(fn [] :hi)]), then you can (mapv #(%) xyz)

vigilancetech07:11:17

it doesn't evaluate it for some reason. I get this: MOTHERBOARD, ((fn* [] (cell= (:name (:mb jm))))), 35 when I call it this way: (#(-> info-mb first rest))

vigilancetech07:11:47

(def info-mb "info page motherboard descriptions map" '(("MOTHERBOARD" #(cell= (:name (:mb jm))))

vigilancetech07:11:26

jm is the map created from the JSON

vigilancetech07:11:37

it works with an eval in clojure

rauh07:11:22

What is MOTHERBOARD?

vigilancetech07:11:59

its the field name. The descriptive text. Those are the arguments that get passed down to a padding function. The field's VALUE should be the 2nd argument, not the function code

vigilancetech07:11:28

but the map keys are :mb and :name

rauh07:11:24

You have to show us the example data in a gist, and how you're trying to call it

rauh07:11:48

Just extract some of your data and def so people can see what you're trying to do

rauh07:11:52

I gotta run...

vigilancetech07:11:59

ok, I think I can reduce it down to pretty simple. Like what I did in the original post above

vigilancetech07:11:09

k, thx for trying 🙂

manishkumarmdb09:11:51

can anyone explane me, how to use reCaptcha in clojurescript for registration from?

cfleming09:11:55

Does anyone know if the goog.crypt module supports cryptographic signing/verification?

cfleming09:11:08

Specifically using SHA-256 w/ RSA?

cfleming10:11:50

Actually, it looks like Node provides what I need.

mikeb10:11:05

If node doesn't work out, libsodium(my preferred crytpo lib) has several js wrappers. https://download.libsodium.org/doc/bindings_for_other_languages/

cfleming10:11:38

@mikeb Thanks, the problem is I need to use this in AWS lambda

cfleming10:11:51

So I’d rather not rely on native extensions if possible

cfleming11:11:31

Although installing node via homebrew with the crypto extensions seems non-trivial

shen11:11:21

Quick question: my current CI pipeline is Codeship -> S3. Looking at Netlify as it seems… simpler than S3, but doesn’t seem to gel as well with boot/cljs? Any recommendations, or should I work my way through netlify-cli?

anmonteiro11:11:57

@gfredericks re: our conversation the other day about extend-type, I just remembered that you can (extend-type default)

anmonteiro11:11:30

so you don't need to repeat yourself for number, object, string, function, etc.

gfredericks16:11:42

@anmonteiro oh awesome, I will definitely do that. Do you think it works for nil as well?

anmonteiro19:11:10

@vigilancetech you want

(def b `("some text" ~#(println "another function")))

kenny19:11:18

@vigilancetech It's because it is a syntax quoted list. Do this

(def b (list "some text" #(println "another function")))

kenny19:11:26

Or that 🙂

kenny19:11:05

Are there any benchmarking libraries in cljs? Or do you guys just do a simple loop over the fn calls and create the avg time?

dnolen19:11:43

@kenny for serious benchmarking just use the browser tooling

dnolen19:11:56

Chrome is quite good, Firefox and Safari have passable stuff as well

vigilancetech19:11:14

ah, I think I see what you guys are saying. Thanks!

kenny19:11:31

@dnolen Hmm.. I've never used it for benchmarking, only debugging slow code. Is there a way to tell Chrome to run a piece of code 1000 times and report the results?

dnolen19:11:00

@kenny console.profile is a thing

kenny19:11:24

Ooooo. Thanks 🙂

mikeb19:11:08

@cfleming It thought that https://github.com/jedisct1/libsodium.js is pure js so no native extensions.

cfleming19:11:57

@mikeb Oh right, it uses Emscripten

cfleming19:11:23

But the Node core crypto stuff is actually sufficient for my needs

cfleming19:11:28

It’s pretty easy to use.

chrishacker19:11:01

any ideas how to investigate why the cljs portion of my project will compile for :dev profile in <30s but when I deploy with dokku, the cljs portion takes 400s to compile?

dnolen19:11:42

@chrishacker advanced compilation is extremely resource intensive

dnolen19:11:03

if the build box doesn’t have enough memory then advanced compiles can take much longer

chrishacker19:11:43

ok. so I should test it out on a larger memory footprint and in theory it should compile faster

dnolen19:11:37

@chrishacker yes by larger I mean at least 1gb

chrishacker19:11:55

pretty sure we're using 1gb

dnolen19:11:07

then try doubling it

chrishacker19:11:16

but we'll bump it.

dnolen19:11:23

if that doesn’t work - then you’ll have to investigate more

dnolen19:11:37

there’s no reason for compiles to be 10x slower

danielcompton19:11:17

@chrishacker check if you've provided memory settings in your project.clj as well, as the JVM will automatically pick values based on the environment which may not be optimal

chrishacker19:11:19

@danielcompton yep, thx. it was set to -Xmx1g. going to bump it to -Xmx2g and see what happens later this afternoon.

thheller20:11:15

I'm drawing a blank here .. is there a way to run a single deftest in cljs.test? don't want to test the entire ns?

dnolen20:11:14

@anmonteiro just ported Rich Hickey’s perf enhancements to clojure.spec, if you’re using it - now would be a good time to test with master

jrheard21:11:14

@kenny i’m gonna write a blog post on profiling cljs in a few weeks, but i’m sure you’ll figure it out between now and then 🙂 like david said, console.profile totally rules

jrheard21:11:28

one thing i didn’t notice for a very long time that i find useful - the profile viewer has this little eye icon, which comes in handy for drilling down past any outer layers of stuff you don’t care about (figwheel, etc)

kenny21:11:48

@jrheard I'll keep an eye out for it.

kenny21:11:51

@jrheard Where is this eye icon you speak of?

kenny21:11:12

Found it.. its just not there in the flame graph view

jrheard22:11:13

ah yeah, i rarely use the flame graph view, i might be crazy though 🙂

chrishacker22:11:25

Following up on earlier :optimizations question/issue. Here is my cljsbuild output from a dokku deployment:

Applying optimizations :advanced to 229 sources
       Nov 07, 2016 10:10:05 PM com.google.javascript.jscomp.LoggerErrorManager println
       WARNING: /tmp/build/target/cljsbuild/public/js/out/cljs/compiler.js:559: WARNING - References to the global RegExp object prevents optimization of regular expressions.
       cljs.compiler.emit_constant.cljs$core$IMultiFn$_add_method$arity$3(null,RegExp,(function (x){
       ^

       Nov 07, 2016 10:10:05 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
       WARNING: 0 error(s), 1 warning(s)
Optimizing with Google Closure Compiler, elapsed time: 183312.998139 msecs
       Optimizing 233 sources, elapsed time: 206736.604839 msecs
       Successfully compiled "target/cljsbuild/public/js/app.js" in 286.498 seconds.

chrishacker22:11:58

Two questions: 1) has anyone see the RegExp warning before? It seemed to appear around the same time as the substantial increase in compile time. 2) any other suggestions on how/where to look into the cause of the compile time?

jr22:11:29

cljs-time maybe?

chrishacker22:11:06

@dnolen Thanks for the suggestion earlier - I increased from 1gb to 2gb and it sped up from 400s+ to ~300s. Have any further advice based on the above?

dnolen22:11:40

@chrishacker make sure that the JVM is running with -server

dnolen22:11:54

other than that it’s hard for me to think of anything

dnolen22:11:01

is the box something you control?

chrishacker22:11:11

:jvm-opts ["-Xmx2g" "-server" "-Dconf=.lein-env"]

dnolen22:11:42

you need ^:replace for those settings to actually take

chrishacker22:11:58

ah... k. crap. smh

dnolen22:11:19

well I would consider this one of Lein’s worst “features"

chrishacker22:11:43

thx. I'll give that a go

dbsgtk23:11:41

I'm going to repost a question I foolishly posted before getting on a plane from Chicago to Qatar.

dbsgtk23:11:52

Hi all, I'm a clojure noob, and I'm using http://clojure.java.io in a clojure library, but only reading files into data structures at compile time. I'd like to read the same files (at compile time) in a clojurescript program. I've read that it's possible to use clojure IO at compile time, but am unsure how to do it. Can anyone point me to a simple example?

kenny23:11:38

@dbsgtk You can do this in a .clj (or .cljc) file using macros.

dbsgtk23:11:55

@kenny thanks, I'll look into it. It'll be my first foray into .cljc files

kenny23:11:53

It may get a little messy. I suggest writing it in a .clj file. I typically use .cljc for utility functions shared between clj and cljs

johanatan23:11:16

hi, with :optimizations :advanced enabled, do we still benefit from goog's module system? i.e., it seems like everything gets compiled into one file so there's no delayed loading of the various modules as they are actually encountered (as there would be in :optimizations :simple or :none modes).

dnolen23:11:10

@johanatan Google Closure supports code splitting and deferred loading even with :advanced optimizations