java

A Scala “Word of the day” shell script alvin February 5, 2018 - 3:39pm

I have a 19" monitor on the counter between my kitchen and living room, and it’s powered by a Raspberry Pi. I use the Linux Phosphor screen saver to show a scrolling “news and stock ticker” on the display, which I’ve programmed to show news from several different sources (Atom and Rss feeds, along with other news and data sources). An old version of the display looks like this:

My Raspberry Pi news ticker display

Today I added a new “Word of the day” feature to the display, and as with all of the other code, I wrote a Scala shell script to generate the output.

A Scala method to replace a few “bad” characters alvin February 1, 2018 - 9:13am

Here’s a little Scala method I wrote to replace some “bad” characters that won’t print properly on my Radio Pi display:

def replaceBadCharacters(s: String): String = {
    s.replaceAll("“", "\"")
     .replaceAll("”", "\"")
     .replaceAll("‘", "\"")
     .replaceAll("’", "\"")
}

There are other ways to solve this problem, but I threw this together as a quick patch until I can figure out why the Phosphor screen saver on the Raspberry Pi won’t print those characters that I’m replacing.

The keytool password for the Java security cacerts file is ...

In case you ever need to manually a certificate to your ${JAVA_HOME}/jre/lib/security/cacerts file, it turns out the password for that file when using the Java keytool command is changeit.

To add a certificate to that file, you’ll want to use a command like this:

keytool \
    -import \
    -alias "foobar.com" \
    -keystore ${JAVA_HOME}/jre/lib/security/cacerts \
    -file foobar.com.crt

I had to do this today for a Java/Scala script that accesses an HTTPS URL, and the site I’m accessing uses a “Let’s Encrypt” certificate.

How to convert a Java Date to a Long value alvin January 16, 2018 - 7:35pm

If you ever need to convert a Java Date to a Long, just call the getTime method on the Date instance. This Scala example shows the process:

How to create a “spacer” in JavaFX (with a Region) alvin January 10, 2018 - 5:56pm

As a brief note to self, I just created a “spacer” in JavaFX using a Region, as shown in this code:

// a spacer to push the visible elements up a little
val spacer = new Region
spacer.setPrefHeight(40)
VBox.setVgrow(spacer, Priority.ALWAYS)

I originally created the spacer as a Separator, which is the wrong thing (it’s more like an HTML <hr> tag). A JavaFX Region just gives you a blank space, which you can control as needed.

LibGDX error: Your Android SDK path doesn’t contain an SDK alvin December 25, 2017 - 5:59pm

I don’t know much about LibGDX yet, but one thing I’ve learned is that if you get the LibGDX error message, “Your Android SDK path doesn’t contain an SDK,” it’s because the LibGDX setup tool doesn’t work automatically with the Android SDK tools that you download from the Android website, at least not the default tools. (That directory may work after you do some configuration with the sdkmanager, dunno.)

Using Scala with Java Swing classes is pretty seamless alvin December 21, 2017 - 1:47pm

If you ever wanted to use Scala with Java Swing classes (like JFrame, JTextArea, JScrollPane, etc.), the process is pretty seamless. Here’s an example of a simple Scala/Swing application where I show a text area in a JFrame:

A Java graphics utilities class alvin December 21, 2017 - 1:23pm

As a quick note, here’s a little Java graphics utilities class I started putting together today. Mostly I’m just concerned with monitor/display sizes at the moment, especially when a computer system has multiple displays.