Scala, Java, Unix, MacOS tutorials (page 1)

Today (April 8, 2020) is a day off for me, so I woke up at 4:30am and went up on the roof of the apartment complex garage, and took a few photos of the Pink Moon. These are some small versions of the best Moon photos, along with one of the Sun, which was coming up behind me from the east as the Moon set in the west over the Rocky Mountains.

First, the “Pink Moon” setting over the Rockies:

Pink Moon setting over the Rocky Mountains

Today (April 8, 2020) is a day off for me, but I woke up early and went up to the roof of the garage to see the big Moon. This is a photo of the Moon setting in the west, and the Sun rising in the east, within about fifteen minutes of each other.

Moon setting in the west, Sun rising in the east

I missed the news about Bill Withers passing away. A lot of times when I’m putting around I sing “Ain’t No Sunshine.” That and “Use Me” are probably in my Top-50 favorite songs of all time.

It was interesting to read that he was a 31-year-old factory worker making bathrooms for 747s when he wrote Ain’t No Sunshine.

He also intended to replace all of the “I know” lyrics with a third verse, but other musicians told him to leave it as it was. “I was this factory worker puttering around,” Withers said. “So when they said to leave it like that, I left it.”

RIP, Bill Withers

I’ll confess this
You’re my tragedy
I paid you to rest
Just as fast as you turned on me
Gone forever
Vanish the memories
This face of pleasure
Is masked by your misery

Straight out of line
I can’t find a reason
Why I should justify my ways
Straight out of line
I don’t need a reason
You don’t need to lie to me
Lie to me

~ some Straight Out of Line lyrics, by Godsmack

As a brief note, you need this setting in your build.sbt file if you want JavaFX client/GUI applications to properly stop in SBT:

// see:
fork in run := true

Conversely, if you don’t use that setting and then you stop your JavaFX app that you started inside SBT, the app won’t stop properly and it will leave a Java process running, and at that point about all you can do is kill SBT and restart it, which gets annoying after a very short while. That setting causes SBT to create and run the JavaFX app in a new JVM. As noted in the code, I found that setting on SO.

The Moon at 5:15 this morning, Monday, April 6, 2020. :)

The Moon at 5:15 this morning (April 6, 2020)

As a brief note today, I started to create a little Scala/JavaFX WebSocket client based on the Java-WebSocket project. I initially created it to test my Play Framework WebSocket example. I had hoped to be able to easily get to the server response request headers, but atm I don’t see a way to do that.

That being said, this is what the Scala/JavaFX WebSocket client currently looks like:

A Scala/JavaFX WebSocket client

And here’s its source code:

In this article I show how to write a WebSocket server using the Play Framework and Scala. My goal is to create the simplest possible WebSocket server so you can see how the basics work.

To demonstrate the WebSocket server I also created an HTML/JavaScript client. It isn’t quite as simple as the server, but I decided to keep some extra code in the client in case you have problems and need some debugging help.

I’m not a big fan of how Bill Gates made his money, but I applaud his call for a nationwide shutdown of the United States to deal with the coronavirus.

As I’ve written before, the President of the United States needs to order a nationwide shutdown. Anything else is just going to prolong how long and how hard we have to deal with the coronavirus, and how many deaths there will be. As I posted before, dealing with this on a state-by-state basis is like having a “peeing section” in a swimming pool. We are, after all, “One Nation Under God.”

You can read more of Mr. Gates’ comments at this Business Insider short story, which has a link to his paywall-blocked op-ed on the Washington Post.

Bill Gates says the U.S. needs a nationwide coronavirus shutdown

As a brief note to self, I currently have a situation where I have about ten shell scripts, and each script uses the same jar file, but I keep changing the version number of that jar file each time I have a new release of my Static Drupal application. For example, my current jar file has this name:


So to keep all of those shell scripts using the correct, current version of my jar file, I created a file named VERSION that has this version variable:


Then in my other shell script files, the first thing I do is “source” that file to get the version variable into those other shell scripts. One of the first lines in my ten shell scripts looks like this:


By doing this, I now only have to change the version number in that first file, and it’s automatically picked up in all of my other shell scripts.

After my previous post about electing people who don’t believe in science, I came across this post about having a “peeing section” in a swimming pool that sums up my feelings about not having a nationwide lockdown.

We are, after all, “One nation under God.”

Not having a nationwide lockdown, and a “peeing section” in a swimming pool

I don’t even know who the My Pillow guy is, but when I saw this image I thought, the United States picked a horrible time to elect people who don’t believe in science.

That the entire nation isn’t under lockdown at the same time is one of the dumbest things I can imagine at a time like this. Not locking everyone down means the coronavirus is going to go on longer, and more people will get sick and die.

The U.S. picked a horrible time to elect people who don’t believe in science

I never met Carl Quinn in person, but I knew of his work. I just read that he passed away from the Coronavirus/Covid-19.

Carl Quinn, software developer, passes away from the Coronavirus

The following is a definition of equanimity, and how equanimity differs from indifference or apathy. The entire quote comes from Shinzen Young:

“Many people get confused about what equanimity is and what it isn’t. Here are some examples that may help clarify.

Equanimity can be deepened by relaxing tension around pain, such as the pain of a broken leg. But equanimity does not mean that you don’t care about getting proper medical attention, such as getting a cast.

Equanimity means opening up to angry sensations that may arise during an argument. But equanimity does not mean that you should stay in a bad relationship.

Ugh, afternoon naps are the worst. I was feeling pretty out of it today, so I decided to lay down, and quickly fell asleep.

When I wake up I hear some children playing outside. I listen to them talk and laugh for a little while, and a thought comes to me that there are more children living here than there used to be. But I like hearing their voices; I'm glad it’s sunny out, and that they’re happy and playing.

The nap seems to be over, so I try to get out of bed — but I can’t move anything. Something is wrong. Very wrong. I’m groggy, and feel extremely heavy. My left arm won’t move. I panic. A woman comes over and I ask her to help me, reaching up weakly with my right arm. I black out or fall back to sleep.

I wake up again, but as I try to move I realize I still can’t move much. My head moves, maybe my right arm, too. Have I been drugged? Am I paralyzed? This time I’m determined to get up, and then manage to fall out of bed and onto the floor. I lay there, face down, with my left arm pinned under my body. I really can’t move ... what’s going on?

Here’s another view of that bright star that’s due west over the Rocky Mountains, as seen from my tiny apartment in Broomfield, Colorado.

The west star over the Rocky Mountains

A great thing about living in this area of Colorado is that there’s a bright star that shines due west over the Rocky Mountains. Every night I open up the shades so I can see it. The only thing that’s on my bucket list is to spend as much time as possible in the mountains to see all of stars up close.

The star is the white dot in the center and bottom one-third of the image, above the roof. It looks more impressive in person. The big white blob in the upper-left is the Moon.

The bright star due west over the Rocky Mountains

“I wish it need not have happened in my time,” said Frodo.

“So do I,” said Gandalf, “and so do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given us.”

“To be a programmer is to develop a carefully managed relationship with error. There’s no getting around it. You either make your accommodations with failure, or the work will become intolerable.”

~ Ellen Ullman (via this tweet)

This quote makes me think of all those years of exception-handling with Java. I never knew there was a better way to handle errors, so I developed a strategy of letting my exceptions bubble up to the controller level (as in model/view/controller), where I would deal with them. These days I know I can use Option/Some/None in Scala, as well as Try/Success/Failure.

I was writing some Scala code like this today:

val sb = new StringBuilder
for (b: Byte <- mdOut.digest) {
    val hexString: String = String.format("%02x", b)

and encountered this error message: