Harley Davidson motorcycle ad - What would you do?

A great Harley-Davidson motorycle ad: What would you do?

Scala - How to declare multiple variables on one line

I thought I’d have a little fun today, and show different ways to declare multiple variables on one line. These aren’t the most useful or common things to do, but they’re interesting, and I know I learned at least one thing while looking into this.

You can define multiple fields on one line, separated by commas, as long as they are all the same type and have the same value:

Web design - If you watch, if you help

A famous and funny, “If you watch, if you help,” web design cartoon. From the book, The Non-Designer's Design Book.

Buddha said, 'Do not dwell in the past'

Buddha said, “Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.”

~ Michael Clark Duncan

MySQL syntax examples - create table, primary key, foreign key

Just a quick note here today that if you need some example MySQL database tables, you can use these. I created them for some experiments I ran last night. They show the MySQL create table, primary key, and foreign key syntax:

I am open to the guidance of synchronicity - The Dalai Lama

“I am open to the guidance of synchronicity, and do not let expectations hinder my path.”

~ The Dalai Lama

Spock vs Spock - Audi commercial

This is great:

Scala file reading performance - Line counting algorithms

Out of curiosity about Scala’s file-reading performance, I decided to write a “line count” program in Scala. One obvious approach was to count the newline characters in the file:

// took 101 secs (10M lines)
// work on one character at a time
def countLines1(source: Source): Long = {
  var newlineCount = 0L
  for {
    c <- source
    if c.toByte == NEWLINE
  } newlineCount += 1
  newlineCount
}

As the comment shows, this took 101 seconds to read a file that has 10M lines. (An Apache access log file for this website.)

Scala zip and zipWithIndex examples (with Stream)

I’ve known about using the Scala zipWithIndex method for quite some time. I’ve used it in for loops to replace counters, and it works like this:

scala> List("a", "b", "c").zipWithIndex
res0: List[(String, Int)] = List((a,0), (b,1), (c,2))

I learned about using zip with Stream last night while reading Joshua Suereth’s book, Scala In Depth. It works like this:

Are you familiar with Sun Tzu?

“Are you familiar with Sun Tzu?” (Michael Clarke Duncan, The Finder)

Syndicate content