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

On my list to listen to: A TED Radio Hour discussion, Why Does Time Exist?

“There could have been no two hearts so open, no tastes so similar, no feelings so in unison.”

I realy like this quote from baseball pitcher Jason Marquis, talking about Tony LaRussa, Manager of the St. Louis Cardinals:

“One thing Tony (La Russa) always preached over there was execution and minimizing mental mistakes. You don’t have to have the most talented team to do that, and it doesn’t take the most talented team to win.”

In baseball and in work I think this is true. It’s similar to this quote from Mike Ditka:

“Effort without talent is a depressing situation....but talent without effort is a tragedy.”

The book, Advanced Scala with Cats, has a nice little function you can use to run a block of code “slowly”:

def slowly[A](body: => A) = try body finally Thread.sleep(100)

I’d never seen a try/finally block written like that, so it was something new for the brain.

In the book they run a factorial method slowly, like this:

slowly(factorial(n - 1).map(_ * n))

FWIW, you can modify slowly to pass in the length of time to sleep, like this:

def slowly[A](body: => A, sleepTime: Long) = try body finally Thread.sleep(sleepTime)

As a quick note, I was just looking into the state of Scala “lint” tools, and found ScalaStyle, WartRemover, and Scapegoat.

This 2014 underscore.io post states, “Those interested in FP purity in a Scala world, you’ll want WartRemover.” (Of course that recommendation may have changed by now.) The current ScalaStyle website states, “Scalastyle is used as part of the grading framework for the course Functional Programming Principles in Scala by Martin Odersky on Coursera.”

While reading the excellent Scala/FP book, Advanced Scala with Cats, I was just reminded that Scala’s Either class was redesigned in Scala 2.12. Prior to 2.12, Either was not biased, and didn’t implement map and flatMap methods. As the image from the book shows, Either is redesigned in 2.12 to include those methods, so it can now be used in Scala for-expressions as shown.

(I write about biasing in my book, Learning Functional Programming in Scala.)

Scala 2.12: Either is biased, implements map and flatMap

Summary: This page is a printf formatting cheat sheet. I originally created this cheat sheet for my own purposes, and then thought I would share it here.

A cool thing about the printf formatting syntax is that the specifiers you can use are very similar, if not identical, between several different languages, including C, C++, Java, Perl, Ruby, and others, so your knowledge is reusable, which is a good thing.

I haven’t used Scala Native yet, but at v0.1 it looks very cool. The image is from scala-lang.org, you can read much more about it at scala-native.org, and follow the developers here on Twitter.

The Scala Native project

“Pleasure in the job puts perfection in the work.”

~ Aristotle

Table of Contents1 - Running Ekko2 - Running Ekko commands3 - Listing commands Ekko understands4 - Written with Akka (and Scala)5 - Next steps6 - Add actors with reflection? (plugins)7 - The source code8 - More ...

I recently started working on a project that may or may not make it into my Scala/FP book. I’m currently calling it “Akkazon Ekko” — or “Ekko” — because it’s a little like the Amazon Echo, but written with Scala and Akka.

Benedict Cumberbatch narrates a film about Vietnamese Buddhist monk Thich Nhat Hanh titled, Walk With Me. You can see the movie preview here on YouTube, and learn more at WalkWithMeFilm.com.

Table of Contents1 - The correct approach (simplified)2 - A thorough example for verification3 - The wrong approach4 - Summary

If you want to create multiple Scala Futures and merge their results together to get a result in a for comprehension, the correct approach is to (a) first create the futures, (b) merge their results in a for comprehension, then (c) extract the result using onComplete or a similar technique.

“If you speak and act with a pure mind, happiness will follow you as a shadow clings to a form.”

~ from the Kung Fu tv series

Android FAQ: When is the Android Fragment onCreateOptionsMenu method called?

I was just working through a problem with an Android Menu and MenuItem, and added some debug code to the methods in my Android Fragment, and found that the onCreateOptionsMenu method is called after onStart. I didn’t put Log/debug code in every activity lifecycle method, but for the ones I did add logging code to, the specific order of the fragment method calls looked like this:

When is the Android Fragment onCreateOptionsMenu method called?

After 84 days, the Sun finally set in Barrow, Alaska (now known as Utqiaġvik) on August 2, 2017.

(Image from this Twitter page.)

The Sun finally sets in Barrow, Alaska

Apparently there’s a honey badger roaming around the University of Colorado campus in Boulder. For more information, see the DailyCamera.com.

A honey badger at the University of Colorado

“It is the sign of a great mind to dislike greatness, and to prefer things in measure to things in excess.”

~ Seneca

“Your attitude is such an important topic, I want to end this book by getting you to look at yourself the way other people see you.”

A quote from the last chapter of my book, A Survival Guide for New Consultants.

Here’s one of my favorite lessons from my consulting book, titled “Who are your customers?