formatting

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:

Android JSON - Print a JSON string in a human-readable format (for debugging)

Android JSON tip: How to use the JSONObject toString(n) method to debug a JSON string in an Android app, by printing the string in a human-readable format.

While working on an Android project recently, I noticed there is a toString method on a JSONObject object that looks like this:

The Scala String format approach (and Java String.format)

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?

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

String.format("%s %s, age %d", firstName, lastName, age)

but if you try that in Scala, you'll get a long and unusual error message.

The Scala String formatting approach

The short answer is that in Scala your String format code will now look like this:

Android EditText inputType - XML formatting examples, options

When using Android with "soft" touchscreen keyboards, you can change how the keyboard looks, and how the EditText widget works by specifying an inputType when you create your EditText widget.

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:

Perl printf format examples (reference page)

Here's a reference page (cheat sheet) of Perl printf formatting options. Hopefully this list covers the most common printf printing options you'll run into, or will at least point you in the right direction.

Perl printf - printing strings

Here are several examples that show how to print strings (text) with Perl and printf. I'll use single quotes in all my printf examples to help demonstrate left- and right-justification.

Java printf - output format examples with System.out.format

In my previous tutorial on using the Java String format method ("Java sprintf") I showed how to use the format method of the Java String class to format strings and text output. That method works fine in many situations where you use the sprintf function in other languages, such as when you need to either concatenate strings, or print formatted output using something like Log4J.

Fri, May 30, 2003 (printf for Java)

Ahh, a printf()-like utility for Java ... life is good again. :)

Follow-up in 2009

These links are much more up-to-date, now that we have real printf capabilities in Java:

Java number formatting - how to format Java numbers

Java number formatting FAQ: How do I format numbers for output on reports in Java programs?

Generally speaking you want to use the Java NumberFormat class and its descendants, such as the Java DecimalFormat class.

Quoting the API documentation, the Java DecimalFormat class "also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized."

Syndicate content