clojurescript

moving injected styles to a static .css file

Intro prelim: this is a following my css-in-cljs method from my garden css has ascended, which was exceptionally good for the first draft/version of the project but eventually should cede to normal CSS once you are ready for hardening the product. The goal here is to remove all the per-html CSS rules that were so perfect for Dev with a single CSS file that can be called from all the html files in the project and is both far more efficient file-size wise, and the Right Wayâ„¢ to do it for caching and synchronization.

Clojure Libraries in ODH

Intro The following is a copy of a blog post for our organization, originally posted at https://odh.byu.edu/blog/clojure-libraries-in-odh My work with The Office of Digital Humanities is as a senior web developer. My teams and I build applications in the Clojure programming language1 to serve the college of Humanities and the Office of Digital Humanities, and utility libraries that serve the university and the broader developer community. Here are a few of our heavily used utility libraries, which have been used internally for years.

How to iterate through all alphabet letters in ClojureScript?

Problem: JavaScript doesn’t have “chars” EDIT [2022-07-19 Tue] no-interop solution from In languages with an integer-based Char datatype, such as C and Java and probably by inheritance JVM Clojure, you could iterate through characters by the equivalent of (+ \A 1). JS doesn’t have chars though; only strings. Is there a nice way out-of-the-box to iterate through the characters of the alphabet, perhaps just in one case? I mean, obviously we could create a collection that contains all the letters we want, but is that already done somewhere?

installing NPM and shadow-cljs on guix

Intro Installing things on guix is usually more involved that just using the one-liners you may have been given with other things in mind. Getting NPM in Guix Install the latest node to get the npm command. guix install node

Uploading Files and Handling Upload Requests in Clojure[script]

What’s the secret? I have used ajax uploads and interactions in Clojure forever; it’s a bread-and-butter skill to use AJAX and JSON1. However, my WordPress usage led me to believe it would be equally trivial to handle file uploads. It turned out to be less trivial than I expected, though. In summary, the secrets I needed were: Make sure the encType on the client is "multipart/form-data", which happens differently with AJAX than with plain HTML

get selected value of a select box in Clojure

option onclick Event not Supported With a recent bug I was reminded that <option /> are not allowed to have onClick events by Google Chrome. This led to some annoying debugging as to why something was working in Firefox but not Chrome on one of our applications. Fortunately, Clojure ships with Google Closure, which provides a straight-forward way of obtaining the selected index, and then getting that from the options of the sel.

Clojurescript Reagent Image-Previewing Selector

Intro It took some elbow-grease but I was able to convert online examples1 into a working image selector in Reagent Clojurescript. It isn’t a lot of code, but there were two complications: converting the declarative style of the examples into more functional CLJS (hint: it involves closures), and doing it in a way that will jive with the React life-cycle. CSS code The following styling makes things look okay. This is using Garden2 syntax.

Capturing key-presses in Clojurescript with Closure

Having good keybindings on your site makes a world of difference for technical users (Twitter and Slack are good examples of this), but writing them yourself has several annoying steps. You have everything you need out of the box with Google Closure, though. Here’s how it goes withotu needing to add any dependencies to your project, since Closure is part of Clojurescript. Strategy and Solution The plan is simple:

zero-padding and truncating with string formats in Clojurescript

One of the discrepancies between Clojure and Clojurescript is that the javascript version doesn’t have anything like the classic Unix/C-style string format functions. Some functionality is not simply reproducible with clever uses of str, but fortunately Google Closure is here to save the day. Because Closure is part of Clojurescript, there are no added project dependencies to make this work. (ns myapp.services (:require [goog.string :as gstring] [goog.string.format])) (str "$" (gstring/format "%.

Creating ToryAnderson.com with ShadowCLJS

After years of a languishing example of The Cobbler’s Children , I finally got around to renovating my own website: toryanderson.com. Admittedly I have a lot to learn about visual design, but I had a good time on the technical front. I took the opportunity to use technologies I love and have been pleased with the result – both in the product and the cost constraints. In other words, it was fun to build and cheap to host: Clojure[script] meets shared hosting.