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

“I’m going to have to resect the colon.”

~ pretty much every surgeon on M*A*S*H at some point

Thanks to diverticula, diverticulosis, and diverticulitis, in 2018 I had to have a colectomy surgery, which is also known as a colon resection. This page is a diary of my colectomy experience.

Background: Diverticulitis

I had two bouts of diverticulitis in the lower-left portion of my abdomen, once in 2015 and again late in 2017. After the second bout in 2017 the pain never went away completely, and would get significantly worse if I tried to eat normal, high-fiber foods like cereal, wheat bread, broccoli, etc.

After my first-ever bought with diverticulitis, I wanted to make notes about what happened over the last five days.

Monday, April 7, 2015

On April 7, 2015, I woke up at 3:30am with pain and discomfort in my lower-left abdomen. I knew something was wrong, but I didn’t know what it was. It felt like a golf ball was lodged in there, and several hours later it was still there.

Java double FAQ: How do I format Java double and float output to two decimal places, such as when I want to format its output for printing or to display in a user interface? (Also, how do I do this in Kotlin or Scala?)

Solution

There are at least two ways to round a double or float value to two decimal places in Java:

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

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/know all of these quotes in this lifetime is a little mind-blowing to me.

Here then are the quotes:

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.”

Java date FAQ: How do I get the current date (i.e., now or today) in Java? (Also asked as, 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:

Functional Programming, Simplified — currently 5-star rated on Gumroad.com, 4.5-star rated on Amazon, and one of the all-time best-selling books on functional programming — is currently on sale in three formats (prices shown in USD):

PDF Format
$15 on Gumroad.com

PDF version of Functional Programming, Simplified

Paperback Book
Now $29.99 on Amazon

Print version of Functional Programming, Simplified

Kindle eBook
$14.99 on Amazon

Kindle version of Functional Programming, Simplified

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

Scala dates FAQ: How do I calculate the difference between two dates? That is, while using ScalaScala 2 or Scala 3 — you need to determine the difference between two dates. Also, you want to use the newest Java date/time API for this work, such as the date/time API in Java 8, 11, 14, 17, etc.

Solution: Calculating the difference between two dates (in Scala and Java)

If you need to determine the number of days between two dates in Scala — or Java or Kotlin — the DAYS enum constant of the java.time.temporal.ChronoUnit class provides the easiest solution:

While many people know the famous Ram Dass book, Be Here Now — which is currently the #1 All-Time Best-Selling book in Spiritualism on Amazon — I’d argue that it’s not necessarily his best book. For example, I have met a few people in my travels who were struggling to read and understand it it because of all the art and 1960s “hippie style” stuff — which I personally like — and it was at that time I realized that while Be Here Now is his most famous book, it may not be his best book.

Ram Dass’s best books

IMHO, I think the following books are his best, where I believe best will also depend on (a) a person’s experience with his writings and teachings, and also (b) their own progress on the spiritual path.

In my post on Ram Dass’s best books — and in other places — I use words and phrases related to the work of Ram Dass, including terms on yoga, Hinduism, Maharaj-ji, Buddhism, meditation, mindfulness, mantras, and the different names of the man he called Maharaj-ji (aka, Maharaji, Neem Karoli Baba, Neeb Karori Baba). To help understand that article, and the speeches, books, and other writings of Ram Dass, I have put together the following “Ram Dass glossary of terms.”

When I first started meditating in the 1990s, I often had a hard time getting into the proper meditative state when I sat down on the meditation cushion. My “monkey mind” would be jumping all over the place, and it would take me a long time to get it to settle down. Many times I couldn’t even get it to settle down before my 30-minute timer went off.

Because of that, and because I really wanted to become better at meditating, I began experimenting with different ways to get into the meditative state faster.

As a result, this page is a summary of the best ways I know to help you get into a good meditation state when you take time to sit on the meditation cushion (or wherever else you sit). If you’re interested in getting into a deep state fast, these are the “best practices” I know, especially when you’re short on time.

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, like this:

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

And also:

Yesterday I watched the very emotional Elton John “Tiny Dancer” music video, and afterwards I wanted to do some research on how the music video was created, the story behind it, and what its meaning is. To that end, here’s a summary of what I found out about the “Tiny Dancer” music video.

The story and meaning of the Tiny Dancer song

The short story behind the Tiny Dancer song goes like this:

Mindfulness/meditation FAQ: What are the reasons, purposes, or motivations to practice mindfulness and meditation?

The motivations to meditate

I just took a little time to share some old notes from my meditation practice about “The purpose of mindfulness.” Or, stated another way, instead of asking about the purposes of being mindful you might ask, “Why bother being mindful?”, or “What are the motivations for practicing mindfulness and meditation?”

In the following sections I describe the purposes and motivations for practicing both mindfulness and meditation.

I don’t know how many people know Ram Dass or have read his writings, but I updated the first motivation here based on his work, because if you really get into mindfulness and meditation, what he states is the end goal.

“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

“On one occasion of my own practice, nearing deep samadhi, I happened to notice that the stage of my mind was quietly turning and a new scene was appearing. In this new scene no wandering thought popped up its head; there was absolute stillness and silence, as if one had landed on the Moon.”

~ Zen Training

Mostly because of Ram Dass books, and also more recently because of the book, I Am That, I have been digging deeper than ever into the concept of “The Witness.” By that I mean both in terms of how we use the witness as a meditation technique, and also what that really means.

To that end I have started collecting Ram Dass Ram Dass quotes about the witness and the process of witnessing as a form of meditation. Here then are the Ram Dass quotes about the witness that I’ve found so far.

Everything changes once we identify with being the witness to the story

Ammonite FAQ: How do I use ZIO 2 in the Ammonite REPL?

Solution

ZIO can be added into the Ammonite REPL as a managed dependency by using Ammonite’s import $ivy syntax: