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

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.

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

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

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:

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.

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 load managed dependencies into the Ammonite REPL? What is the syntax for loading dependencies (and JAR files, too)?

Solution

If you want to import a managed dependency into the Ammonite REPL, the solution is to use its import $ivy syntax:

I initially created this “How to use Scala CLI” content for my new Scala book, Learn Functional Programming Without Fear, but when I decided to shorten what I include in the book, I also decided to put the full version of this content here.

What is Scala CLI?

Until some time in the year 2021 I would have written this book using only the Scala SDK and its scalac and scala commands to compile and run your code, respectively. (These are just like javac in Java, kotlinc in Kotlin, and java with both of those.)

But since that time the Scala CLI command project has come along, and it greatly simplifies the “getting started with Scala” experience, so I use it in this book. Scala CLI:

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.

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

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.

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.

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, all is well.

I should also say that I was very busy, 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.

“Trying to find a way to love everyone in a world I don’t even like.”

As a brief note today, here is some source code for a ZIO ZLayer application using Scala 3. In this code I use the ZLayer framework to handle some dependency injection for a small application. (Note that I don’t like to use the word “simple” when writing about software, but I have tried to make this as simple as I can.)

I’ve commented the code below as multiple “parts” so you can see the thought process of creating an application that uses ZLayer. Basically the idea is that your application needs some sort of service — which might be like a database connection pool, HTTP framework, etc. — and then you make that service available to your application with ZLayer’s provideLayer function (or one of its other functions).

The ZLayer example

Given that small introduction, here’s my ZIO ZLayer example, with many notes shown in the comments inside the code: