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

macOS FAQ: From the command line, how do I show the largest files under a directory on macOS (and Linux/Unix systems).

Solution: Use the Unix du (disk usage) command, and sort its output.

A du/sort command to show the largest files under a directory on Mac OS X

The Unix/Linux command that worked for me on my MacOS system is this:

$ du -a * | sort -r -n | head -10

du is the disk usage command, and the -a flag says, “Display an entry for each file in a file hierarchy.” Then I use the sort command to sort the du output numerically and in reverse. After that, head -10 shows only the first ten lines of output. In the Music folder on my Mac the command and output look like this:

Tho’ much is taken, much abides; and tho’
We are not now that strength which in old days
Moved earth and heaven, that which we are, we are;
One equal temper of heroic hearts,
Made weak by time and fate, but strong in will
To strive, to seek, to find, and not to yield.

~ Part of the poem Ulysses, by Lord Alfred Tennyson

(In the process of writing Functional Programming, Simplified, I had to make thirteen trips to the emergency departments of three different hospitals.)

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 #4 out of 7.

Buy a Scala Cookbook, signed by Alvin Alexander

As a quick note today, here’s a list of my currently-free books and online video courses about the Scala programming language and functional programming (as of October, 2024):

These books and courses are free thanks to the generosity of Ziverge. If you ever want to pay them back, check out their “on-demand team extension services.”

Free books and online video courses from Alvin Alexander

December 11, 2023: The following quote is from a book I’m currently reading named Demystifying Awakening. I wish everyone had the chance to experience Nirvana at least once in their physical lifetime. I think Earth would be a much better place.

Here’s the quote:

I just had a situation where I wanted to convert this Scala Map:

val userPrefs = Map(
    "theme" -> "dark",
    "lang" -> "en"
)

into a formatted String that looks like a collection of key/value pairs, like this:

"theme=dark;lang=en"

In short, I found this to be a good solution:

Server-side HTTP FAQ: When you're writing a server-side application, are cookies considered to be part of the header information?

Answer

Yes, cookies are part of the HTTP headers. Specifically:

Here’s a photo I took on the drive back from Golden today of some cattle on the right and wrong side of the fence, a big field, and some mountains. (Click the small image to see the full size image.)

Cattle, field, and mountains near Golden, Colorado

December 10, 2021:

I was sitting there meditating in the pitch dark this morning, enjoying a peaceful, easy feeling, when I heard a woman say, “Alvin.” It wasn’t like “Alvin, are you there?”, but more like, “Alvin, pay attention, I’m about to say something to you.”

But for some reason that was as disconcerting as any experience I’ve ever had, and I popped out of the meditative state and opened my eyes.

I only learned about Sri Nisargadatta Maharaj in 2024, but his teaching have made a huge impression on me. To that end, here are some of my favorite quotes related to his famous saying, “I am not the body,” from the book, Consciousness and the Absolute: The Final Talks of Sri Nisargadatta Maharaj:

  • The very idea that you are the body is ridiculous. Consciousness is experiencing its manifestation.
  • Just as I see you, I look at this body, but I am apart from it. I am not identified with the body.
  • (A jnani) watches the play as a witness.
  • ... this consciousness functions through millions of forms.
  • A jnani’s state remains the same with or without the body.
  • Disassociate from the body.
  • There is no otherness; you are everything.

There are many more great quotes in that book, but these are the ones that really strike me today (December, 2024).

I was sleeping on the couch this morning when X (a black and white husky) jumped up on me. I was laying on my right side, facing the back of the couch, so my back was to her. When she jumped up, her front legs were on my left hip, so I assumed she was standing on her back legs.

This woke me up and without moving much, I said, “Do you have to go out? That’s a good girl for letting me know.”

So I moved around and got up, but there was no dog there. X was asleep on her bed in the hallway.

(This was the third time a dog has gotten in bed with me while I was laying down, only to not be there after I moved around.)

~ December 7, 2022

[From time to time I write little stories that have nothing to do with programming or technology; this is one of those stories. So, if you’re only here for the technology stuff, you’ll want to skip this one.]

I’m standing in the kitchen of a friend’s house at a Christmas party, making myself a drink while talking to a friend named Angie. This was nothing unusual; she and I were always talking about something. We became friends during our last year in high school, and we’ve been talking ever since.

