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

When you use sbt to build Scala projects — at least with version 1.4.4 in November, 2020 — if you use commands like doc, package, packageDoc, and probably assembly, sbt doesn’t show the directory where your output JAR files are written.

SBT: How to show file output locations

I don’t know why it doesn’t show those output locations — maybe people who use sbt all the time don’t want to see those things, such as if they have sbt doc or sbt package commands in a shell script — but if you want to see the directory and name of the files that sbt creates, use the show command before other commands like doc and package, like this:

This page contains a collection of over 100 Scala String examples, including string functions, format specifiers, and more. I don’t provide too many details about how things work in these examples, although I do show the output of all the examples. This is mostly just a collection of examples that can be used as a Scala String reference page or cheat sheet.

If someday the Moon calls you by your name don’t be surprised, because every night I tell her about you.

~ Shahrazad al-Khalij

As I wrote about in this Facebook post, two nights ago I dreamed about a man dying and gently singing a song as he was dying, which led me to listen to The Impossible Dream, from Man of La Mancha, by Brian Stokes Mitchell. Here’s another terrific performance of that same song, as he sings with an orchestra and choir.

As a brief note, if you need to use a varargs parameter with a Scala method, and those varargs parameters should be added to an ArrayBuffer, I can confirm that this code works with Scala 2.13:

import scala.collection.mutable.ArrayBuffer
val xs = ArrayBuffer[String]()

// add one element to the ArrayBuffer
xs += "a"   // ArrayBuffer(a)

// now create a method with a varargs parameter
def appendStrings(strings: ArrayBuffer[String], varargsStrings: String*): Unit = 
    xs.appendAll(varargsStrings)

// now add multiple varargs parameters to the ArrayBuffer
appendStrings(xs, "b", "c")
xs   // ArrayBuffer(a, b, c)

I just confirmed that this code works with Scala 2.13 and Scala 3.0.0

A friend’s young child has been having some serious health problems recently, which led me to this song titled, I Won’t Let Go, by Rascal Flatts:

I will stand by you
I will help you through
When you’ve done all you can do
If you can’t cope
I will dry your eyes
I will fight your fight
I will hold you tight
And I won’t let go

I had forgotten about Rascal Flatts. The last time I thought about them was probably 2010 or earlier. I was sitting at the bar area of a Tumbleweed restaurant in Louisville, Kentucky, and the bartender was trying to tell me how good they were.

This photo from January 12, 2012 of the Rocky Mountains behind Boulder, Colorado made me feel like I was living on the Moon.

Rocky Mountains behind Boulder, Colorado

What the sky will look like when people travel back and forth to the Moon. :)

Traveling to the Moon

[In a Season 1 episode of Fringe, Olivia has been thinking that she’s losing her mind because she’s having dreams where she sees people being murdered, and when she later wakes up and goes to her job as an FBI agent, she finds that they have been murdered. But now they’ve found a potential suspect named Nick Lane, which leads to Olivia and Peter sitting in the lobby of a mental hospital, waiting to meet a doctor there.]

PETER: You know, until this year I’d never actually been to a mental hospital.

OLIVIA: [Bent over, her head in her hands, looking at the floor] Learn to like new things.

PETER: Maybe I never gave it enough thought ... what Walter went through. I only ever saw it through my own perspective. His being crazy was something that he did to us. To my mother and me. It wasn’t something that happened to him.

OLIVIA: Well, you were young.

PETER: Well I’m not young any more. [long pause, looking off into the distance] It must be a terrible thing to not be able to trust your own mind. [sighs]

OLIVIA: Yeah ... [rubs her hands together, then puts her head in her hands again]

After a brief Gitter discussion that starts here and ends here, I decided to take a little time to see:

  • What it would take to show Scala documentation in the REPL, and
  • Different ways of viewing that documentation

A long time ago, in a place far, far away when I first learned about design patterns in computer programming, I learned that they were based off of this original book by Christopher Alexander, which documents and explains concepts about design in architecture.

One thing that stood out to me in that original book was the following discussion about having views of beautiful scenery. I don’t necessarily agree with it, but I’ve never forgotten it. I found this text on this website, and I’ll leave it here for you as well:

This is the essence of the problem with any view. It is a beautiful thing. One wants to enjoy it and drink it in every day. But the more open it is, the more obvious, the more it shouts, the sooner it will fade. Gradually it will become part of the building, like the wallpaper; and the intensity of its beautify will no longer be accessible to the people who live there.

Therefore:

If there is a beautiful view, don't spoil it by building huge windows that gape incessantly at it. Instead, put the windows which look onto the view at places of transition — along paths, in hallways, in entry ways, on stairs, between rooms.

If the view window is correctly placed, people will see a glimpse of the distant view as they come up to the window or pass it; but the view is never visible from the places where people stay.

As a brief note about catching the [ctrl][c]/ctrl-c signal in a Scala command-line application, I just used this approach on Mac (Unix) system, and was able to catch the ctrl-c signal:

/**
  * The ability to cancel this code with `ctrl-c` inside of 
  * sbt requires you to have this setting in build.sbt:
  * 
  *     fork in run := true
  */
object SlowSocketServer extends App {
    val serverResponseDelayTimeMs = 0
    val serverPort = 5150

    Runtime.getRuntime().addShutdownHook(new Thread {
        override def run = {
            System.out.println("Shutdown hook ran")
            // if (socket != null) socket.close()
            Thread.sleep(1000)
        }
    })
    
    // more code here ...

I was running this application with sbt, and as long as I used that fork setting in the build.sbt file, the ctrl-c keystroke killed my application without also killing sbt, which is what I wanted. This method also printed out the "Shutdown hook ran" string before it died, as desired.

As a quick note, if you need to paste multiple lines of input at one time to the Ammonite REPL, paste your code inside a block. This is particularly helpful when you need to paste something like a companion class and companion object into the Ammonite REPL:

@ {
    // your code starts
    class Foo {
        // code here ...
    }
    object Foo {
        // code here ...
    }
    // your code ends
}

As shown, just include your code inside the opening and closing curly braces.

Back on November 11, 2015, we had our first snowfall, and I took this photo of my neighbor’s horses.

Horses and snow, November 11, 2015

I didn’t know that Longmont, Colorado had a newspaper, but it looks like there is one called Times-Call.

A few days ago I was driving back from the hospital and took a series of photos of the Moon over the Rocky Mountains from this rural area of Erie and Longmont, Colorado. This is the first photo.

The Moon, Rocky Mountains, and Colorado (Photo 1)

One on one to talk to you
Like film stars they get close to you

You’ve mirrored his appeal

He wants you so
He wants to be beside you

Then you pass by
Giving him the other side of you
Like the mystics do
So that every time he moves
He moves for you

Soul light can always see
The meeting of true love and she
This silent night and I
I guess a lonely mind might see
I’ve seen love on the screen
I’ve seen a screen goddess and me
Oh ...

How often this
How often this power of you

And so
I must confess
Whatever I see
I’m meant to be there with you
With you

I heard portions of this song while watching a Fringe episode last night, and thought it sounded really beautiful. From The Friends of Mr. Cairo, by Jon & Vangelis.

So a cat in the state of Washington walks into a shipping container ..... then 2,500 miles and a week later, it shows up at a Home Depot in Kenai, Alaska. And thanks to social media, the owners were found and the cat got a free flight home.

The story is here at adn.com.