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

A photo of my old RAV4 in Coldfoot, Alaska, on the Dalton Highway, on the way to Deadhorse and Prudhoe Bay, Alaska, back in August, 2007.

The RAV4 on the Dalton Highway, Alaska (Coldfoot)

A photo of me (Alvin Alexander), after coming inside from a cold, Alaskan winter night in 2010-2011.

Alvin Alexander, cold Alaskan winter night

I guess I still don’t understand women.

This morning one of my doctors kept saying, “Is there anything else you’d like to ask me?”

After the third time she asked that question I thought, “I’ve seen this in the movies, I know what she’s really asking,” so I replied, “Do you want to come over and bake some cookies?”

Everything after that was a blur ... I think she said, “What?”, and then I think I said, “What??” ... now I don’t know if I need a new doctor or some cookie dough.

~ a Facebook post from July 15, 2014

The Arctic Caribou Inn, aka, the “Hilton” of Deadhorse (Prudhoe Bay), Alaska. I drove up there once upon a time in early August, 2007.

The Arctic Caribou Inn, Deadhorse, Alaska

A curious wolf I came across one time in British Columbia, Canada.

A curious wolf in British Columbia, Canada

“Live the life you love.” As seen in Estes Park, Colorado.

Live the life you love shirt

The Welcome to Beautiful Downtown Talkeetna (Alaska) sign.

Welcome to Beautiful Downtown Talkeetna

Quick tip: To append when writing to a text file in a Scala or Java application, create your FileWriter with the append flag set to true, like this:

val bw = new BufferedWriter(new FileWriter(new File("/tmp/file.out"), true))
bw.write("Hello, world\n")
bw.close
Table of Contents1 - Linux crontab: How to run a command every minute2 - Descriptions of the crontab date/time fields3 - Run a crontab command every hour4 - Run a crontab entry every day5 - Run a crontab entry every 5 minutes6 - Unix and Linux “crontab every” summary7 - Unix and Linux crontab reference information

Linux crontab FAQ: How do I schedule Unix or Linux crontab jobs to run at intervals, like “Every five minutes,” “Every ten minutes,” “Every half hour,” and so on?

Solution: I’ve posted other Unix/Linux crontab tutorials here before (How to edit your Linux crontab file, Example Linux crontab file format), but I’ve never included a tutorial that covers the “every” options, so here are some examples to demonstrate this crontab syntax.

Table of Contents1 - A “Hello, world” MacOS AppleScript notification2 - AppleScript: Mac notification with a sound3 - How to add a title and subtitle to your notification4 - Running from Scala (or Java)5 - See also6 - Summary

Summary: This tutorial demonstrates how to fire MacOS system notifications with AppleScript and Scala (or Java).

In this article it helps if you already know a little bit about AppleScript, though that’s not completely necessary. Near the end of the tutorial I show how to invoke the AppleScript code using Scala, so feel free to skip down to there if you just want to see that — you can always read the stuff at the top for reference later.

A team of researchers have created this photograph showing the entanglement of photons. Business Insider has a nice little story about their work.

Photo of quantum entanglement

I watched an episode of Northern Exposure recently and at the end of it I was surprised to see that Stuart Margolin directed the episode. I always enjoyed his characters on The Rockford Files and M*A*S*H, and I remembered seeing him on Magnum, P.I., but I didn’t know anything else about his career, including that he was a director. After reading his Wikipedia entry I hope at some point to see the episode of 30 Rock he did with Alan Alda.

Stuart Margolin and Northern Exposure

The UI still needs a lot of work, but I like the idea of having an Inconceivable mode in the next version of my XO Play Android football game.

My 'XOP' football game UI, v1.4

I heard this poem on this Monk episode last night.

“Hold me, Adrian,
my darling husband.

True love’s touch is so rare a gift.
How much more precious is your caress
who loves so deeply,
yet fears the warmth,
of hand on hand.

Still your love is given free,
only to me,
only to me.”

~ Trudy Monk

Table of Contents1 - Basic use2 - Using a Map3 - Match expressions4 - Sed limitations5 - My Sed project6 - Bonus: Factories and HOFs

My Scala Sed project is still a work in progress, but I made some progress on a new version this week. My initial need this week was to have Sed return a String rather than printing directly to STDOUT. This change gave me more ability to post-process a file. After that I realized it would really be useful if the custom function I pass to Sed had two more pieces of information available to it:

  • The line number of the string Sed passed to it
  • A Map of key/value pairs the helper function could use while processing the file

Note: In this article “Sed” refers to my project, and “sed” refers to the Unix command-line utility.

Back to top

Basic use

In a “basic use” scenario, this is how I use the new version of Sed in a Scala shell script to change the “layout:” lines in 55 Markdown files whose names are in the files-to-process.txt file:

“More important than Buddhism, or Zen, or anything, is waking up. The Buddha was not a Buddhist. He was a ‘wake up’ person and what he woke up to is something everybody already has. Buddhism is not going to help you. Waking up is going to help the whole world.”

~ Zen Master Dae Kwang (from KwanUmZen.org)

Buddhism is not going to help you

From NASA.gov: As if black holes weren't mysterious enough, astronomers using NASA's Hubble Space Telescope have found an unexpected thin disk of material furiously whirling around a supermassive black hole at the heart of the magnificent spiral galaxy NGC 3147, located 130 million light-years away.

The conundrum is that the disk shouldn't be there, based on current astronomical theories. However, the unexpected presence of a disk so close to a black hole offers a unique opportunity to test Albert Einstein's theories of relativity.

Hubble telescope uncovers black hole that shouldn’t exist

I’ve seen five rattlesnakes since I moved to Colorado, four dead and one that was quite upset with me. As I was walking yesterday I wondered, can snakes see? Here’s an answer from animals.howstuffworks.com.

LiveScience.com adds this information: “With the exception of a few species that have adapted to daytime hunting, most snakes do not see well. Generally they can see shapes but not details. Snakes called pit vipers can see well at night by an amazing trick. Their pits (one on each side of the head) sense heat (infrared light) like night vision goggles. These pits, not eyes, actually are thought to render images of prey in the snakes’ brains.”

Can snakes see?

Since I’ve been in Colorado we seem to get anywhere from five to 25 hailstorms a year. Sometimes they have markdowns on cars, other times, flowers.

Hailstorms in Colorado (and markdown sales)