In retrospect, it’s obvious that I have feelings for her, but I guess you could say that I didn’t appreciate her back then. After high school, my ambition took me away to college, and then to a series of jobs in different states. By the time I decided to move back home, she was married and had two young children.

While we talked all the time, this kitchen conversation was unusual. I don’t remember how it started, but Angie did ask me about something I rarely talk about: my parents getting divorced in high school.

A friend was in Talkeetna recently, and sent me a picture of what this cabin looks like these days. Skipping over that, this is what it looked like in mid-September when I lived there.

The old cabin in Talkeetna

Some great lyrics from Dan Fogelberg:

I have these moments all steady and strong
I’m feeling so holy and humble
The next thing I know, I’m all worried and weak
And I feel myself starting to crumble
The meanings get lost, and the teachings get tossed
And you don’t know what you’re gonna do next
You wait for the sun but it never quite comes
Some kind of message comes through to you
Some kind of message comes through
And it says to you
Love when you can
Cry when you have to
Be who you must
That’s a part of the plan
Await your arrival
With simple survival and
One day, we’ll all understand

Years before I heard of Shinzen Young, I had always “enjoyed” practicing meditation in the cold. Some part of it probably goes back to childhood, when I had to wait for the schoolbus in the freezing cold of northern Illinois winters. (This was in the time before global warming.) I used to stand there without moving, and mentally I’d concentrate on not being cold, or at least not feeling the cold.

Many years later when I lived in Alaska, I used to enjoy going up into the mountains to basically inflict the same thing on myself. I always thought the “meditate deeply or suffer the consequences” approach forced me to meditate more deeply. This past winter that same “Do or die, there is not try” mentality forced me to maintain my focus and helped to combat my medically-induced lack of energy.

A favorite quote:

“She was beautiful, but not like those girls in magazines. She was beautiful, for the way she thought. She was beautiful, for the sparkle in her eyes when she talked about something she loved. She was beautiful, for her ability to make other people smile, even if she was sad. No, she wasn't beautiful for something as temporary as her looks. She was beautiful, deep down to her soul. She is beautiful.”

~  F. Scott Fitzgerald

She was beautiful, but not like those girls in magazines ...

As I wrote in Different meditation/mindfulness practices, different cultures, and they all talk about witnessing/noting, mindfulness and meditation masters (teachers) from different cultures, countries, and styles of practice often teach the same thing in different ways: a style of mindfulness meditation known as witnessing or noting.

To me, a simple way to think about this is that as your body goes along with its daily life, all you have to do is simply narrate what your body is doing at all times, in the present moment.

If you like, you can think of yourself as being the witness/soul, watching the body, and noting what it’s doing, like a birdwatcher does when they note what birds are doing in a forest. It’s that simple.

I’ve mentioned before that at the Providence Zen Center, when you meditate, you are told to constantly ask yourself, “What am I?” And when you’re doing some action, such as driving a car, you ask yourself, “Who is driving?”

I’ve also mentioned that these days the most popular mindfulness practice is to “note” what you’re doing, moment by moment. So when you’re eating you say, “eating,” and when you’re washing your hands you say, “washing,” and so on.

Ram Dass and witnessing

Tonight I was re-reading Ram Dass’s first book, Be Here Now, and found a section where he talks about developing the “witness” in yourself by narrating your life: “Oh, he’s heading to the refrigerator now. It looks like he’s going to get some ice cream. Yes, he’s picked up the ice cream container...”

The thing about these techniques is that (a) they come from three different types of spiritual practice, but (b) although their words are different, their intent is the same: They try to get your attention/awareness aligned with what your body is doing in the present moment.

If you’re interested in logging in a ZIO application, the following example shows a collection of different ways you can write log messages. I also show how to create your own custom log format, so the output logging from this application looks like this:

Just a quick note today that the “noting” and “witnessing” styles of meditation are basically the same.

When you practice noting, you note everything the body does as it’s doing it, so as the body does things you say walking, picking up, hearing, etc.

Similarly, when you practice witnessing...

Mindfulness/Meditation: Noting, Witnessing, and Daniel Ingram’s agencylessness