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

I’ve been stuffing receipts and junk into a compartment in my car for years, and cleaned it out yesterday. This card is by far the best thing I found in there (find Haines, AK on a map, and you might know why). As I’m shredding things, I just saw that on this day two years ago I was in Virginia Beach.

A motel in Haines, Alaska

The book, Advanced Scala with Cats, has a nice little function you can use to run a block of code “slowly”:

def slowly[A](body: => A) = try body finally Thread.sleep(100)

I’d never seen a try/finally block written like that (without a catch clause), so it was something new for the brain.

In the book they run a factorial method slowly, like this:

slowly(factorial(n - 1).map(_ * n))

FWIW, you can modify slowly to pass in the length of time to sleep, like this:

def slowly[A](body: => A, sleepTime: Long) = try body finally Thread.sleep(sleepTime)

As a brief tip, here’s an example of how to capitalize every word in a string in Scala:

"foo bar baz".split(" ").map(_.capitalize).mkString(" ")

The output of that expression is:

Foo Bar Baz

Also, instead of using the underscore character inside of map, you can write that anonymous function like this, if you prefer:

"foo bar baz".split(" ").map(s => s.capitalize).mkString(" ")

If you wanted to see how to capitalize every word in a Scala string, I hope that’s helpful. Also, if the map method doesn’t make any sense to you, check out my How to write a 'map' function in Scala lesson.

JavaFX TextArea FAQ: How do I insert a string/text into a TextArea at the cursor/caret position?

Solution: First get the position of the cursor/caret in the TextArea, then insert your new text at that position:

int caretPosition = notesTextArea.getCaretPosition;
notesTextArea.insertText(caretPosition, "My new text");

JavaFX tip: To set the minimum width of a dialog, such as a TextInputDialog, use the setMinWidth method on the dialog’s dialog pane, like this:

val d = new TextInputDialog("")
d.setTitle("Open URL")
d.setHeaderText("Open a URL")
d.getDialogPane.setMinWidth(500)  <-- solution

As a brief note, here are a few examples of how I add some keystroke handlers/listeners to a JavaFX project written in Scala:

// add keystroke listeners/handlers to the scene
def addKeystrokeHandlers(scene: Scene, stage: Stage, theMainPane: MainSplitPane): Unit = {
    configureCommandMHandler(scene, stage)
    // other code was here ...

// Minimize (needed to implement manually)
private def configureCommandMHandler(scene: Scene, mainStage: Stage): Unit = {
    val keyComboCommandM: KeyCombination = new KeyCodeCombination(
    scene.addEventHandler(KeyEvent.KEY_RELEASED, (event: KeyEvent) => {
        if (keyComboCommandM.`match`(event)) {

[This is a chapter from a currently-unpublished book I’m writing on meditation and mindfulness.]

As a spiritual being, one possible way to think of life here on Earth is as a “game” that serves as a training ground for the soul. It’s a game like other games, so it has many levels, and they get harder and harder as you progress. So in this case, the better you become at the game of spirituality — the Soul Game — the harder the levels become.

I wasn’t able to take any pictures of them, but last week we had some beautiful full Moon sunsets over the Rocky Mountains. Then I just came across this photo of the Moon and some mountains, with this “true emptiness” quote by Zen Master Seung Sahn. (The image comes from this link.)

True emptiness is before thinking

My phone says I have 18 songs by the Cranberries and Dolores O’Riordan. Some of the favorites are Zombie, Linger, Dreams, Electric Blue, and War Child. RIP, Ms. O’Riordan.

In Jason Quinn’s Inka Speech he describes “original nature” very clearly. When you find the mind before thinking, you find Zen.

For more information, see Zen Master Seung Sahn’s books. I highly recommend Dropping Ashes on the Buddha, and Only Don’t Know. They are both as clear as any Zen books you will ever read.

Original nature, simply stated

My book, Functional Programming, Simplified — 4.5-star rated on Amazon — is currently on sale in three formats:

PDF Format
Just $15 on
(December sale!)

PDF version of Functional Programming, Simplified

Paperback Book
$39.99 on Amazon

Print version of Functional Programming, Simplified

Kindle eBook
$14.99 on Amazon

Kindle version of Functional Programming, Simplified

In meditation practice you come to a point where you have to “let go.” It’s easy for me to do this at night, I’m usually tired and there isn’t any resistance, but it’s 1,000 times harder during the day. I’ve done it a few times for brief periods and the experience is really remarkable, but I haven’t been able to sustain it yet. No telling what happens when I can sustain it.

In other blog posts I've mentioned that I think meditation can be a great tool for improving your concentration, so I thought I'd take a few moments here to explain how to meditate. It comes very naturally to me these days, but if you've never meditated before you may not know how to get started, so I thought I'd share this very simple technique here.

How to meditate

This is the very simple technique I learned when I first started meditating. Even in Zen schools, meditation is very simple. The secret is in the daily practice, the repetition that builds the new neural connections in your brain.

A quote from one of my favorite Zen Masters, Shunryu Suzuki: “(In meditation) Leave your front door and your back door open. Let your thoughts come and go. Just don’t serve them tea.” Image from this Tumblr page.

Shunryu Suzuki: Keep your doors open

I first posted this definition of the word “Namaste” in January 2015. As I think about some friends, I’m reminded of it today:

I honor the place in you
Where the entire universe resides.
I honor the place in you
Of love, of light, of truth, of peace.

I honor the place in you
Where if you are in that place in you and
I am in that place in me,
There is only one of us.

That namaste definition comes from the excellent book, Polishing the Mirror, by Ram Dass.

Namaste. :)

“Low self-esteem is the root cause of practically all the pain and misery in the world. It’s what drives war, and torture, and genocide. It’s what evil is. Do you think Hitler liked himself? Or Cortez? We hate others because we hate ourselves.”

~ Leonard, on Northern Exposure

“I would say I outdid myself, but I’m always this good. So I simply did myself.”

~ Tahani

Still on my bucket list, thanks to meeting a native American shaman several years ago: See the wild horses of the Sand Wash Basin. (Thanks to the AAA magazine for this reminder.)

The wild horses of the Sand Wash Basin

The prettiest song I’ve heard in quite a while: Love at the Five & Dime, by Nanci Griffith.

(I thought maybe I knew this song from the 1970s, but it wasn’t released until 1986, so maybe it was a Texas thing.)

And you know the sun’s settin’ fast
And just like they say nothing good ever lasts
Well, go on now and kiss it goodbye but hold on to your lover
’Cause your heart’s bound to die
Go on now and say goodbye to our town, to our town
Can’t you see the sun’s settin’ down on our town, on our town