I ran into a couple of interesting things today when trying to generate random alphanumeric strings in Scala, which can be summarized with the code shown below. Skipping the details of what I was working on, here are several examples that show how to generate lists of alphanumeric/ASCII characters in Scala:
Scala, Java, Unix, MacOS tutorials (page 114)
A favorite gift from the last twelve years is the purple pencil sharpener shown at the top of this image. It may have only cost a dollar or two, but one of my sisters and her daughters gave it to me when I saw them right before I moved to Alaska, and it’s been with me ever since. I especially like it at times like this, when I’m editing a new book.

I found a little ice skating rink in downtown Louisville, Colorado recently. Looks like it would be fun at night. :)
Scala lets you add new methods to existing classes that you don’t have the source code for, i.e., classes like String
, Int
, etc. For instance, you can add a method named hello
to the String
class so you can write code like this:
"joe".hello
which yields output like this:
"Hello, Joe"
Admittedly that’s not the most exciting method in the world, but it demonstrates the end result: You can add methods to a closed class like String
. Properly (tastefully) used, you can create some really nice APIs.
In this article I’ll show how you can create implicit methods (also known as extension methods) in Scala 2 and Scala 3 (Dotty).
I recently started using AsciiDoc to write a new book. A great thing about it is that unlike Markdown, you can use AsciiDoc to write a book and get all of the features you want in a book, including linking between anything, captions for tables and figures, indexes, etc. Because this got me started using AsciiDoc I thought, “Wouldn’t it be nice if I could also use AsciiDoc to write blog posts like this one?”
Sadly, I quickly ran into a problem: I couldn’t find a good way to convert AsciiDoc into HTML, or even Markdown. There are tools to convert AsciiDoc to HTML, but for some reason they take the approach of including a ton of markup in the HTML (divs, spans, and attributes), and as far as I can tell there’s no way to turn off that markup.
I ended up not using this code, but if you wanted to see one way to use JSoup’s OutputSettings (Document.OutputSettings) class to set some parameters before calling JSoup.clean
, I hope this is helpful:
// tried some things to improve the html output val settings: OutputSettings = new OutputSettings settings.prettyPrint(true) //`true` is default settings.charset("UTF-8") settings.outline(true) //this is close to what i want, but too extreme settings.indentAmount(4) val cleanHtml: String = Jsoup.clean(html, "", wl, settings)
I can attest that this code works, it’s just not what I need at the moment.
Also, the code shown is written in Scala, but as you can see, it converts easily to Java.
“How can we prevent our thoughts from wandering? How can we learn to focus our attention on one thing?”
“The answer is that we cannot do it with our brain alone; the brain cannot control its thoughts by itself. The power to control the activity of our mind comes from the body, and it depends critically on posture and breathing.”
~ From the book, Zen Training, by Katsuki Sekida
If you ever need a Scala method/function to convert a string with newline characters in it to a sequence of strings (Seq[String]
), here you go:
def convertStringWithNewlinesToSeq(s: String): Seq[String] = s.split("\n").toVector
You can convert the final result to a Vector
, Seq
, List
, ArrayBuffer
, Array
, etc., but I prefer Vector
. The Scala REPL demonstrates how it works:
scala> convertStringWithNewlinesToSeq("") res0: Seq[String] = Vector("") scala> convertStringWithNewlinesToSeq("foo") res1: Seq[String] = Vector(foo) scala> convertStringWithNewlinesToSeq("foo\nbar\nbaz") res2: Seq[String] = Vector(foo, bar, baz) scala> convertStringWithNewlinesToSeq("foo\nbar\nbaz\n\n") res3: Seq[String] = Vector(foo, bar, baz)
“The way you look at things is the most powerful force in shaping your life. In a vital sense, perception is reality.”
~ John O’Donohue, Anam Cara: A Book of Celtic Wisdom
(Or, as I wrote many years ago, all you are is attitude.)
Here’s a photo of a big sky over the Rocky Mountains, just south of Boulder, Colorado on January 28, 2014. I saw this same sky in Denali, Alaska once many years ago. Breathtaking both times. (Click the image for a much larger version of it.)

As a brief note, here are a couple of examples about why you shouldn’t use double or float values for currency, courtesy of Joshua Bloch’s Effective Java book:
scala> 1.03 - .42 val res0: Double = 0.6100000000000001 scala> 1.00 - 9 * 0.10 val res1: Double = 0.09999999999999998
I don’t know who created this image, but I’m all for it. Make America kinda again. Make America compassionate again. Make America smart again. Any sort of intelligent, enlightened leadership in this country would be wonderful.

Don’t judge each day by the harvest you reap, but by the seeds you plant.
I’ve been a fan of Joe Walsh for a while, especially since meeting a friend back in 2013 that had a drug and alcohol problem. Here are a few quotes from him from an article titled, Creating While Clean (Sober musicians on how to thrive creatively without drugs or booze):
Most of my buddies are dead. And for some reason, I am not.
I would say I’m a sober member of Alcoholics Anonymous. I have 25 years of sobriety. But the important thing is, I haven’t had a drink today.
How do you say it? “A huge ego with no self-esteem.”
I was that scared little kid again. And I managed to get some consecutive days of sobriety, and I went to some AA meetings, and I realized, “I can’t say my life got better, but it stopped getting worse.” And that was huge. So I stuck around. And I realized that I’m not one of a kind and unique and different from everybody else. I’m an alcoholic. And a big light went off, and I didn’t feel alone anymore.
I can’t say this to you in ink. I can pencil it in: I know I’m good today.
My life has got better beyond my wildest imagination.
(And if you’ve never heard it before, here’s his song, One Day At A Time.)
This image is from an article titled, Why don’t people use formal methods? I like the parts about writing “precise, unambiguous specifications,” and some other parts.

I think this white van has been parked in Talkeetna, Alaska, for as long as I've been living and visiting there.

Worked on pickup lines with my nieces in Illinois last night. I usually go with, “Excuse me, do you know how to bake cookies?”; “Oreos: Regular, or Double Stuf?”; or the classic, “What did you do when Hostess went bankrupt?” But thanks to them I’m working on my repertoire:
You’re so hot you must’ve started global warming.
Did it hurt? When you fell from heaven?
If you were a booger I’d pick you first. (might be best used in grade school)
Is it hot in here, or is it just you? (may be good if the woman appears to be having hot flashes)
Do you have a map? I just got lost in your eyes.
Stop, drop, and roll, baby. You are on fire.
Woo baby, you’re hotter than donut grease. (works best at Krispy Kreme and Dunkin’ Donuts)
~ a Facebook memory from January 24, 2014
Me: Alexa, play 70s folk music.
*Alexa starts playing a James Taylor song*
Me: Alexa, never play songs by James Taylor.
Alexa: Shuffling James Taylor playlist, on Amazon Music.
I love this short video of a primary school principal leading his students in a dance, in an effort to get them exercising and off their computers.