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

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.

If you want to open an Apple News URL in Apple News on a Mac, the trick is to first open the URL in the Mac Safari web browser. From there you can then open the story in Apple News. And FWIW, to me this is a significant user interface and user experience problem when using Apple News with an iPhone and then Mac/MacOS systems.

As a quick note, if you want to embed a Scala source code example in your Scaladoc comments, just put the source code block in between {{{ and }}} characters in your comments, as shown in this example:

How to format source code blocks in Scaladoc comments

I know that it’s fashionable to say that Scala is dead or something similar to that, but I’ve gotten a few royalty checks from O’Reilly this year for the Scala Cookbook that are amazingly good (💰) for a 3-year old programming book.

Shoot, I’d be happy to receive these royalty payments during the initial months after the book’s release.

As Bjarne Stroustrup said, “There are only two kinds of programming languages: the ones people complain about and the ones nobody uses.”

“People tend to overestimate or underestimate how wonderful the experience (enlightenment) is. How wonderful is it? Well, I would say that anyone who has entered into the world of no-self, emptiness, and wisdom mind, who abides in that world, if you gave them a choice to live one day knowing what they know, or live an entire lifetime but not be allowed to know that, I think — I can’t speak for everyone — but I would say most people who live in that world would say, ‘I’d rather have one day knowing what I know than a lifetime of not being able to know this.’ So that’s how wonderful it is.”

~ Shinzen Young, in this video