{ "feed": { "id": "urn:uuid:2e8662fc-461f-58a7-9159-c22ca4880eb0", "link": [ { "@attributes": { "href": "http://darrennewton.com/atom.json", "rel": "self" } }, { "@attributes": { "href": "http://darrennewton.com/" } } ], "title" : "Miscellanea", "subtitle" : "Code, design & cultural ephemera from Darren Newton's brain", "updated" : "2016-12-21T15:18:25-05:00", "author": { "name": "Darren Newton" }, "rights" : "Copyright (c) 2016, Darren Newton", "entry": { "id" : "urn:uuid:6e914559-e3ec-566e-82d6-f409c6fca05f", "link" : "http://darrennewton.com/2016/12/17/identicons-with-clojurescript/", "summary" : "
\n\nA while back I put together a little graphics package written in Racket for generating identicons. This summer someone at work stumbled across it and asked if I could generate some of those identicons in the browser. I decided to give it a shot and whipped up a small subset of the original package in ClojureScript: identikon-cljs ", "content" : "
\n\nA while back I put together a little graphics package written in Racket for generating identicons. This summer someone at work stumbled across it and asked if I could generate some of those identicons in the browser. I decided to give it a shot and whipped up a small subset of the original package in ClojureScript: identikon-cljs
\n\nYou can see the compiled JavaScript in action at https://pool-chatter.gomix.me/
\n\n\n\nTo get an interactive development environment run:
\n\n:::bash\nlein figwheel\n
\n\nand open your browser at localhost:3449.\nThis will auto compile and send all changes to the browser without the\nneed to reload. After the compilation process is complete, you will\nget a Browser Connected REPL. An easy way to try it is:
\n\n:::clojure\n(require '[identikon-cljs.core :as identikon] :reload)\n(identikon/make-identikon \"#idk0\" 200 200 \"identikon\")\n
\n\nand you should see an identikon appear in the browser window:
\n\n\n\nFrom JavaScript you can import /resources/public/js/compiled/identikon_cljs.js
and then use it like so:
:::javascript\nidentikon_cljs.core.make_identikon(\"#idk0\", 300, 300, \"identikon\");\nidentikon_cljs.core.make_identikon(\"p.idkp\", 60, 60, \"small identikons\");\n
\n\nSince the original package was written in Racket it made a lot of sense to use a Lisp for the browser version as well. The only real player in this space at the moment is ClojureScript, which I\u2019ve used before on other projects. The downside to ClojureScript is it brings along a largish compiled runtime and I wanted to keep this as small as I could. The Google Closure compiler does a great job with dead code elimination, but the runtime still incurs a hit, so I decided to do away with SVG rendering libs and generate elements on my own using Hiccups. I also needed to generate SHA-1 hashes of input strings, so I leaned on cljs-hash. Finally I needed to manipulate HSB and Hex colors so I included the excellent color library.
\n\nAll in all it was fun to port Racket over to ClojureScript and also re-think a few things in the process.
\n", "title" : "Identicons with ClojureScript", "updated" : "2016-12-17T14:56:00+00:00" } } }