formatting

Using sed to add a newline on Mac OS X

As a quick note today, I have been converting parts of the Scala Cookbook from a plain text format to a Markdown format, and as part of that I needed to add some newline characters to add spacing to the document. This wouldn’t be bad if it was a few pages, but it’s hundreds of pages, so I decided to use the Unix sed command to do the work.

Scala: Displaying XML in a human-readable format (pretty printing)

Problem: You have some XML in a hard-to-read format in a Scala application, and want to print it in a format that’s easier to read, at least for humans.

Solution

Use the scala.xml.PrettyPrinter class. To see how it works, imagine starting with a long, continuous string of XML:

Drupal 6 - The CKEditor is removing/deleting CODE tags

I had a problem using the CKEditor with Drupal 6 where the CKEditor would not display <code> tags properly in the editor, and would then delete trailing spaces after the <code> tag. After some digging around, I finally found that I needed to comment out the following line in the ckeditor.config.js of my CKEditor module installation:

The Scala String format approach (and Java String.format) alvin March 24, 2012 - 11:28am

Scala String formatting FAQ: How do I write code that is equivalent to the Java String.format class? That is, how do I format strings like that in Scala?

NOTE: As of Scala 2.10 this approach is a little out of date. You can still use this approach, but there's a better way to handle this situation in Scala 2.10 and newer Scala version.

In Java I always write code like this to format a String:

A Log4J format example

Log4J formatting FAQ: Can you share a Log4J output/logging format example?

Sure. I'll share a Java Log4J format example that I'm pretty happy with.

I've used the following Log4J logging format quite a bit lately, as I've been working on a headless Java app that can be deployed on thousands of computers, and I was looking for a good Log4J format that was easily readable by humans, and also easy to parse by computers. Here's what my Log4J output format look like these days:

Ant - How to use a date or timestamp in an Ant build script

Summary: An Ant date and timestamp (tstamp) task example.

I was just digging through some Ant build scripts I've created, and I noticed a segment of a build script that first creates a timestamp, and then uses that timestamp in the process of creating a manifest file. (This build script is used for building a Java Swing application.)

Here's the code from my Ant script that does this timestamp magic: