I didn't feel like going out in the rain and snow yesterday here in the Boulder, Colorado area, so I decided to stay indoors and create a video introduction to the Scala REPL and the Scala variable types, var and val. Without any further ado, here's the video:
Scala, Java, Unix, MacOS tutorials (page 327)
With Apple's iPad 3 announcement coming tomorrow (March 7, 2012), I took a few minutes last night to reflect on various Jonathan Ive interviews I've read over the years. Here are a few notes on what I learned by reading those interviews.
1) Invest in great tools
Jonathan Ive often talks about how the Apple design team doesn't have a lot of things you might expect, but they do have great "tools". In his case, that means great tools for prototyping, presumably fabricating different hardware designs.
Perl date FAQ: Can you share a Perl date example where you print a date in a decent human-readable format?
Update: Be sure to look at the comments below for some great Perl "one liners", i.e., one-line solutions to this problem.
In this blog I'll share the source code for a Perl program that takes nagios.logrecords as input, then outputs the records with a human-readable date format. More specifically, the input records look like this:
Just a quick note tonight that my new book, Scala Cookbook, will be coming soon. The book is being published by O'Reilly, and you can see preliminary information about it on their Scala Cookbook page.
Here's what the cover looks like:
So what I learned tonight is that the Stack Overflow (SO) website has copied my content almost 800 times without linking back to my website once. This image shows the Google search results:

Java String comparison FAQ: Can you share some examples of how to compare strings in Java?
If you’re like me, when I first started using Java, I wanted to use the == operator to test whether two String instances were equal, but that’s not the correct way to do it in Java.
Perl getopts FAQ: Can you demonstrate how to use the getopts function? (Also written as, "Can you demonstrate how to read Perl command line arguments?")
Since I changed devdaily.com to alvinalexander.com, I've received several emails from people saying they're interested in buying the devdaily.com domain name. All I can say is that if you're interested in buying it, using the contact form here to contact me and make me a solid offer. I'm pretty sure that if the offer is $1M (one million dollars, US currency) or more, you'll get my attention. Otherwise I'll probably put it up for auction next year, and at that time you'll be bidding against a lot of other people.
I just ran into a situation for a Drupal/PHP client where I wanted to log some access information. There was some unusual access activity on the website, and I want to log IP addresses and URLs for a few days.
As part of that, I wanted to get the web client's IP address, and in PHP you get the client IP address like this:
$ip = $_SERVER['REMOTE_ADDR'];
That returns something like this:
192.168.100.10
If you just need to get a web client's IP address from a PHP script, that's all you need.
When you want to create a Play Framework template function, you can find some examples on the Scala Templates page. There you'll find these first two examples.
First, assuming you have a Product model defined something like this:
case class Product(var name: String, var price: BigDecimal)
The first template looks like this:
To handle 404 and 500 errors in the Scala Play Framework 2, you need to create a Global.scala object in your main app directory. The object should extend GlobalSettings, and override the necessary methods.
The following example Play Framework Global object, saved as app/Global.scala, demonstrates this:
The Play Framework scala.play.api.data.Forms object provides form validation helpers (which I've also seen referred to as mappings, data manipulation helpers, and constraints) such as these:
A cool thing about Scala sets -- and some other Scala collections -- is that you can easily determine the union, intersection, and difference between two sets. The following examples demonstrate how the methods work. First, we create two sets that have a slight overlap:
scala> val low = 1 to 5 toSet low: scala.collection.immutable.Set[Int] = Set(5, 1, 2, 3, 4) scala> val medium = (3 to 7).toSet medium: scala.collection.immutable.Set[Int] = Set(5, 6, 7, 3, 4)
Now we exercise the methods. First, the union:
Scala Array FAQ: How do I merge two Arrays or ArrayBuffers?
Solution: Use the ++ method to join two arrays into one new array:
scala> val a = Array(1,2,3) a: Array[Int] = Array(1, 2, 3) scala> val b = Array(4,5,6) b: Array[Int] = Array(4, 5, 6) scala> val c = a ++ b c: Array[Int] = Array(1, 2, 3, 4, 5, 6)
ArrayBuffer
Use the same approach to merge two ArrayBuffers into a new ArrayBuffer:
It took me a few minutes to figure out that when you want help on Play Framework console commands (i.e., the Play command line tool), you may get more useful help by typing help play instead of just help. Using the first command shows information on commands like clean, compile, console, etc., which is what I'm more interested in.
To take a quick look at this, here's what you get when you type help play:
MySQL DATE syntax FAQ: How do I set a MySQL DATE field to default to "now", i.e., the current time?
Setting the date to "now"
Unfortunately you can't default a MySQL DATE field to "now", but you can get the "now" behavior with a MySQL TIMESTAMP field. The syntax to create a MySQL TIMESTAMP "now" field is:
Here's a quick example of how to use a map function call on a Scala collection in a Play Framework template:
Git SSH repository FAQ: How do I set up a private Git server on a remote ssh server, such as an A2 Hosting web server? (i.e., how do I create my own private SSH Git repository on an A2 Hosting server?)
I just created a new domain on an A2 Hosting web server, and one of the reasons I chose A2 is because they offer/allow Git hosting, specifically Git hosting over SSH.
If you’ve never set up a private Git repository over SSH, well, fear not, me either. But, I just got it done, and here’s how I did it.
Just a quick note today that while I've been busy working on my next book (which will be printed by a major publisher), I just noticed that sales of my last eBook, "You Want Me to Do What? A Survival Guide for New Consultants", have really picked up.
