Skip to content

Category Archives: CodeSnippets

Quick command line spell check of a single word or sentence

Here’s a short bash script, using aspell, to spell check a word or several words from the command line. It’s simple but effective. If anyone else knows a cleaner or even simpler way, please let us know.

#!/bin/bash
WORD=$1
TEMPFILE=temp.spell
echo $WORD > $TEMPFILE
aspell -c $TEMPFILE
cat $TEMPFILE
rm -f $TEMPFILE
rm -f $TEMPFILE.bak

I named this script “spell”. Simply [...]

Dirt Simple EXTJS Grid on Grails

At my current contract, I’ve been using the popular EXTJS javascript library. In order to get up to speed faster, I’ve started a small project to assist my learning.
I thought about using a number of back ends to support my project, but decided on Grails after reading about the built-in JSON converters.
Getting started note: Since [...]

SVN Log History By User to HTML

Most SVN users who use the command line client understand how to create a log in XML format:

svn log –xml -v svn://some/url > svnlog.xml

But this dumps the whole log, and I really just want to see a specific user. Plus, I hate XML and definitely do not want to read it.
Here is a handy stylesheet:

<?xml [...]

A simple java.util.Date to java.sql.Date converter

If you’re using JSF and need a converter for converting UI elements (typically java.util.Date) to your domain object’s date field (typically java.sql.Date), here’s the code snippet,

public class DateConverter implements Converter, Serializable {
public Object getAsObject(FacesContext context, UIComponent component, String value) {
java.sql.Date sqlDate = null;
Calendar cal = null;

[...]

Extending Hibernate Validator for BigDecimal Range validation

Hibernate Validator is a very precise framework written in the hibernate umbrella of frameworks. Using the inbuilt validators should solve most of your column constraints. However, if you have Decimal types (Float, Double of BigDecimal), there is no inbuilt validator to validate both the precision and scale. Also, I’ve stopped using Doubles and Floats in [...]

Commons StringUtils Is Your Friend

I have just completed a test for a method that parses a forward-slash delimited String:

private static final String PROJECTID_STR_1 = "";
private static final String PROJECTID_STR_2 = "101/103/102/104/105/106/107";
private static final String PROJECTID_STR_3 = "///103/104";
private static final String PROJECTID_STR_4 = "a/b/102/104/105/106/107";

@Test
public void testParseProjectIds1() {
List<integer> projectIdList1 =
getViewBillingReportController().parseProjectIds(PROJECTID_STR_1);
assertTrue(projectIdList1.size() == 0);
}

@Test
public void testParseProjectIds2() {
List<integer> projectIdList2 =
getViewBillingReportController().parseProjectIds(PROJECTID_STR_2);
assertTrue(projectIdList2.size() == 7);
}

@Test
public void testParseProjectIds3() [...]

Step by Step Tutorials – DWR with Spring, Ajax – Dynamic drop down lists

Scenario: A simple jsp page with a standard drop down box. A Selection criteria (could be another drop down box and a couple of check boxes) to change the values in these drop down box dynamically, without submitting the page.
What you will learn:

Configure dwr.xml with spring beans
Configure application contexts for dwr beans
The basic structure of [...]

Example code, sending emails using Spring SimpleMailMessage, MimeMessagePreparator and Velocity Templates

When I first wrote my custom Email utlity 4 years back using JavaMail, it spread well over hundred lines of code. Looking at Spring’s out of the box functionality for sending Emails with attachements & velocity templates makes you wanna feel sorry for your old code. The reference doc by Spring for Email is quite [...]

Groovy CLIBuilder In Practice

Ok, it doesn’t get much easier than this to build a CLI:

class ContentUpdaterMain {

static void main(args) {

def cli = new CliBuilder(usage: 'java -jar contentupdater.jar -su[dh] "update name"')
cli.h(longOpt: 'help', 'usage information')
cli.u(longOpt: 'update', 'update the provided table', args: 1)
cli.s(longOpt: 'stage', 'stage the provided table', args: 1)
cli.d(longOpt: 'debug', 'run the process with debugging enabled')
def opt = cli.parse(args)
if(!opt) return

if(opt.h) [...]