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

Today I heard the song Seminole Wind, by John Anderson for the first time. It’s pretty, sad, and haunting all at once. From SongFacts: “The lyrics reference the Seminole war chief Osceola, whose ghost cries out over the destruction of natural resources for financial gain.”

Today it reminds me of this very long dream I had about being a Native American and being killed by a white man.

I’ve been thinking lately that my biggest personal mistake is not finding a realtor in Colorado to find a small house for me, maybe back in 2013-14 or so.

That being said, I started going unconscious at that time (syncope) and had no idea if I was going to live, because doctors had no idea then that I had a rare blood disease. So in my defense, I didn’t know if I would die one of the nine times I passed out, or the four times I had “fake heart attacks” — blood flow reduced to my heart because of the blood disease (allergic angina, also known as Kounis Syndrome).

What I did instead was “loan” money to one of my sisters so she could buy a house, and now Zillow says her house is worth twice what she paid for it, so that worked out well for her.

I also spent all my savings on my mother’s caregiving expenses, and this combination of reasons is why I don’t live in Colorado anymore. (At the time of this writing, you can now find me in Kentucky.)

As a brief note, the paperback versions of my Scala and functional programming books are all currently on sale. Each book is at least 10% off right now (December 27, 2023). This sale will end on January 2, 2024.

Here are links to the books on Amazon:

(Note that the links are “Amazon affiliate links,” which means that I get a small commission on each sale, which helps me offset these price reductions.)

“If it wasn’t for the problem of how to sequence input-output actions correctly, monads probably wouldn’t have appeared in Haskell. But once it was appreciated what they could do, all kinds of other uses quickly followed.”

~ Thinking Functionally with Haskell, Richard Bird

I just added a new video — “What is Functional Programming?” — to my free “Introduction to Functional Programming” video training course.

What is Functional Programming? (free video)

Dateline December 19, 2023: I’m pleased to report that the initial videos for my 100% FREE Introduction to Functional Programming video training course are now online!

In this course I expect to have about 50 videos total, and 14 are recorded, eight are being released today, and I’m editing and reviewing the other six.

As always, I want to provide a big Thank You to Ziverge for sponsoring these free videos. It takes a long time to create videos like this, and I couldn’t do this without them!

If you’re ready, the free training videos start at this link:

Free Introduction to Functional Programming video course

This is a page of quotes from Daniel Ingram, mostly from two versions of his book, Mastering the Core Teachings of the Buddha.

On a personal note, there are maybe five great books I have read about meditation, and this book is one of the Top 5, maybe #1.

All of the following quotes come from Mr. Ingram.

The quotes from Daniel Ingram

  • Until you gain access concentration, you ain’t got squat.
     
  • ... if we can simply know our sensate experience clearly enough, we will arrive at fundamental wisdom.
     
  • Insight practice is all about ... grounding attention in our six sense doors and their true nature.
     
  • There are six sense doors. Sensations arise and vanish. Notice this for every sensation.
     
  • The gold standard for training in concentration is how quickly we can enter into specific, skillful, altered states of consciousness...
     
  • The gold standard for training in wisdom ... is that we can quickly and consistently perceive the true nature of the countless quick sensations that make up our whole reality...

I don’t remember how I first heard this, but I love this song named Runaway by Aurora.

As I update this post on December 16, 2023, I particularly like the lyrics, “Take me home, take me home where I belong.” (You get to a point in meditation that some people call “The Dark Night,” and I’ve been there for a while now, and I just want to finish the deed.)

There are a lot of songs about the relationship between fathers and sons, but this song named Fathers & Sons by Yusuf (nee Cat Stevens) hits pretty hard for the wonky relationship between my father and I:

How can I try to explain, cause when I do he turns away again
It’s always been the same, same old story
From the moment I could talk I was ordered to listen
Now there’s a way and I know that I have to go away
I know I have to go

Scala String FAQ: How do I split a String in Scala based on a field separator, such as a String I get from a comma-separated value (CSV) file or pipe-delimited file.

Solution

Use one of the split methods that are available on Scala/Java String objects. For instance, this example in the Scala REPL shows how to split a string based on a blank space:

Here’s a look at how to use the Scala Map class, with a large collection of Map class examples.

The immutable Map class is in scope by default, so you can create an immutable map without an import, like this:

I needed to use Gnuplot a little bit over the last few days, mostly to create 2D line charts, and these are my brief notes on how to get started with Gnuplot. If you haven’t used it before, it’s a pretty amazing tool.

Jumping right in ...

Installing gnuplot

Use MacPorts or Homebrew to install Gnuplot on Mac OS X systems:

port install gnuplot
brew install gnuplot

Sample data files

My examples use the following 2-column and 4-column data files:

[toc hidden:1]

Java array FAQ: How do I determine the Java array length, i.e., the length of a Java array?

Answer: While you might logically expect there to be a length method on a Java array, there is actually a public length attribute on an array (instead of a length method). Therefore, to get the Java array length, you just have to access this array length attribute.

Here's a source code example that demonstrates how to determine the Java array length for an array named toppings:

Java file FAQ: How can I test to see if a file or directory exists in Java (or Scala)?

Java solution

To see if a file exists in Java code, use the Java File.exists method. Here’s an example that shows the basic technique:

After being exposed to bed bugs at the Sage Hotel in Santa Fe, New Mexico in late 2023, I’ve been researching bed bugs. This article is specifically about bed bug infestations and how to treat them. This information comes from ChatGPT and a few other sources.

I haven’t decided yet if I like the book, Demystifying Awakening: A Buddhist Path of Realization, Embodiment, and Freedom, by Stephen Snyder, but one thing I do like is the concept of an “80/20 rule” that he learned about for when we are interacting with other people.

The idea is that even when you’re talking and interacting with other people, 80% of your concentration should still be on yourself and your inner processes, and 20% should be on who you are interacting with.

This is consistent with my own thoughts on the subject, and what Ram Dass said about Maharaji, that Maharaji could always be seen mouthing “Ram ... Ram ... Ram,” even when he was listening to others. Ram Dass himself also spoke of this in his own practice, and is almost always seen working a mala in public speeches.

Old woman, trying to make a man feel guilty: “What would your mother say?”

Man: “She’d say, ‘I’ve been dead for ten years, leave me alone.’”

~ an episode of Midsomer Murders

As a brief note to self, when you need to reduce the Scala Ammonite REPL verbosity, specifically the output that shows “type” information when you declare new variables, I just found that this command helps:

repl.pprinter() = repl.pprinter().copy(defaultHeight = 0)

From what I can tell from the docs, the defaultHeight defaults to 5, and this reduces it to 0. So when you have Ammonite type output that looks like res1 in this example:

As a brief note, here’s an example of the ZIO (ZIO 2) collectAll method.

To make things more interesting, I also show several examples of how to use ZIO types and type aliases, both with the printLine function and the theEnd value at the end:

As a brief note today, if you want to see an example of the ZIO collectAllPar method, the Scala 3 source code below shows one possible example that uses collectAllPar in a for expression.

First, here’s a small snippet of code that shows just the key parts: