Category Archives: Programming

Leiningen passing Invalid Flags to Java Compiler

Just a note about some weirdness in my work process and it’s solution.

A few weeks ago, I started noticing some weirdness in trying to use some tools with Leiningen while developing a program in Clojure. When running tools like kibit, lein would fail with an error from javac about an invalid flag. Initially these flags were for attempts to set the file encoding. And the file encoding kept changing.

Over time, these failures became more frequent. Always about passing an invalid flag to the java compiler. Finally, I was unable to run a REPL, run a program, or build an uberjar.

Long story short, it looks like it was related to the JAVA_CMD environment variable. That had been set a loooong time ago and in fact pointed to the java compiler, not the VM. Simply removing the variable fixed things. Might have worked just by setting it to java rather than javac but I didn’t try it and so far nothing else has broken.

Still don’t know what caused things to get flaky in the first place since this variable was set so long ago.

Keeping the JavaFX UI Responsive

It’s common knowledge that the JavaFX user interface tookit is single-threaded. When your JavaFX-based program is doing things that can take some time, you need to run those tasks on a separate thread(s) to keep the interface responsive.

Recently, I’ve been working on a program that can spend a lot of time reading and writing to the disk, but at the same time I want to retain the ability for the user to change views of the UI as the work proceeds. I also want to provide the opportunity for the user to cancel the background task at any time. I thought I would provide a couple of examples of how I did that in the program.

Continue reading

Clojure/Script has Ruined Me for Other Languages

The Elm language is often cited as an up-and-comer for web front end development. I was attracted to it largely because of the compiler’s friendly and extremely helpful error messages. It’s really attractive in many ways.

But when I started looking at examples, I often found myself thinking things like “Why is this so inconsistent?” or “Why is this syntax so complicated?“. And it finally occurred to me that I’ve been ruined by the way Clojure/ClojureScript/Lisp/Scheme do things. I can’t seem to go back.

Speech Synthesis in ClojureScript

Just like everyone else, it seems, I’ve been following all of the news about voice-activated personal assistants. There are all the commercial offerings like Siri, Alexa, Cortana, and so on, as well as some DIY projects on the web, like this one and this one and this one.

These types of projects typically involve a front end that converts voice to text, some middle piece that interprets the text and obtains some answer or creates an action, ending up with a voice response by the system back to the user. I have some (out-of-date) experience with speech to text, but not the other end of the process: text to speech. So here’s a little investigation into how to do it with ClojureScript. Turns out that it is almost trivial these days.

Continue reading

Hardening an Nginx Server

Besides the site where I host this blog, I have several other sites that I maintain. This is all more of an educational effort for myself than anything really important. That said, I am a neophyte in terms of server security. It’s something I want to do better. What better place to start than by evaluating security settings on some of my “play” sites that use nginx as the server component?

Like I said, I’m no expert, but these are some of the things I have done to my own sites.

Continue reading

ClojureScript with Reagent and figwheel

I have a bit of a love/hate relationship with ClojureScript. On the one hand, it is a Lisp, with all the power it entails. On the other, the development toolchain can be byzantine. With the advent of WebAssembly and ECMAScript6, I have hopes of seeing tail call optimization (allowing true recursion) handled in ClojureScript, if not Clojure itself. And Reagent and figwheel can make web development (not my strong suite) much easier.

Continue reading

River5 on Ubuntu 14.04 LTS with a CloudAtCost VS

River5 is the latest in a series of RSS News Aggretators written by Dave Winer. You can read his announcement here. These notes describe how to set up a River of News on a Virtual Server (VS) purchased or rented from CloudAtCost and freshly imaged with Ubuntu 14.04.

These notes assume that you have done some work in configuring your VS with a user, other than root, that has super user privileges. If you need help doing the initial setup of your VS, look here.

Continue reading

Using Local Java JARS in Clojure Projects

Recently, I’ve been working on a Sudoku game program. Part of the program provides a user with the ability to generate new puzzles of a particular difficulty. Generating a puzzle usually requires two puzzle solvers: one that solves puzzles (slowly) like a human would, the other that solves puzzles (very quickly) like a computer would.

Rather than write my own from scratch, for this part of the development, I wanted to use an existing implementation of the machine-like solver. After a little research (more on this some other time), I found one I liked a lot — the Kudoku solver written in Java from attractive chaos.

But how does one use a local jar file in a Clojure Project? Read on…

Continue reading

Finding Mono-Spaced Fonts in JavaFX

There are many use cases where a mono-spaced (fixed-width) font is useful in programming. Programming editors and creating program listings come to mind. But there doesn’t seem to be a consistent way of obtaining a list of all of the mono-spaced fonts installed in the operating system.

Back in the days of Swing, you usually had to grab a list of font families (e.g. Arial, Times New Roman, etc.) from AWT and then create a BufferedImage to print the font to and check layout widths. In JavaFX, it seems a bit easier. Here’s one way to do it.


* Return a list of all the mono-spaced fonts on the system.
* @return An observable list of all of the mono-spaced fonts on the system.
private ObservableList<String> getMonoFontFamilyNames() {

    // Compare the layout widths of two strings. One string is composed
    // of "thin" characters, the other of "wide" characters. In mono-spaced
    // fonts the widths should be the same.

    final Text thinTxt = new Text("1 l"); // note the space
    final Text thikTxt = new Text("MWX");

    List<String> fontFamilyList = Font.getFamilies();
    List<String> monoFamilyList = new ArrayList<>();

    Font font;

    for (String fontFamilyName : fontFamilyList) {
        font = Font.font(fontFamilyName, FontWeight.NORMAL, FontPosture.REGULAR, 14.0d);
        if (thinTxt.getLayoutBounds().getWidth() == thikTxt.getLayoutBounds().getWidth()) {

    return FXCollections.observableArrayList(monoFamilyList);

It seems a little less complicated in that all of the needed functionality is available right in JavaFX. One thing that hasn’t changed is that it can still be slow. For example, if you want to populate a ComboBox with all of the mono-spaced fonts at the start of program execution, it can add a small but noticeable delay.

In my own case, on Windows, I have about 370 fonts on the system. Twenty-seven of those tested as mono-spaced, including quite a few that I never use, mostly non-English character sets that get installed somehow.

Still, good to know.