My thoughts as Apple’s iPhone celebrates its 10th anniversary

A few days ago the iPhone celebrated it’s 10th anniversary.

I was at T-Mobile when the iPhone was announced. Now mind you.. I had been – like many other Steve Jobs fans – been following news and rumors out of Apple for months: The various patents being filed, rumors of a iPod with a full touch screen, etc. All of the rumors pointed to a phone. I had only been a T-Mobile a couple of months when the product launch happened. When the unveiling occurred in this huge media event that Steve loved to hold I looked at my boss, Shawn and said; “So when are we carrying it?”

“We’re not”; Shawn said.

I’ve never told Shawn this, but I almost put my badge on her desk that day and walked out of the building…

Continue reading “My thoughts as Apple’s iPhone celebrates its 10th anniversary”

HOWTO: Use IdentD with OSX Yosemite

If you’re an Internet Relay Chat (IRC) user like me, you’re probably familiar with or at least have heard of an identd service. IdentD is simply a service that, when accessed on port 113 of a computer, returns a simple string that identifies you as a user. If you were to watch the traffic you’d see something like this

1234,6578 : USERID : UNIX : itsmemario

Most OSX IRC clients don’t support this feature, and very few (if any) IRC servers require it any more. For those who needed this in the past, there was Identd for Mac. Which created a simple and functional icon in MacOS:


However in OSX Yosemite IdentD for Mac stopped working. The original author, Gallerand Sebastien, stepped up and made a new version. I’ve translated (as best as I could) his article and made a copy of his code here. So far it works great.

For those using the old IdentD

If you had previously installed identd, remove the old version:

# Clean Up !!!
sudo killall identd
sudo rm -R /Library/StartupItems/IdentD
sudo rm -R /Library/PreferencePanes/IdentD.prefPane
sudo rm -R /usr/local/identd

Now you’re ready to set up the new IdentD as a service.

Download, extract and set up IdentD

1- Download the file identd

2- Extract it to the desktop and you get a folder named identd.

Now the fun part.. installing stuff!

3- These commands will copy identd to the proper location and start it up

# Prepare
sudo mkdir -p /usr/local/identd
sudo chown root:wheel /usr/local/identd

# Install
cd ~/Desktop/identd/
sudo cp ./identd /usr/local/identd/
sudo cp ./identd.conf /usr/local/identd/
sudo cp ./org.macmax.identd.plist /Library/LaunchDaemons/
sudo chown root:wheel /usr/local/identd/identd
sudo chmod 755 /usr/local/identd/identd
sudo chown root:wheel /usr/local/identd/identd.conf
sudo chmod 644 /usr/local/identd/identd.conf
sudo chown root:wheel /Library/LaunchDaemons/org.macmax.identd.plist
sudo chmod 644 /Library/LaunchDaemons/org.macmax.identd.plist

# Load & Start
sudo launchctl load /Library/LaunchDaemons/org.macmax.identd.plist
# identd will start on boot up now.

4- Now test to see if identd is running

# Try :
ps aux | grep identd | grep root

# should report a process belonging to root
# root 1393   0.0  0.0   861896   7012   ??  Ss   Sat07PM   0:01.79 /usr/local/identd/identd

5- Now let’s send a test ident call to the service

# type this at your terminal prompt :
telnet localhost 113

Which should return something like this:

Trying ::1...
Connected to localhost.
Escape character is '^]'.

You can enter something like this:

# Type the following and press Enter :

If all went well you’ll be greeted with this response, and you’re good to go!

1234,5678 : USERID : UNIX : JohnDoe

Connection closed by foreign host.

Customizing the User name

Let’s say you want a name other than JohnDoe.. NO problem.. the following lines would take care of that nicely

# Change name to YourNameHere
sudo sh -c "echo 1:YourNameHere > /usr/local/identd/identd.conf"
sudo launchctl stop org.macmax.identd

And you’re done!

Download the file

Link to original code and article at (in French)

Fixing “XMLGregorianCalendarImpl is internal proprietary API and may be removed in a future release”

While running builds I noticed the following warning from Maven..

