alvin's blog

The Scala for loop translation scheme

If you're interested in the details of the translation scheme of a Scala for loop (for comprehension), here's a quick look at how a for loop is translated into, well, other code.

A simple Scala for loop

In a first example, we'll start with the following Scala class:

class Main {
  def foo { for(i <- 0 to 10) println(i) }
}

Next, I compile this class from the command line like this:

How much are you worth to your employer?

This is a short story from my book, A Survival Guide for New Consultants:

A long time ago -- 1991 to be exact -- a friend of mine named Joe was a contractor for the aerospace company I worked at. Just like a consultant, Joe was paid by the hour.

A collection of Scala flatMap examples

Scala flatMap FAQ: Can you share some Scala flatMap examples?

Sure. When I was first trying to learn Scala, and cram the collections' flatMap method into my brain, I scoured books and the internet for great flatMap examples. Once I had a little grasp of it I started creating my own examples, and tried to keep them simple.

Using flatMap on a list of String

The following examples show the differences between map and flatMap on a sequence of String:

20+ Unix/Linux find command examples

Linux/Unix FAQ: Can you share some find command examples?

Sure. The Unix/Linux find command is very powerful. It can search the entire filesystem to find files and directories according to the search criteria you specify. Besides using the find command to locate files, you can also execute other Linux commands (grep, mv, rm, etc.) on the files and directories you find, which makes find extremely powerful. 

How I started a multimillion dollar consulting firm

A friend of mine is currently unemployed, and as I've talked to her about ways to approach her situation, I'm reminded of how I started a consulting business named Mission Data.

A Java deep clone (deep copy) example

While interviewing for computer programming positions here in the Boulder, Colorado area, I've found that most interviewers ask questions about Java serialization. After being asked about serialization for the third time recently, I suddenly remembered an old Java deep clone hack that takes advantage of serialization.

The basic idea is this:

A letter to Future Me

Like many other people, during the months of December and January I reflect on the year that's passed, and come up with some goals for the next year. Over the years this has led me to:

Convert a Scala array to string with mkString

Scala collections FAQ: How can I convert a Scala array to a String?

A simple way to convert a Scala array to a String is with the mkString method of the Array class. (Although I've written "array", the same technique also works with any Scala sequence, including Array, List, Seq, ArrayBuffer, Vector, and other sequence types.)

Here's a quick array to string example using the Scala REPL:

The difference between DL-Phenylalanine, L-Phenylalanine, and D-Phenylalanine

Quick note: Since The Mood Cure helped me so much with my thyroid problems last year, I bought The Diet Cure, and have been reading through it. In short, the power of amino acids blows me away. While I've never felt any different after taking any other "supplements", the difference I've felt by taking amino acids has been amazing.

My Zen charity - The Zen Foundation

If you're thinking about giving to a charity this year, please consider giving to the Zen Foundation. Our organization has one simple purpose:

"The Zen Foundation will freely distribute classic Zen books to libraries, schools, healthcare facilities, and other locations where people can discover Zen."

With this mission, we hope other people will discover Zen in the same way we did: By stumbling onto one of the classic Zen texts, flipping through the pages, and beginning to wonder.

Syndicate content