Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

[Dateline: The evening of May 5, 2007, On The Border restaurant, Louisville, Kentucky, after several pitchers of margaritas and beer, and three days before I would leave for Alaska.]

Brother-in-Law: Seriously man, I want to thank you.

Me: For what?

Brother-in-Law: You inspired me to start my business.

Me: That’s great, how did I do that? (Now I’m all geared up to hear a motivational story of how I inspired him.)

Brother-in-Law: I figured if you can start a business, anyone can.

In one of the stranger things to happen in dreamland, I’ve had several dreams with my brother-in-law in them in the last few weeks. He passed away last summer, and each time he appears, he’s a translucent white color, and as I observe him, he keeps helping people within the dreams. Last night a man passed away in a bed, and then my brother-in-law appeared and picked the man up and carried him away.

Though I have lucid dreams all the time, these are particularly unusual because I haven’t had a translucent person in a dream since I was less than eight years old. Back then we lived in Chicago and right after I’d go to bed, a translucent man would come out of the closet and try to play with my toys, in particular a large model Boeing 727 aircraft. (Which is probably more than you want to know about my dreams, lol.)

This land today, shall draw its last breath
And take into its ancient depths
This frail reminder of its giant, dreaming self
While I, with human-hindered eyes
Unequal to the sweeping curve of life
Stand on this single print of time.

This land, today, my tears shall taste
And take into its dark embrace
This love, who in my beating heart endures
Assured, by every sun that burns
The dust to which this flesh shall return
It is the ancient, dreaming dust of God.

When working from home, my preferred writing environment is to use a huge fixed-width font on a large monitor with a matte finish, and nothing else on the screen. I write my text using either Markdown or LaTeX, depending on what the output format is going to be. And Yoda and Meditating Guy make me feel a little less crazy when I’m talking to myself. ;)

My preferred writing environment

And in the category of “Strangest Things I Never Knew About Java,” I give you ... CAFEBABE.

CAFEBABE and Java class files

If you want to create a shell script so you can change between MacOS dark mode and light mode from the Terminal (Unix) command line, put this source code in a file and name it something like dark:

osascript -e \
'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode'

Then make that file executable, and make sure it’s on your PATH. Now you can type dark to toggle back and forth between dark mode and the regular light mode:

Table of Contents1 - Example2 - A more complex example3 - Note4 - Summary

If you’re ever working on a really small Scala project — something that contains only a few source code files — and don’t want to use SBT to create a JAR file, you can do it yourself manually. Let’s look at a quick example. Note that the commands below work on Mac and Linux systems, and should work on Windows with minor changes.

If you run into a problem where a Scala shell script won’t run on MacOS — it hangs indefinitely without doing anything — hopefully this bug report will help. The solution is to change this line at the beginning of the Scala shell script:

exec scala -savecompiled "$0" "$@"

to this:

exec scala -nocompdaemon -savecompiled "$0" "$@"

I just had this problem with Scala 2.12.x and Java 8 running on MacOS 10.14.4, and I can confirm that adding -nocompdaemon solved the problem for me.

Table of Contents1 - def field in trait2 - val field in trait (abstract)3 - val field in trait (concrete)4 - var field in trait (abstract)5 - var field in trait (concrete)6 - An abstract class in the middle7 - A trait in the middle8 - Summary

I generally have a pretty good feel for how Scala traits work, and how they can be used for different needs. As one example, a few years ago I learned that it’s best to define abstract fields in traits using def. But there are still a few things I wonder about.

Today I had a few free moments and I decided to look at what happens under the covers when you use def, val, and var fields in traits, and then mix-in or extend those traits with classes. So I created some examples, compiled them with scalac -Xprint:all, and then decompiled them with JAD to see what everything looks like under the covers.

I was initially going to write a summary here, but if you want to know how things work under the hood, I think it helps to work through the examples, so for today I’ll leave that as an exercise for the reader.

Sometimes people write to tell me that they like my writing style, that I’m good at explaining things. Other people write and say that if they wrote a book, they would have written it just like mine.

The truth is, when I first started working with Scala I fell in love with the language, so wanting to write about it was easy. After that, I’m not that smart, so I have to break complex things down so I can understand them myself. So I think that by breaking things down and looking for meaningful examples, people seem to appreciate what I’ve written (or I hope they do).

After I wrote the Scala Cookbook and people sent me notes like that, I struggled with writing for a little while. Then I decided to just try to write for a younger version of myself and ignore what other people were saying. I just ask myself, “Would this have helped Al two years ago?” Since then I’ve been fine.

Don’t objectify me

“What is it about elevators?”

~ Christian Grey

As a brief note today, here’s an example of stackable modifications in Scala.

Lately I was curious about what super means when you mix Scala traits into a class or object. A simplified answer is that super refers to the last trait that’s mixed in, though I should be careful and note that this is an oversimplification.

This can be demonstrated in an example that uses both inheritance and mixins with traits. Given this combination of traits and classes:

Just when Margaret thought Frank was going to say something else ...

Have you got any cookies?

I call this one, “Up With the Sun, Gone With the Wind.”

(April 13, 2017)

Up With the Sun, Gone With the Wind

Working with yoga is often interesting. You stretch and twist and focus, trying to be very conscious and aware of your movements, and then one day in the middle of a twisting pose you see your left foot coming out from behind your right ear. At first that’s a real surprise, a shock. You think, “Well, that can’t be my foot over there”, and then you realize it is your foot, and with that comes a strong sense of accomplishment, and maybe a little smile.

Then you do the same pose in the opposition direction, but twist and stretch as you might, your right foot doesn’t come out from behind your left ear. You know you can’t push it any more, at least not while doing the pose properly, so you realize you have a little imbalance. You accept that you have some work to do, but it’s a good thing, so you push on.

I think life is like that too, or can be like that. If you enjoy the struggle, if it’s a worthy struggle — a path with heart — the effort comes willingly, and with its own rewards.
 

Namaste

For many years I struggled with how to combine two of my main interests, Zen and work. I had read that the Zen mind is the mind before thinking, so it seemed like Zen and work must be totally unrelated. But over time I came to understand phrases like, “When working, just work.”

This article contains a collection of quotes that have been helpful to me in understanding the relationship between Zen and work. Please note that I don’t wrap each quote in double quotes, and I also try to attribute each quote to the correct author/speaker. If you’re interested in how to combine Zen and work, I hope you’ll find them helpful.

I’m horrible at date calculations — what do you mean by “between”? — but I do know that April 10th is the 100th day of all non-leap year years.

Happy 100th Day of 2019