XMLGregorianCalendarImpl is internal proprietary API and 
may be removed in a future release 

Rightfully so if you’re not using the correct convention for this..

type.setDate(new XMLGregorianCalendarImpl());

A quick look at Stackoverflow shows this:

In short you need to leverage a factory pattern and get an instance of the underlying implementation. The following snippet is an example of this:

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.datatype.DatatypeFactory;
import java.util.GregorianCalendar;
private XMLGregorianCalendar now;

now = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar());

And your code will be in better shape and future-proofed as well.

Scripts to select the default Java version on MacOS

Thanks to I found a neat trick to make it easy to list your installed Java versions and switch between them. Just add these to your .bashrc file:

alias java_ls='/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.\d[,_]" | cut -d , -f 1 | colrm 1 4 | grep -v Home'

function java_use() {
    export JAVA_HOME=$(/usr/libexec/java_home -v $1)
    export PATH=$JAVA_HOME/bin:$PATH
    java -version

The java_ls command reduces the output of java_home -V to just return the version numbers and java_use is just a shortcut for the exports and path updates you’d normally use.

Shellshock Exploit – Manually patching BASH

Recently the events concerning the Shellshock exploit have been all over the media. This one is bad.. real bad:

Remote exploit vulnerability in bash CVE-2014-6271

However it’s entirely possible that your Linux distribution might not have a patch readily available if say, you’re running an older linux distro like Ubuntu 8.0.4

Fear not.. building and installing your own patched version of bash is fairly straightforward, presuming you have GCC and build tools installed with your distribution. If you’re comfortable building code you can do the following:

#assume that your sources are in /src
cd /src
#download all patches
for i in $(seq -f "%03g" 0 25); do wget$i; done
tar zxvf bash-4.3.tar.gz
cd bash-4.3
#apply all patches
for i in $(seq -f "%03g" 0 25);do patch -p0 < ../bash43-$i; done
#build and install after retrieving and patching the bash build files
sudo ./configure --prefix=/usr --bindir=/bin --sbindir=/sbin --sysconfdir=/etc && sudo make && sudo make

Here’s a link to the original discussion on this over on Hacker News

Setting up mail support in your Grails application

At some point in your Grails application development you’ll find yourself invariably needing your application to send mail.  With the Grails mail plugin, it’s a snap.  Essentially the mail plugin is a wrapper to configure a Spring MailSender instance.  And the Spring MailSender is a wrapper to the JavaMail API. As long as you know about these libraries and implementation details, using Grails mail is pretty straightforward.  First start by adding following dependency reference to your plugins section of your project’s BuildConfig.groovy file:

    plugins {
        //.. other plugs 
        compile ":mail:1.0.1"

You can also use the “standard” approach to install the plugin as well:

grails install-plugin mail

Next you need to configure the mail plugin to know what smtp server to use in Config.groovy:


grails {
    mail {
        host = "mail.yourdomain"
        port = 25
        props = ["mail.smtp.from":"david.orrissjr@yourdomain"]

The ‘props’ section can be populated with any of the properties defined in the JavaMail API to leverage the various SMTP features.  Take note to be very careful with them and read the RFCs on the SMTP protocol before you attempt to use something you aren’t familiar with.

Finally a simple call in your controller to the sendMail method that you provide a closure for is all that’s needed to send an email.

class MailSendController {

    def sendMessage () {
        sendMail {
            to "davido@yourdomain"
            subject "Hello from the sendmail plugin"
            body "Hello from the sendmail plugin.  Here's the email you wanted."

        render "EMail sent."



There are plenty of other ways you can leverage the mail plugin as well.  You can find more details on the grails mail plugin page:

And the Mail Plugin documentation page:

To see what other features you can leverage you should also read about the JavaMail plugin itself and the SMTP properties that can be set in the JavaMail session object.  You can find out more about that subject here:

Grails and Legacy Data – Composite Keys in your Tables

When developing a Grails app, you don’t always have the luxury of using GORM (the Grails ORM) ‘out of the box’ against new schemas. Sometimes you just have to work with legacy data as you get it with little modification (if any). Today I’m going to show some of the tricks/traps for working with legacy data when creating a new grails application. There are a few pitfalls that aren’t well-documented with the help of this article you should be able to avoid them.

Mapping Metadata to your Domain Class

GORM is really powerful, but it imposes its own “world view” on table and metadata structures. That can be fine when you start from scratch on a new application. But what happens when you have data that doesn’t match that world view? You could consider revising the table structure and impact all of your other applications. Or you can simply structure your Grails domain class to fit the data you’re working with.

Consider the following table. For this example I’m using MySQL but any popular SQL server  would work:

CREATE TABLE `application_config` (
  `CONFIG_NAME` varchar(128) NOT NULL,
  `KEYNAME` varchar(128) NOT NULL,
  `VALUE` varchar(1024) NOT NULL,
  `DESCRIPTION` mediumtext,
  `VERSION` decimal(10,0) NOT NULL DEFAULT '0',

This looks simple enough, but Grails will puke on it if you try to use it as-is for a couple of reasons:

  • GORM wants an auto-incrementing large integer field called ‘id’ to be the primary and unique key for the table. A primary key is required by GORM and quite frankly you shouldn’t even bother doing work in SQL databases if you’re not going to use them.
  • GORM also wants a version field for managing changes via optimistic locking. This isn’t a requirement, but I’d strongly recommend adding this field to your tables. Even a simple non-null field defaulting to a value of ‘1’ would be sufficient and your grails app will be more robust for it.

According to the Grails documentation there is support for Composite Primary Keys.  From their website:

GORM supports the concept of composite identifiers (identifiers composed from 2 or more properties). It is not an approach we recommend, but is available to you if you need it.

They aren’t kidding.  They not only don’t recommend it but they don’t document very well how to do it, either.

First step is to create your domain class.  For this we’ll call it AppConfigInfo:

grails create-domain-class AppConfigInfo

After being greeted with your empty domain class, lets start adding the data members that will be mapped to the database:

class AppConfigInfo implements Serializable {
	String configName
	String propertyName
	String propertyValue
	String description
	Date updated

	static constraints = {

I’ve added the reference to implements Serializable because as we add the rest of the mapping information to the class serialization will be required.

The next thing we need to do is configure constraints for the table.  While not required I’d strongly recommend it.  This way you don’t have issues with your primary key having blank entries.

 * basic constraints to specify the field order. needed when
 * views are generated for the controller
 static constraints = {
	configName (blank:false)
	propertyName (blank:false)
	propertyValue (blank:false)
	description (maxSize:80)

Now we’ve enforced basic input validation, but we still need to map the data attributes of this class back to the columns in the table. That’s what the mapping block is for:

 * this mapping configures the columns to match up to the legacy
 * database table.
static mapping = {
	// this line will disable the version number support required
	// for GORM optimistic locking.  comment out or remove
	// if you want to support locking (recommended, not required)
	version false
	id composite:['configName','propertyName']
	//maps the columns to the properties in the domain
	columns {
		configName column:'CONFIG_NAME'
		propertyName column:'KEY_NAME'
		propertyValue column:'VALUE'
		description column:'DESCRIPTION', type:'text'
		updated column:'LAST_UPDATED'


Note the columns block above. That’s the final piece for the mapping. With that block, grails knows which fields will be mapped to your legacy table. That leaves us with only a couple other lines tasks left. We need the code to handle the field called updated and the code to return the composite key to your controller. Also if you have two different fields for creation and update timestamps instead of one, you can skip the handling code below and just write the code that returns the primary key:

//if you have separate columns for created and updated timestamps
//you can skip this code and map the above columns accordingly
//most of the time in my experience, schemas have only one column for this
def beforeInsert = {
	updated = new Date()
def beforeUpdate = {
	updated = new Date()
def getPK() {
	["configName":configName, "propertyName":propertyName]

At this point if you got the idea that you could just generate a controller and use the built-in dynamic scaffolding like this to test out the design so far:

class ConfigureController {
    def scaffold=AppConfigInfo

It’ll sort of work, but you’ll have some hiccups. For example: you will be able to create new records like this

Grails Create Screen1

But you won’t be able to edit the entry because the scaffold only recognizes the GORM model of using the standard ‘id’ unique key. Note the empty column for ID:

Grails List Screen1

This fix for this requires generating the full set of views and the fully implemented controller. From there we can modify the views and controller to do what we need. Besides, you’d never actually use the dynamic scaffolding for any real work, anyway

grails generate-all AppConfigInfo

There’s a few other things that have to be updated also. We’ll have to replace the code that supports the GORM id field with code that enables the use of our composite key. When you try to start your application, list will work but clicking the ‘Details’ link generate exceptions like this:

Error 500: Executing action [show] of controller [example.AppConfigInfoController] caused
 exception: groovy.lang.MissingMethodException: No signature of method: example.AppConfigInfo.getPK() 
is applicable for argument types: (org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap) 
values: [[propertyName:english.language.error.expired.password, configName:I18N, action:show, 
controller:appConfigInfo]] Possible solutions: getPK(), getId(), get(java.lang.Object), 
getAt(java.lang.String), getAll(), getLog()

On the bright side, create may just work for you immediately so that’s at least one area you’ll be able to leave alone. Fortunately, Grails actually is attempting to give you a hint on how to resolve this as well with the following line:

Possible solutions: getPK(), getId(), get(java.lang.Object), 
getAt(java.lang.String), getAll(), getLog()

The use of get(java.lang.Object) is the hint. Note that your controller for the ‘show’ action has a line like this:

def appConfigInfoInstance = AppConfigInfo.get(

In order to leverage the composite key we’ll need to modify two files, the controller and the views for the show and list actions. First change your controllers show action to something like this:

def appConfigInfoInstance = AppConfigInfo.get(new AppConfigInfo(params))

This fulfills the contract suggested by grails stacktrace.

Next the view for the list action (list.gsp) has to be modified so that we can click on the “Details” link and correctly load the show action. Modifying the line shown below is the trick:

<g:each in="${appConfigInfoInstanceList}" status="i" var="appConfigInfoInstance">
    <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
        <td><g:link action="show" id="${appConfigInfoInstance.getPK()}">Details</g:link></td>


Changing the id attribute to a params attribute bridges the gap to the controller:

<g:each in="${appConfigInfoInstanceList}" status="i" var="appConfigInfoInstance">
    <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
        <td><g:link action="show" params="${appConfigInfoInstance.getPK()}">Details</g:link></td>


Next, we need to modify the views for Edit and Delete. Let’s tackle Edit first. GORM supports optimistic locking via a numeric “version” field for tables that are set up to support it. For this demo we’ve disabled it. So change edit.gsp from this:

<g:form method="post" >
    <g:hiddenField name="id" value="${appConfigInfoInstance?.id}" />
    <g:hiddenField name="version" value="${appConfigInfoInstance?.version}" />

To this:

<g:form method="post" >
    <g:hiddenField name="id" value="${appConfigInfoInstance.configName}" />
    <g:hiddenField name="value" value="${appConfigInfoInstance.propertyName}" />

To complete the change we also need to the show.gsp view:

<div class="buttons">
        <g:hiddenField name="id" value="${appConfigInfoInstance?.id}" />
        <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
        <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>

To reflect the composite key as shown:

<div class="buttons">
        <g:hiddenField name="id" value="${appConfigInfoInstance.configName}" />
        <g:hiddenField name="value" value="${appConfigInfoInstance.propertyName}" />
        <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
        <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>

For the sake of completeness I’ve also included the sample code from my application here. This application was built in SpringSource Tools Suite – if you use the same toolset you should have no problem importing it and playing with it.

Grails is a powerful framework, geared toward maximizing web application productivity in the Java ecosphere. With a few adjustments you can leverage this powerful framework in a variety of situations.

Reversing a String in Java

Today I’m going to go ‘back to basics’ a bit and talk about string manipulation in Java. In particular, let’s talk about reversing a string. Something that is taught in every 100-level computer science class. The premise is simple enough. Take a string as input, return a string with the sequence of letters reversed.

So that means:


Is turned into:


Reversing a string is simple enough: Starting from the end of the source string take each character and append it to a new string. When you have reached the beginning of the source string return the result. It’s the approach you take that determines if you really know your Java coding, however.

In Java, the String object is immutable. This means that you cannot change it. And making a ‘change’ to a string actually creates a new string and disposes of the old one. Consider the following:

	String input = "FOXTROT";
	String s = "";

	for (int i= input.length(); i > 0 ; --i ) {
		s = s + input.charAt(i-1);

Or rather what the Java compiler will actually turn the above code into:

	String input = "FOXTROT";
	String s = "";

	for (int i= input.length(); i > 0 ; --i ) {
		s = (new StringBuilder()).append(s).append(input.charAt(i-1)).toString();

(Be thankful you don’t actually ever have to write that out yourself)

New strings are created for each iteration. One that will include all the characters from the previous iterations plus a new string that represents the current letter in your input variable. The previous version of the string and the character that was converted into a string are flagged to be garbage collected until the final result, “TORTXOF”, is created.

So you might think that’s not so bad. Just a few bytes, right? But if you do something like this when you’re parsing files with thousands of lines of text, it can add up fast. And when you build up a lot of objects for flagging for garbage collection you cause the JVM’s garbage collector to invoke more often, affecting your performance of your software and the scalability of the software you’re creating.

A more memory-savvy approach is to leverage the StringBuilder class. You can also use the StringBuffer class, which is synchronized and used if you need to write something that is thread-safe (which is a completely different topic). StringBuilder, since it’s not synchronized, has the benefit of also being faster.

So taking this into account the above code would look something like this:

	StringBuilder sb = new StringBuilder();
	String input = "FOXTROT";
	String s = "";

	for (int i=input.length(); i > 0 ; --i ) {

	s = sb.toString();

In this example, we’re down to two string objects: One for the input and one result. Far less GC will occur. Less overhead and work for the JVM and better scalability for your application.

The complete class shown for this example is below. Java is definitely a language that’s geared toward programmer productivity. But learning *how* the Java language itself works makes sure that you leverage it for maximum machine productivity as well.

package com.codethought.java101;

 *	Simple string reverse utility class.  If you want to learn more about all the fun
 *  things you can do with String manipulation in Java I've provided the link below.
 *  Note the use of a StringBuffer.  Strings are immutable.
 *  Meaning that if you change one - say by catenation - the previous version gets
 *  sent off to GC (garbage collection).  To minimize impact to GC, StringBuilders 
 *  can be used to create the string you need (since they're mutable).  When you 
 *  are done, you just call toString() on the builder and call it good.  You can find more out
 *  at:
 *  @author David Orriss Jr

class StringReverser  {

     * Reverses the string given to it.  
     * @param 	input 	the string to be reversed
     * @return null if null string is sent, the exact input for short strings, or the reversed string
	public String reverse (String input) {
		StringBuilder sb = new StringBuilder();
		//defensive coding in the event someone tries to use a null string
		//you could also just let an NPE trigger.  personal choice
		if (input==null) {
			return null;
		if (input.length()<2) {
			return input;
		//strings are zero-based (see referenced docs for details).
	    //subtract 1 in the call to charAt, decrement to 'step back' 
		//down thru the string.
		for (int i=input.length(); i > 0 ; --i ) {
		return sb.toString();

Ruby 1.9, TextMate and Segmentation fault errors

While tinkering with Ruby 1.9 in TextMate I found that Ruby was segfaulting on the TextMate Ruby Bundle output screen.

/Users/codethought/Applications/ [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]

Turns out you can fix the error yourself… as I found at

To quote here:

Edit the catch_exception.rb file in your Ruby bundle in TextMate. To get into it on my machine I had to do:

mate Applications/

Then, comment out the require “cgi” line. And then remove all references to CGI::escapeHTML.

But a simpler way is to go is to download the change that someone else made from github and install it yourself.

And put the new version catch_exception.rb in the following directory yourself:


And your problem will be resolved.