Fork me on GitHub

is there an idiomatic way to limit precision when generating doubles from a spec? I have the following but I really just want to generate dollar amounts

(spec/def ::amount (spec/double-in :Nan? false :infinite? false))


You could generate integers, then use a function to divide them by 100.


Where by 'use a function' I think I mean using gen/fmap as described here:


ok, I'll try that. Thanks


Hello: apologies if this has been asked before, but is there a goto template for react-native development?

Michaël Salihi08:02:24

• Re-natal : Figwheel + RN • If you want run with Shadow-CLJS : Note that you have the channel #cljsrn for all the CLJS and React Native stuff


Thanks for the info!

Michaël Salihi08:02:24

• Re-natal : Figwheel + RN • If you want run with Shadow-CLJS : Note that you have the channel #cljsrn for all the CLJS and React Native stuff


Did anyone try to decode binary transit data in js / cljs?


You probably mean "encode"? If so, Transit already supports binary data. And it uses base64 for it.


@U2FRKM4TW transit-js and transit-cljs only support the :json format, right? And I only need decoding


I am still not sure what you mean. You pass the data to a Transit writer on one end, you get it out of a Transit reader on the other end. Why do you need to explicitly do something with base64?


(require '[cognitect.transit :as t])

(let [out (ByteArrayOutputStream.)
      writer (t/writer out :json)] 
  (t/write writer (.getBytes "Clojure" "UTF-8"))
  (let [in (ByteArrayInputStream. (.toByteArray out))
        reader (t/reader in :json)]
    (String. (t/read reader))))
=> "Clojure"
And something similar should work in CLJS just as well - you'd get a Uint8Array instead of bytes[].


Here, if you scroll a bit, is a table with all data types supported by Transit: bytes is in there.


Thank you. However I want the binary format because it is more compact than json. Not for a regular web app case. It will have to be like this: encoding clj data -> transit msgpack bytes -> base64 string. On the cljs side: decode base64 to binary integer array -> cljs data


I see. Just make sure you do actual measurements, because base64 eats away more than 30% of space. Just out of curiosity - why do you even need base64, why not just transfer binary data?


I need to put the dat in a cloudformation template


maybe it could be higher order base, but then I would also have to write that decoding code


My point is that it's very likely that JSON will end up being smaller than base64-encoded binary. :) I just tested it on a few samples, and that's indeed the case.


I've tested in on a few samples where it wasn't the case 🙂 But it depends on other things as well. I heavily use integers for instance


But i'm happy to have received your feedback and given the current state of transit libraries I'll try to get the maximum out of transit-cljs


Oh, nice! Can you give me such a sample?


It's not open source yet, but it will be when it's done. The basic idea is to replace repeated and known entities by integers. For my use case it is much more compact than Gzip for instance


Interesting, thanks!

Joe Corneli18:02:11

Hi, I am trying to find my way around inside of a CLJS REPL.

Joe Corneli18:02:19

cljs.user> (require 'cljs.analyzer.api)
cljs.user> (cljs.analyzer.api/all-ns)
#object[Error Error: No protocol method IDeref.-deref defined for type null: ]
	 cljs.core/missing-protocol (target/public/cljs-out/admin/cljs/core.cljs:316:4)
	 cljs.core/-deref (target/public/cljs-out/admin/cljs/core.cljs:671:1)
	 cljs$core$deref (target/public/cljs-out/admin/cljs/core.cljs:1452:4)

Joe Corneli18:02:26

This is a bit confusing

Joe Corneli18:02:12

Is there a way to dig deeper and understand what this "null" is about?

Joe Corneli18:02:45

The CIDER message is as follows:

Joe Corneli18:02:57

1. Unhandled clojure.lang.ExceptionInfo
   #object[Error Error: No protocol method IDeref.-deref defined for
   type null: ]
   {:type :js-eval-exception,
    {:status :exception,
     "#object[Error Error: No protocol method IDeref.-deref defined for type null: ]",
     :ua-product :firefox,
     "cljs$core$missing_protocol@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:309:9\ncljs$core$_deref@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:2162:17\ncljs$core$deref@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:4927:18\ncljs.analyzer.api.all_ns.cljs$core$IFn$_invoke$arity$1@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:197:73\ncljs$analyzer$api$all_ns@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:183:33\ncljs.analyzer.api.all_ns.cljs$core$IFn$_invoke$arity$0@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:193:33\ncljs$analyzer$api$all_ns@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:179:33\n@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js line 751 > eval:1:94\n@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js line 751 > eval:9:3\nfigwheel$repl$eval_javascript_STAR__STAR_@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:751:24\n@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:799:56\nG__12816__2@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:35676:106\nG__12816@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:35943:20\nfigwheel.repl.ws_connect.cljs$core$IFn$_invoke$arity$variadic/</<@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:1053:30\\\\<|>.WebSocket.prototype.onMessage_@http://exchange-cljs.test/cljs-out/admin/goog/net/websocket.js:426:8\n"},
    :form (cljs.analyzer.api/all-ns),
    "try{,(function (){var ret__6754__auto__ =;\n(cljs.core._STAR_3 = cljs.core._STAR_2);\n\n(cljs.core._STAR_2 = cljs.core._STAR_1);\n\n(cljs.core._STAR_1 = ret__6754__auto__);\n\nreturn ret__6754__auto__;\n})());\n}catch (e184785){var e__6755__auto___184786 = e184785;\n(cljs.core._STAR_e = e__6755__auto___184786);\n\nthrow e__6755__auto___184786;\n}"}
                 repl.cljc:  578  cljs.repl$evaluate_form/invokeStatic
                 repl.cljc:  499  cljs.repl$evaluate_form/invoke
       piggieback_impl.clj:  207  cider.piggieback/eval-cljs
       piggieback_impl.clj:  206  cider.piggieback/eval-cljs
       piggieback_impl.clj:  243  cider.piggieback/do-eval/fn
          152  clojure.lang.AFn/applyToHelper
          144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
       425  clojure.lang.RestFn/invoke
       piggieback_impl.clj:  220  cider.piggieback/do-eval
       piggieback_impl.clj:  219  cider.piggieback/do-eval
       piggieback_impl.clj:  266  cider.piggieback/evaluate
       piggieback_impl.clj:  264  cider.piggieback/evaluate
          384  clojure.lang.Var/invoke
       piggieback_impl.clj:  297  cider.piggieback/wrap-cljs-repl/fn/fn/fn
       piggieback_impl.clj:  190  cider.piggieback/enqueue/fn
           22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
           22  clojure.lang.AFn/run
       834  java.lang.Thread/run


@holtzermann17 you are not in a self-hosted REPL so you can only access the analyzer from a clojure REPL


the null is about the compiler env not being initialized, since that is initialized on the clojure side of things

Joe Corneli19:02:38

OK, that's interesting.

Joe Corneli19:02:56

I do have Clojure listed as a dependency in the project, but that's not enough?


no you misunderstand how things work. you are in CLJS REPL so things you eval'd run in the JS engine after being compiled by the CLJ side


you want to talk to that CLJ side directly instead


but what exactly are you after? you might need to go self-hosted depending on what you are doing

Joe Corneli20:02:28

Yeah, just hoping to use all-ns at the moment. Ah. I could try for the [self-hosted]( compilation...

Joe Corneli20:02:35

Sounds like a bit of heavy lifting for this limited purpose but it might be interesting.


all-ns is intended to be used from CLJ (or from macros), so its not directly accessible in the REPL unless you are using self-hosted

Joe Corneli20:02:30

Maybe compiling a self-hosted version will be a good "learning project" for me for this weekend

Joe Corneli20:02:52

Thanks for the helpful guidance!

Ivan Koz23:02:28

Guys, i'm just getting into frontend, how do you approach css\layout side of things is there something specific for that?


just getting into frontend in general or just getting into it with clojure?

Ivan Koz23:02:42

in general, last time i did website was 10 years ago

Ivan Koz23:02:55

it was joomla php build


there's something to be said for just sticking with vanilla css, especially if it's newish to you. it'll be by far the easiest to google etc


it's what will be presented to you in developer tools too

Ivan Koz23:02:37

i have no problems with java or clojure, but it's a bit confusing how it all works together, atm the hardest part is css\layouts\rendering side of react components and how static\client rendering fits into a whole


and in my experience it's pretty rare to need to generate css. if you do, then might make sense


but probably best to just define explicit css classes and assign the classes to your react components

Ivan Koz23:02:01

how do professionals approach css and layouts in their apps? Just to see if there is a direction to go to.


That's a big question - I would look for general CSS and design resources specific to the kind of work you want to do. In general, I think the biggest changes in the past 10 years have been the rise of preprocessors and the way that React has brought styles into React components with JSX.

Ivan Koz23:02:40

yes i understand it's a big question, i just need a solid direction to where to go

Ivan Koz23:02:48

i think bootstrap and flexbox also right?


Yes, though flexbox is a browser standard (so much nicer to use than what we had 10 years ago), where bootstrap is another framework


A couple of component libraries specific to Reagent (if that's what you're using)

Ivan Koz00:02:28

i plan to go with rum for now, but need to evaluate that decision


Personally, I tend to throw all my CSS directly into my reagent components as I'm figuring things out ( is amazing for this) and move it into classes later (using garden to generate my stylesheets)


Good luck - there's a lot to learn, and I found it particularly challenging to translate from general resources to CLJS when I was getting started.

Ivan Koz00:02:43

i'm ok with java and fp in lisp, that's plays in my favor i guess

Ivan Koz00:02:57

need to learn javascript better tho

Ivan Koz00:02:09

thank you a lot Shaun


No problem, hope things go well!


professionally I haven't worked with css for 7ish years. but that's how it was done then, with classes