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

5-Star Rated on Amazon.com
Domain Modeling
Made Functional

My book, Functional Programming, Simplified — 4.5-star rated on Amazon, their 6th-best selling book on functional programming, and 5-star rated on Gumroad.com — is currently on sale in three formats:

PDF Format
$15 (sale!) on Gumroad.com

PDF version of Functional Programming, Simplified

Paperback Book
Now $34.99 on Amazon
 

Print version of Functional Programming, Simplified

Kindle eBook
$14.99 on Amazon
 

Kindle version of Functional Programming, Simplified

Akka Actors Problem: You want to see the proper way to shut down Akka Typed actors.

(Note: This tutorial is written for Akka 2.6.)

Solution

There are two main ways to shut down Akka Typed actors:

  • Send them a “graceful shutdown” message, and let them shut themselves down by calling Behaviors.stopped

  • As a parent, stop a child actor with actorContext.stop(actorRef)

Akka Actors Problem: You know that an actor that “blocking” is bad for your Akka system, so you want to create actors that don’t block.

Solution

When using Akka actors, the mantra is always, “Delegate, delegate, delegate.” It’s important that high-level actors delegate work to lower-level actors, so the high-level actors can be free to receive new messages and respond to them immediately. This example shows how to implement non-blocking actors.

As I was writing the Scala Cookbook, 2nd Edition — and debating writing a book about Scala.js — I had to start thinking about how to implement Scala.js applications in the real world. When I did that, I began to look at these Scala.js libraries:

Akka Problem: In some situations you can’t pass an ActorRef to another actor, so you want to see how to “look up” an Akka Typed actor so you can send a message to it.

Solution

There are at least two ways to find other Akka Typed actors, and both involve using the Akka Receptionist. The example shown here in the solution shows how to find an actor asynchronously, and the example shown in the Discussion shows how to use the ask method to find another actor synchronously.

In both examples I’ll use the idea of creating an actor system that works like Amazon Echo devices. The basic idea is that a device like this has ears to listen to you, a mouth to speak to you, and a brain to do all of its work. In these examples the Brain actor will need to discover the Mouth actor.

We were playing at our camp when my older brother — who was standing on higher ground than I — saw something in the distance. He stood upright, then perfectly still. After a few moments he turned to me in a look of panic I had never seen before, pointed in a direction opposite from where he was looking, and screamed, “Run! Run!” I was startled at his behavior but I knew that something was very wrong, so I ran. And I ran.

I ran as fast as I could, weaving through the brush and constantly changing my course as I was chased by a white man on a dark horse. I thought I might be close to safety when I darted through some bushes, but I ran right into a creek that was too wide to jump across. As I paused for a moment to decide how to continue, the white man shot me in the back.

In intense pain and sudden shock, I stumbled forward into the creek, bent over with one hand in the creek. As I attempted to stand up and regain my balance, I was shot in the back again. This time my body flew forward towards the opposite side of the creek. I tried to control my fall but could not, and my torso slammed against the land. The right side of my face was pressed against the ground, my eyes still open. My right arm was trapped under my body, my left arm was somewhere down my left side. My legs lay in the creek’s water.

As a brief lesson on “the time value of money,” I’ve paid over $175,000 for caregiving services for my mom, which has forced me to sell my beloved Apple stock (which I had owned since 2009), as well as some Shopify stock that has multiplied even more than Apple. As you can easily tell from this one image, that $175,000 — which I started paying in 2014 — would be worth well over $1,000,000 today.

So, as an example, if I could have kept that $175,000 in the market at the beginning of 2017, it would be worth at least 5x since that time. This is one example of why a certain amount of money now can be worth much more.

Conversely, if you just keep your money in the bank, with the cost of living increasing at about 4% per year, $1 in 2003 is worth about 50 cents today. (Using the “Rule of 72”.)

AAPL stock, 2016-2021

May 17, 2021: At the moment I don’t expect/plan to write a book on Scala.js, but in my research I came across this terrific set of short videos by Mark Lewis on the Play Framework and creating web applications with Scala. At video #69 he starts to talk about Scala.js.

Interesting discussion of the day: A young woman who helped me at Best Buy today told me that one reason she works there is so she has something she can talk about with her father (tech stuff).

~ May 16, 2014

“The most beautiful people we have known are those who have known defeat, known suffering, known struggle, known loss, and have found their way out of the depths. These persons have an appreciation, a sensitivity, and an understanding of life that fills them with compassion, gentleness, and a deep loving concern. Beautiful people do not just happen.”

~  Elisabeth Kubler-Ross

I prefer the phrase, “Sun does not set.” #talkeetna #alaska

Talkeetna, Alaska: Sun does not set

This is a photo from May 10, 2011. The long bike-riding path in Palmer, Alaska was  one of my favorite things about living there. As you can see, it’s a nice, big path, separated from the road.

Bike path in Palmer, Alaska

I don’t remember where exactly in Palmer, Alaska I took this photo, but my best guess is that I was on a bike ride near some of the farms. I just found this photo this morning, so I thought I’d share it here.

Mountain range in Palmer, Alaska

Sunrise at Virginia Beach, April 9, 2017. No filters have been applied, this is what it looked like. :)

Ocean sunrise

Mama always told me not to look into the eye’s of the Sun ... sunrise in Virginia Beach, April, 2017.

Sunrise in Virginia Beach, April, 2017

Today (April 8, 2020) is a day off for me, so I woke up at 4:30am and went up on the roof of the apartment complex garage, and took a few photos of the Pink Moon. These are some small versions of the best Moon photos, along with one of the Sun, which was coming up behind me from the east as the Moon set in the west over the Rocky Mountains.

First, the “Pink Moon” setting over the Rockies:

Pink Moon setting over the Rocky Mountains

Last night I was chasing people who were putting bombs in buildings and flying shape-shifters (who I would later realize were on my side). When I started to catch up to them I’d find myself yelling, “please comply.” I give a “thumbs up” for the action/adventure part of the dream, but the writing and line delivery were just horrible.

~ a dream from April 8, 2017

Doctors have been treating me for “suspicion of mast cell activation syndrome (MCAS)” since 2016, and I recently got my first Covid vaccination shot. Here’s a quick summary of the experience.

Before the shot I took one Allegra pill, as usual, and then two Xyzal pills (where I normally take one a day, but as many as four).

I got the Pfizer vaccine shot, and quickly developed these symptoms:

A “Love” sign you might find at a rest area somewhere in Virginia.

Love (a Virginia rest area sign)

“In enlightenment, death has no relevance to one’s state of being.”

As I reflected on the meaning of Easter this morning, I remembered this quote from Tibetan lama, teacher, physician, sculptor, and painter, Chagdud Tulku Rinpoche. The quote is from his book, Life in Relation to Death.

5-Star Rated on Amazon.com
Domain Modeling
Made Functional