MySQL how to display the character set for a table

Needing the character set details on various tables within a MySQL Database:

SHOW TABLE STATUS

Have a look the MySQL documentation: http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html

Executing a class using the Maven Exec Plugin

Today, in a java maven built webapp, I needed to have a way to execute a class from the commandline. As maven was already building package into a war, I needed something extra.

Bring in the Maven Exec Plugin: http://mojo.codehaus.org/exec-maven-plugin/index.html

Pretty useful as I was able to define a specific profile for this class and now execute it by:

mvn compile -P run_my_class

Have a look at the documentation.

Also a good quick overview is provided by http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven

Java SimpleDateFormat Example

I keep forgetting the exact syntax of the SimpleDateFormat. The below example passes in a month value say “02″ and returns “February”.
However this can work to transfer any date format into another format.

Refer to the Java 7 doc for the Date and Time Patterns


import java.text.SimpleDateFormat;

public String formatMonth(String month) {
SimpleDateFormat monthParse = new SimpleDateFormat("MM");
SimpleDateFormat monthDisplay = new SimpleDateFormat("MMMM");
return monthDisplay.format(monthParse.parse(month));
}

formatMonth("2");
Result = February

Finally Java gives us a switch on a String

I haven’t really paid much attention to the new features in Java 7. But at the Canberra Java User Group meeting last week a presentation was given on the new features of Java 7. It was actually quite interesting, especially the history bit … but the take home was the ability to use a String with the Switch statement. Definitely in the “About time” category. It has been one of those pet peeves that I just had to accept. (This was especially apparent when working on Java code after doing a few projects in Ruby.)

For example:

String color = "red"; 

switch (color) {
case "red":
	System.out.println("Color is Red");
	break;
case "green":
	System.out.println("Color is Green");
	break;
default:
	System.out.println("Color not found");
}

Code4Lib 2009

In 2009 I attended the Code4Lib Coneference hosted at Brown University.

I presented on RESTafarian-ism at the NLA. Click on the link see the slides and video.

“Two years ago the National Library of Australia decided to go the route of SOA, particularly REST web services. Since then we have developed a stack of them for varying projects. This talk will expose a few of those services (that provide MARCXML, MODS, METS, Identity information and Copyright Status), highlight some of the technology choices and give some idea of the success of this approach.”

It was really fun to hang out with fellow developers from the Library domain. The Code4Lib community is rather interesting too.

Rails / Ruby DateTime Stuff

A great blog entry: http://anandmuranal.wordpress.com/2007/12/12/formating-date-time-in-rails/

Rails update a gem to an older version

You want say rack version 1.0.1 but the latest version is rack 1.1 and it’s installed on your machine:

gem install [gem name] –version [version number]

For example:
gem install rack –version 1.0.1

Getting Threads in Rails

So you want threads in rails? Add the following 2 lines to your production.rb file:

config.threadsafe!
config.eager_load_paths << “#{RAILS_ROOT}/lib”

For more reading, checkout: http://m.onkey.org/2008/10/23/thread-safety-for-your-rails

Rails: Unpacking your gems into vendor/gems

Okay you have your marvelous gem but want to put it into the vendor directly.

No worries. In this example I will be working with the “marc (0.3.0)” gem.

  1. Edit the environment.rb file and under the “Rails::Initializer.run do |config|” put the following line: config.gem ‘marc’
  2. Next “rake gems:unpack GEM=marc” where GEM=gem_name – don’t worry about the version number.

All done. You should have a new directory under vendor/gems/gem_name.

Troubleshooting. If this doesn’t quite work, you might want to try:

  • Create the gems directory under vendor yourself
  • It may complain that it lacks the specification file. If so go to the vendor/gems/gem_name directory and run: gem specification gem_name > .specification

If this still doesn’t work … then google or bing yourself to death.

Viewing RDoc for installed gems

Pretty simple:

gem server

It’s then available on localhost:8808

Pretty cool. It’s like having available doc for JAR files. Sort of.