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

I don’t know why they don’t work, but last night for about the 100th or 1,000th time I was reminded that light switches don’t work in dreams.

We were hoping to see the northern lights here last night, so I was intentionally sleeping lightly, waking up every half hour or so. In one dream I looked out my bedroom windows, saw the lights, went out of the room to tell others that we could see the northern lights, tried to turn on a light switch, and it didn’t work. So I tried turning on other light switches, they didn’t work, and then I thought, “Gosh darn it, I’m asleep,” and I woke myself up.

Without much explanation, here’s a Scala 3 and ZIO 2 example that shows how to process command-line arguments (command-line input) in a ZIO 2 application:

As a brief Scala note today, in Scala 3 it doesn’t look like there’s a way to use something like a package object to make some initial code available to all sub-packages of a high-level package. That is, I’d like to be able to define some types in a top-level package like this:

As a brief Scala ZIO 2 note, if you are using ZIO.attempt and want to show the actual exception you are working with (instead of just Throwable), use refineToOrDie, as shown in this example:

I just wrote the following ZIO 2 question about how to use ZIO.cond to a friend, and got the answer shown. I’ve also added in my own comments where they make sense.

ZIO.done question

Hey, I’m trying to understand why my ZIO failWithMsgEffect doesn’t seem to get run in the following code example?

I have learned that there are better ways to handle this, but I’ve found that if I don’t understand something like this, it will come back to bite me later. Here’s the code:

Scala math FAQ: How do I square a number in Scala, such as squaring an Int, Double, Long, or Float?

Solution

You can square a number in Scala in at least two different ways:

  1. Multiply the number by itself
  2. Call the Java Math.pow function or the scala.math.pow function

Java date/time FAQ: How do I get the current date (i.e., now or today) in Java? Also how do I get the current time in Java?

Solution

With Java 8 and newer — i.e., Java 11, 14, 17, etc. — use any of the follow “now” methods on these Java classes to get the current data and time:

I don’t know the original source of this image or quote, but I like it.

Impossible ... risky ... give it a try

This is a bit of an unusual note, even for me :), but if you’re ever laying in bed and feel like someone or some thing has gotten in bed with you — but they’re not really there — you may already be asleep and not know it, or you may be having a hypnagogic hallucination.

For instance, last night in bed, while I was waiting to fall asleep, I was practicing a “witness-ing” meditation technique that I have learned. So I’m doing that as intensely as I can, just witnessing my body breathing, and then someone gets in bed with me. So then I realize that I’m probably in the usual “mind awake, body asleep” situation that I have been in a few thousand times in my life.

When I was younger I used to experience sleep paralysis a lot, but these days I can usually just wake myself up, and that’s what I did last night.

I think of this as being asleep and then waking myself up, but other people might say, “No, you must have been having a hypnagogic hallucination.” Personally, I’m about 99% sure that I am asleep, because I was able to do the same thing during an fMRI many years ago, and also during a sleep study test where the tester thought I was asleep because of my brain waves, but I was actually awake.

I have often thought that the story of The Odyssey is about temptation and maybe even addiction. And just now I saw this story from the Daily Stoic titled, Discipline Now, Freedom Later, and it offers an interesting take on self-discipline that starts like this:

“At a critical moment in The Odyssey, Odysseus tied himself to the mast of his ship because he knew he wouldn’t be able to resist steering the ship toward the beautiful sound of the Sirens. In temporarily giving up his freedom, Odysseus became the first person ever to hear the Sirens without fatally crashing into the rocks surrounding the island where they lived.”

The story goes on with another quote: “The labor will pass, the rewards will last.”

In a brief personal note, here’s a story about how “Pain is the Doorway.”

Pain is the Doorway

A few years ago I had a lucid dream that had a beautiful song in it. Unfortunately I didn’t wake myself up right away, and by the time I did wake up, I couldn’t remember all the lyrics. But my favorite lyrics, which set the tone for the song, are:

What do you think about
When you think about me?

So over time I’ve been coming up with other lyrics as I think of them, such as:

Tonight at the table,
Looking out at the sky,
My thoughts were so far away,
I wish I could tell you why.

And also:

Mac OS X launchd FAQ: Can you share some Mac launchd examples (also written as launchd plist examples, or launchctl examples)?

In an earlier tutorial (Mac OS X startup jobs with crontab, launchctl, and launchd) I demonstrated how to use the Mac OS X launchd facility instead of cron to run what would normally be a cron (crontab) job. As I started working with launchd and launchctl, I realized it would probably be helpful to see several different launchd examples, specifically launchd plist file examples.

MacOS screen zooming FAQ: Is there a way I can zoom in and zoom out my Mac screen (iMac, MacBook, MacBook Pro, Mac Mini)?

Yes, you can zoom in and zoom out your Mac/MacOS screen. The solutions are shown in the sections that follow. Note that this solution has been tested on macOS — formerly Mac OS X — systems from OS X 10.6 through macOS 10.14.

Mac desktop zoom in/out commands

If you’re using a Mac desktop system (iMac or Mac Pro) with a keyboard and a mouse with a mousewheel (or any sort of mouse-based scrolling system, like a Magic Mouse), just press and hold the [control] key, then scroll the mousewheel up and down, and you’ll see what I mean. The entire Mac screen zooms in and out, just like the “software zoom” on a digital camera.

Here’s another “fake oil painting” I created with Gimp recently. This one is of Thich Nhat Hanh meditating. I don’t remember the original source of this image (before I converted the original photo to an oil painting), but I’m pretty sure I found it on Facebook. On this one I manipulated the colors quite a bit, and also did a Gaussian Blur on the background.

Thich Nhat Hanh fake oil painting with Gimp

If I have my druthers, I’ll finish writing my current book near this wonderful spot, somewhere in Alaska.

A great place to write a book (somewhere in Alaska)

The following are some favorite quotes from Sri Nisargadatta Maharaj and his book, I Am That.

And on a personal note, to think that I have come to understand all of these quotes in this lifetime is a little mind-blowing to me.

Here then are the quotes:

If you’re interested in meditation but “don’t have the time for it,” this quote from Daniel Ingram on intensity in meditation/mindfulness practice was helpful to me:

“It is important to know that really getting into a sense of the breath as a continuous entity for ten seconds will do you more good than being with the breath on and off for an hour.”

One of my favorite songs of late is named Mad As A Hatter, by Larkin Poe. The song is about their grandfather, who has schizophrenia, and their grandmother, who has dementia.

All my life I have known someone who has schizophrenia, and in the last 20 years I’ve also known quite a few people who had dementia and/or Alzheimers, so it’s a touching song in multiple ways. YouTube has this terrific live performance of “Mad as a Hatter”.

Here are some of the lyrics from Mad As a Hatter:

If you must then just please wait and let me have some time
(Let me have some time)
Please don’t come for me
Mind over matter (it don’t matter) when you’re as mad as a hatter

The song ends with these repeated lyrics:

Off with her head, off with her head...
Paint the roses, paint the roses...

I assume the ending lyrics relate to Lewis Carroll’s Alice’s Adventures in Wonderland.