This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-06
Channels
- # admin-announcements (10)
- # alda (78)
- # arachne (33)
- # bangalore-clj (2)
- # beginners (11)
- # boot (70)
- # chestnut (8)
- # cljsjs (5)
- # cljsrn (4)
- # clojure (212)
- # clojure-art (1)
- # clojure-berlin (1)
- # clojure-brasil (27)
- # clojure-canada (6)
- # clojure-colombia (12)
- # clojure-dev (6)
- # clojure-greece (29)
- # clojure-hk (2)
- # clojure-italy (7)
- # clojure-russia (51)
- # clojure-spec (12)
- # clojure-uk (18)
- # clojurescript (115)
- # clojurex (8)
- # component (1)
- # crypto (41)
- # css (5)
- # cursive (31)
- # datomic (17)
- # defnpodcast (7)
- # emacs (9)
- # flambo (1)
- # funcool (4)
- # juxt (29)
- # off-topic (1)
- # om (122)
- # onyx (12)
- # pedestal (1)
- # planck (10)
- # portland-or (1)
- # re-frame (30)
- # reagent (4)
- # rum (3)
- # slack-help (2)
- # specter (20)
- # sql (3)
A question to anyone who has good insight in random numbers in javascript. I need a random 32-bit integer. Is there something wrong with the following function:
(defn random-32 []
(Math/round (* (- (Math/pow 2 32) 1) (Math/random))))
from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random "Using Math.round() will give you a non-uniform distribution!"
otherwise you seem to follow the recommended approach, but Math/floor should be more uniform
@dschlyter Great, thanks!
test.check has a random number generator for double
s and long
s https://github.com/clojure/test.check/blob/master/src/main/clojure/clojure/test/check/random.cljs
@vikeri : If you want cryptographic random numbers, you can use Isaac.js. Here's a copy I have where I've added all of the JSDoc annotation to make the Closure compiler happy - https://github.com/Sepia-Officinalis/secp256k1/blob/vendor-sjcl/src/js/secp256k1/math/random/Isaac.js
Chrome/Safari/FireFox all expose crypto.getRandomValues
, which can fill in a UInt32Array
, Int32Array
, or the 8 bit equivalents with secure random values. IE 11 has a similar service msCrypto.getRandomValues
Here's a routine I have that tries these various ways of generating random number and falls back to Isaac.js if they aren't around -
https://github.com/Sepia-Officinalis/secp256k1/blob/vendor-sjcl/src/cljs/secp256k1/math.cljs#L92
@mfikes : As per our conversation in #planck, I think @vikeri is an example of a user who might want crypto.getRandomValues
available 😉
@xcthulhu Great! Btw, could you explain why the method I mentioned would not be considered sufficiently random?
Well, so it sort of depends on how js/Math.random
is implemented. This varies from platform to platform. If it's a linear congruential generator, then you'll see a lot of correlation in the lower order bits. You can see that Chrome's old V8 4.7 used to use such an RNG - https://v8project.blogspot.com/2015/12/theres-mathrandom-and-then-theres.html
If you care deeply about this, you can try the DieHard or DieHarder statistical test suites - http://www.phy.duke.edu/~rgb/General/dieharder.php
from your example above “inline” is not a class, it is form element’s attribute, so you should write something like this: [:form {:inline true} …]
not sure about that true
part, I’m not that familiar with reagent, you might have better luck asking in the #reagent channel
Some sort of UUID, so it’s not sensitive from a security perspective. But I’m still interested in the subject, since I’ll do more security sensitive things further ahead.
The library I linked is my attempt to wrap all of the JavaScript cryptostuff and provide fallbacks and polyfills when it's not around.
Anyway, clojurescript has a random-uuid
built-in - https://github.com/clojure/clojurescript/blob/709cc57d003590945329ea8745b799e75ac4ba88/src/main/cljs/cljs/core.cljs#L10238
Alright, will use that for now then. And migrate to your library in the future when I need more security sensitive values.
If you are doing digital signatures, it's best to just use RFC 6979 anyway, although the performance is horrible on Nitro and Nashorn.
Alright, it’ll be an interesting venture. There should be a #security channel for these matters...
@mfikes : I'm seeing that the latest figwheel won't build andare: Could not Analyze target/out/cljs/core/async.cljs ----> No such var: ioc/state-machine
@pat Ahh, plz log a ticket. (It could be the case that Andare is not working properly with non-self-hosted ClojureScript.) (In any case, I’d suggest only using it with things like Planck and use the official core.async
with JVM ClojureScript, if you can.)
@mfikes yes I'm trying to use fw to dev some bootstrap friendly libs. it was working fine until recently
@pat there’s a bug in the latest ClojureScript release that just got fixed, probably the same thing
@pat huh, ok - in anycase I just cut ClojureScript 1.9.229 with the js-dependency-index fix
@pat fwiw I had similar looking issues with CLJS+Figwheel until @anmonteiro’s patch and they are gone for me now
@pseud I don’t directly, but my coworkers do. Whats the issue? I haven’t seen any differences with editor specific setup (they do what I do, and I use emacs).
Well it's just that I'm unable to figure out what conjuring is required to the damned thing to play ball with a lein project which uses checkout dependencies (meaning the classical approach of running a script/repl.clj to load figwheel via sidecar seems out of the question)
One thing I would do is make sure you add your checkouts to src paths. For instance :source-paths [“checkouts/my-lib/src”]
for clj and cljs builds. Also core namespace can be fiddly if you are calling set-refresh-dirs
In fact. I think I'd be willing to drop some 200USD on some tool that could just work (tm) with regular lein projects. I really can't understand why the tooling is always this poor. Seems to me that lein has done a great job at abstracting all the insanity, how come then that all tools (cursive, cider) reintroduce all the problems ? What am I missing here?
Oh the cljsbuild stuff is easy enough, if I run "lein figwheel" from a terminal everything is peachy. checkout dependencies work, reloading works, everything works (tm).
and how do you actually get going then ? I'm dropping figwheel, nrepl, piggieback, sidecar and god knows what into every project.clj I need to work with and I need to use a script like https://github.com/bhauman/lein-figwheel/wiki/Running-figwheel-in-a-Cursive-Clojure-REPL to get going - but once I do, I'm running a regular jvm process, not lein - and that means I'm hosed as far as checkout dependencies go
No, checkouts doesn’t care where the repl comes from. My coworkers don’t use lein repl.
The link above specifically mentions that it breaks checkouts. I haven't been able to run a say.. "lein figwheel" session from within cursive - I have to run a regular jvm process, load a script file as the guide indicates and that then triggers figwheel.
Well, the problem, I guess, is that I'm just trying to write some code and I have (after some struggling) figured out how to make lein behave - but apparently it's a whole new thing getting cursive to work with these things. Seems like (from the run configurations dialog) that cursive wants an nrepl session - and I'm guessing that's where the misery starts
Yeah, the cursive part I am not as up to date on. But I use figwheel, and haven’t had a problem with checkouts
lein, figwheel - all the cli tools are perfect, once you finally get them configured - it's just cursive, which I'm trying out after repeated issues with cider... x_x
There is, almost nothing but. It's lein support is abysmal. You can't even run a task. if you select lein, all you can do is specify the profile(s) to run...
yeah, I just got cider figured out, and haven’t spent a whole lot of time with cursive
I think I'll just grab a break. This is infuriating me and I don't think I'll get anything constructive done - as evident by my whining. But man, the IDE <-> clojure interplay is stoneage compared to Racket...
@pseud I use boot so I don't know how to solve your issue with lein. Have you checked out the Leiningen tab? If you go to Leiningen projects > your project name > Tasks you can select a task and run it.
I have - the lein tab is really just a prepopulated list of standard lein tasks - meaning if you install any plugin like cljsbuild or figwheel they won't show up there (nor will things like 'repl'). 😞
Plug for boot.. boot's checkouts work nicely with Cursive (really you just run in the command line). You add :checkouts
to your environment and boot will automatically pick up changes from all projects added. Not sure why extra tooling is needed for this to work in lein.
Well I'm forced to work with my colleagues so as nice as boot might be, it's not an option. Also, I'd expect a tool which someone actually wants to charge money for could help to make popular use-cases work, at least provide some damned documentation if automation is out of the picture. But oh well.
All I do is run my boot task in the command line (e.g. boot web-dev
) and it just works. You can't do this with lein?
You can also add that command to IntelliJ's external tools so all you have to do is go to Tools > External tools > boot web-dev and click and it auto runs that command.
You could also run figwheel from the command line and connect to the remote nrepl port from Cursive. I've used it quite a bit and it works well.
Not that I know of. But it seems that I can either bombard each lein project with third-party deps and special clj files to auto-run such that booting a nrepl (lein repl) session and then starting figwheel might work - that way I can connect via cursive to the remote nrepl (at least Cursive can't ruin that). Its just.. not elegant. So I'm looking into whether I can move all dependencies to ~/.lein/profile.clj but then I'm back to not having any easy-to-run function to start figwheel and dump me in a cljs-repl...
shaun-mahood: yea, exactly my thought 😛 Have you somehow abstracted away all the dependencies, auto-start scripts and whatnot such that you're not including a modified user.clj/repl.clj (whatever you call it) and a bunch of dev-time deps for each project ?
@pseud I think you could use lein run
to run your own clj with classpath populated from project.clj setting, that would be analogous to running your standalone scripts/repl.clj
@pseud there’s also a #cursive channel, I’m sure people have run into this before. FWIW, I don’t bother with Lein here, a REPL launched via the clojure.main
option works just fine
If anyone know how to achieve something like this: https://gist.github.com/jwdevantier/ae6ffe64e212cae2556974c087a5d48a then I'd be golden
I would create a separate lein profile myprofile
with all deps/setup needed for that, then do lein with-profile +myprofile run -m myproject.mynamespace
and there define -main
function which would call (figwheel)
OK, interesting, I guess that's a good approach, better than what I had considered, even
as an inspiration for you, this is pretty fresh code I still have in my head:
https://github.com/binaryage/cljs-oops/blob/master/scripts/run-circus-tests.sh#L14
https://github.com/binaryage/cljs-oops/blob/master/project.clj#L33-L36
https://github.com/binaryage/cljs-oops/blob/master/test/src/circus/oops/circus.clj#L219
once you get -main
launched you should have checkout dependencies on your classpath and from there you can call figwheel (or do whatever)
@darwin Ooo. That lib looks useful. I have also ran into the problem with externs being slightly out of date causing exceptions in prod. Any ETA docs?
@kenny I’m sorry, won’t promise anything at this point 🙂 first I want to convert all my libraries/projects to use it, to battle test it, then I will maybe spend some time on the docs
is there a way to get a cljs repl from within clojure w/o using figwheel ? I have some library projects too where I really just want a repl of some sort and right now I seem to have some troubles with figwheel in those projects. Can I just get a cljs repl to use for evaluating forms and the like ?
Yea, writing a custom .lein/profile.clj with an accompanying .lein/figboot.clj which I ensured got loaded (via :repl-options) didn't work either, when it finally boots the checkout dependencies aren't observed so any changes in the parent project are not reflected until I restart the repl... Not surprisingly, it's the same if I start a repl by letting cursive start a regular java process and load some file which spawns a figwheel repl. 5 hours of no progress... 😞
Is there a nice way of loading in a JSON data file to clojurescript on load? Basically I have a bunch of data I want to search over, but I don't want it to have to make an API call, and I don't want a long loading time on the user's end.
if you have a lot of JSON data, perhaps https://stedolan.github.io/jq/ would be the right tool 😃
@slester not sure if that's what you're asking but you could inline the JSON or an edn representation of it using a macro
you could also just put it into the HTML file that loads your application
@martinklepsch sounds more helpful! in what format should I do that, though? just load the json into a variable, then use js/varname
within the clojurescript? is there an order I need to do it in?
if you put it into the html you'd define a global that you access via js/varname
, yes
you can just put the JSON into a <script>
tag, not sure what other format you're asking about?
As for order it would make sense to put the JSON first if your app isn't useful without it. You can probably do it either way depending on your application code.
@martinklepsch I just wanted to read it in from a file instead of plopping it directly into the HTML
@slester you could generate the HTML, inlining the JSON? all that said simplest is very likely just loading it via an ajax call
@slester You could parse the json from another cljs file. In the end the user has to download the data one way or another into his memory. Or just parse the json to edn map during development if the data is static.
@hlolli hmm, interesting; could I read it into a variable from a static file on compilation?
@slester using a macro, yes
you could have an immutable map and to (get map :key) or (:key map), just like you had any other clojure map.
@martinklepsch maybe this belongs in #beginners but could you point me in the right direction on how to import it via macro?
https://github.com/clojure/data.json there are some json->edn parsers here.