Scala, Java, Unix, MacOS tutorials (page 339)

I've recently started writing a series of articles on Design Patterns in Java, i.e., Design Patterns explained using Java source code examples. Although it will take me a little while to create each design pattern example, this page will eventually contain links to all of those examples.

If you're not familiar with software design patterns, they're described on Wikipedia like this:

[toc hidden:1]

Summary: A discussion of the Strategy Design Pattern using Java source code examples.

The Strategy Design Pattern consists of a number of related algorithms encapsulated in a driver class often named Context. A user or a client program typically selects the algorithm they want to use, although the Context class may also select the algorithm automatically.

The intent of the Strategy Pattern is to make the algorithms easily interchangeable, and provide a means to choose the appropriate algorithm at a particular time.

I was just searching for a good description of Guy Kawasaki's DICEE acronym --  it stands for Deep, Indulgent, Complete, Elegant, Emotive -- and found it surprisingly hard to find online. So, to help with that problem, here's a brief take on what Mr. Kawasaki's DICEE acronym means, along with a link to his website.

As I embark on two new PHP web applications that have a lot of charting and graphing needs, I've started to dig into the PHP charts and graphs world. I'm pleased to say there are several nice, free PHP charts and graphs tools available, and several commercial PHP charting/graphing tools as well. Here's my quick review of the current PHP charts and graphs tools.

Java file FAQ: Can you share some examples of the Java BufferedReader class?

When it comes to reading character input streams, the Java BufferedReader class is extremely important, and I'll demonstrate this in several different source code examples.

[toc hidden:1]

In case you need a sample .bash_profile startup file for your MacOS or other Unix/Linux system, I thought I’d share my most recent version here.

If you're not familiar with a .bash_profile file, this is a startup file that is read whenever you open a new Terminal window. It's a special configuration file, and it needs to be placed in your home directory. For instance, on my MacBook Pro, this file is located as /Users/al/.bash_profile.

Unix and Linux aliases are a really nice way of customizing the command line to work the way you want it to work. With alias commands, you're essentially doing a little programming, and creating new Unix and Linux commands custom-tailored to the way you work. You can create aliases to use instead of existing commands, and you can also create aliases as Linux command pipelines.

This morning I decided to take a few minutes to backup all the songs I've purchased over the last half-year. These are all on my Mac OS X system, under the Music folder in my home directory.

The problem with trying to do this with standard Unix tools is that all these subdirectories and filenames have spaces in their names. Just looking at the Music folder, it contains many directory names like this:

Summary: This document is a Scala cheat sheet (reference page), in HTML format.

This page is very much a work in progress, but as I've been learning Scala, I've been creating all sorts of little notes, and I'm now trying to organize them into this Scala cheat sheet. These notes are based on the excellent books, Programming in Scala (Odersky, Spoon, and Venners), and Programming Scala (O'Reilly).

[toc hidden:1]

Summary: This brief tutorial shows Scala import statement syntax examples.

I was just trying to develop a little Java/Swing application in Scala, and right away I ran into the problem of how to import Java classes and packages into a Scala application. 

In short, the following code shows how to import a Java class into a Scala application:

Looking for a Ruby on Rails like approach for Drupal 7 form and module development? If so, I may have just the tool you're looking for.

As you can see in the video below, I show how I can generate Add, Edit, Delete, and List forms for a Drupal 7 project I'm working on in four minutes, or one minute per form. Of course there's a little more work to be done, but the code-generating approach I've taken is exactly what Ruby on Rails and CakePHP did the last time I used them.

Drupal form FAQ: How do I get default input focus on a Drupal form field (presumably a form textfield)?

There may be a better way to do this, but here's what I just did to get default input focus on a series of Drupal form 'add' and 'edit' pages. I just included the following Drupal form suffix definition on any form where I wanted to control the default input focus:

While developing a Drupal module, I just ran into a situation where it may be common for users to generate SQL exceptions. I have a 'unique' limit on several of my database tables, essentially saying that certain name fields must be unique for the current project. As you can imagine, it's extremely easy to enter a duplicate name, and while doing a SQL INSERT that can easily lead to a SQL exception.

As a result, I dug around and found a way to handle SQL exceptions in Drupal queries. My current problem is with a Drupal 7 db_insert query, and I handled it like this:

I finally dug into a problem with TextMate that has been driving me crazy. I always have the TextMate "soft tabs" feature enabled, and want two spaces wherever there was a tab. However, it turns out TextMate doesn't really do what I expect here. Instead of automatically converting tabs to spaces, you have to take an extra step to make this work.

Assume you've just opened an existing document. To convert the tabs in the document to spaces (soft tabs):

Shortly after writing my Arduino Uno Hello, World example, I read my documentation a little more, learned that Pin 9 on the Arduino Uno board is an analog pin, switched the LED wire to that pin, and created the following program, which slowly lights up the LED using an analog programming approach, and then fades the LED light out.

Here's the source code for my LED fade sketch:

Last night I finally got some time to work with my new Arduino Uno board, and created a little "Hello, world" program. This program is just the same "LED on Pin 13" program I see repeated in every book and on every website, but it really is helpful when you're struggling to get started with the Arduino hardware, like I was.

I'm currently developing a new Drupal 7 application (technically built as a new Drupal module), and as I'm building the application, I've made notes on database queries I've made.

The approach I'm taking is to use the following Drupal SQL query functions. As you can see from the function names, there are now different Drupal functions for each query type:

[toc hidden:1]

Summary: This is a Git cheat sheet (Git command summary) I've created, featuring many Git command examples.

As I've begun to set up my own private Git hosting repository (see Private Git hosting services, and My A2 Hosting Git repository using SSH), it's time to cram all these Git commands back into my head again.

[toc hidden:1]

Today is organization day for me, and in an effort to organize everything I've ever written about a Java JFrame, here is a collection of links to all my Java JFrame examples and tutorials.

Java Swing clipboard FAQ: How do I copy an image to the clipboard in a Java/Swing application?

Last night I needed to do just this, get an image that I'm currently displaying in a Java JFrame, and copy that image to the clipboard. I won't discuss the solution here too much, other than to say that in the example source code below, a MetaFrame is a customized subclass of a JFrame, and when I call the getCurrentImage() function, it simply returns a Java Image type.

Here's the source code: