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

If you’d like to buy a signed copy of the Scala Cookbook, here’s a link to one I have on sale at ebay.

As I note on ebay, I only have seven copies of the Cookbook, and this is Book #2 out of 7.

Buy a Scala Cookbook, signed by Alvin Alexander

NOV., 2022: My new book, Learn Functional Programming The Fast Way, is currently an Amazon Java and functional programming #1 new release. The book is now available in three formats:

PDF Format
$10 (USD) on

Learn Functional Programming The Fast Way! (PDF Version)

$30 on Amazon

Learn Functional Programming The Fast Way (Paperback)

$10 on Amazon

Learn Functional Programming The Fast Way! (Kindle Edition)

Functional Programming, Simplified — currently 5-star rated on, 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

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

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.

IMHO, once you dig into all the eastern religions, you’ll find people saying the same things, and just using different words.

One favorite quote comes from Sri Nisargadatta Maharaj, who said, “Just remember that you are the witness only ... even for a moment, do not think that you are the body.”

Anandamayi Ma was quoted as saying, “My consciousness has never associated itself with this temporary body.”

Those two quotes remind me of this great image that’s based on a Ram Dass quote about humans being spiritual beings who are having a human experience, and not vice-versa. (Also, I apologize, I don’t know who originally created this image, so I can’t give them attribution.)

Ram Dass: spiritual beings who are having a human experience

As a brief note today, here’s a Scala 3 function that counts the number of vowels in the String it is given as input:

def countVowels(s: String): Int =
    val vowels = Set('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')

Note that this works because as I have mentioned in other places, a Scala Set can be used as a function — specifically as a predicate — and the count function on the Scala sequence classes expects a predicate.

As a brief note today, and without much discussion, here’s a ZIO 2 ZLayer example I’ve been working on. The intent of the example is to show one possible way you can enable logging in a ZIO application using ZLayer.

As I mentioned, without much discussion, here’s the ZIO 2 source code:

Datline March 22, 2014: A little personal enlightenment:

After going unconscious several times during the last few weeks, I've had conversations with doctors, nurses, friends, and even a shaman about life, death, quality of life, goals, and desires.

I had a hard time answering some of their questions, and yesterday I realized why that was:

If you're truly living in the present moment, those questions don’t make any sense! You can't think about life, death, the past, or the future if you’re fully absorbed in the present moment.

“Are you afraid of dying?” / “I’m sorry, your fear has to do with the future, you’re not talking about the present moment.”

When planning for the future, live fully in that moment of planning for the future. When eating, just eat; and when writing text like this, just write. That’s all.

(In computer parlance, become single-threaded, where that one thread is only focused on HereNow.)

This is an ongoing blog post about “making the switch” from Google AdSense to Ezoic in 2024. If you’re just interested in updates over time, see the “Updates” section at the bottom of this article.

Switching from AdSense to Ezoic

For a long time I was afraid to switch to another company besides AdSense because I had not heard of Ezoic and others, but after several weeks on their platform, I’m happy to say that all is well.

I should also say that in my defense, I was also busy with other things in life, and I thought that “making the switch” might take a while, but if you have existing AdSense and Analytics accounts, it doesn’t seem to take too long. The actual time I spent on a computer to make the changes was probably about 4-8 hours overall, but in calendar time it took a few days because of the AdSense and Analytics integration (waiting), and a few other configuration things I had to wait for. (So, several days in calendar time, but 4-8 hours in actual time.)

It’s also important to note that Ezoic is an AdSense partner, which I discuss more below.

In my post on Ram Dass’s best books — and in other articles on this website — 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, as well as his speeches, books, and other writings, I have put together the following “Ram Dass Glossary of Terms” (and I hope it’s helpful to others).

Whenever I think of Father’s Day, I think of the song Papa Was A Rolling Stone: “And when he died, all he left us was a loan...”

(I never knew if the lyrics were supposed to be “alone” or “a loan,” but the latter is more accurate in my case.)

This was from a thoughtful gift back in the day. :)

A great Halloween pumpkin squirrel card

I got a “chemo ninja” t-shirt like this one when I was recovering from thyroid cancer. Think I’m gonna need a new one after they remove part of my digestive system in about ten days.

Chemo ninja t-shirt

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.

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

Scala dates FAQ: How do I calculate the difference between two dates in Scala? That is, while using Scala 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:

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 the same thing in Kotlin or Scala?)


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

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.

As a brief note today, I’ve been reading the Bhagavad Gita (translated by Jack Hawley) lately, and he shares this good line that relates to desire, attachment, and even addiction:

“Realizing the truth of your True Self is your principal weapon for eradicating desire.”

My short interpretation of that is that our True Self is not our physical body, but something else that you might call awareness, consciousness, the subtle body, the soul, or the Atma (depending on your background), AND, it is possible through yoga, mindfulness, and meditation practice to get in touch with (feel/experience) your True Self. And then, once you realize who “you” really are, your attachments to the physical world will go away.

I used to have a friend who was an addict, and I know she was always looking for anything that would help, so I hope this quote can be helpful for others.

As a followup to my original post, in the book, I Am That, Nisargadatta Maharaj basically says the same thing (many times) as the quote I shared above.

As a brief note today, I have tried quite a few different styles of meditation over the last 10-20 years, and I want to make a note of them here. I’m going to start by listing the meditation teachers I know, write a little bit about each one, and then at the end I’ll try to summarize these teachings.