Programming


Producing W3C Datetime Format with Timezone in Java

W3C Datetime (also known as ISO 8601) is a standard machine readable way of formatting dates. In its most specific form, dates can be printed with time and time zone in this format:

YYYY-MM-DDThh:mm:ss.sTZD

For example:

1997-07-16T19:20:30.45+01:00

It is not as easy to produce dates in this format in Java as it should be. I needed to format dates like this for creating an XML Sitemap file.

(more…)


TripAdvisor’s Hotel Availability Comparison

Since I spent about six months of my professional life working on TripAdvisor’s hotel availability comparison feature, I thought a little writeup about it here would be appropriate. If you fill in the form over on the right you will be taken to a page on TripAdvisor that shows hotels that are available for the dates that you chose.

(more…)


Efficiently Implementing Dilate and Erode Image Functions

Dilate by One

Motivation

Dilate

Dilate is a function that accepts a black and white image. It is also known by the names “grow”, “bolden”, and “expand”. It turns on pixels which were near pixels that were on originally, thereby thickening the items in the image.

(more…)


Finding a Loop in a Singly Linked List

Motivation

A singly linked list is a common data structure familiar to all computer scientists. A singly linked list is made of nodes where each node has a pointer to the next node (or null to end the list). A singly linked list is often used as a stack (or last in first out queue (LIFO)) because adding a new first element, removing the existing first element, and examining the first element are very fast O(1) operations.

When working with singly linked list, you are typically given a link to the first node. Common operations on a singly linked list are iterating through all the nodes, adding to the list, or deleting from the list. Algorithms for these operations generally require a well formed linked list. That is a linked list without loops or cycles in it.

(more…)


Convert a Java OutputStream to an InputStream

If you have ever programmed using Java IO, you will quickly run into a situation in which a class creates data on an OutputStream and you need to send it to another class that expects to read the data from an input stream. You’ll soon be asking the question, “How do I convert an OutputStream to an InputStream?”

Nowhere in Java will you find a OutpStreamToInputStreamConverter class. Luckily, there are several ways to go about this.

(more…)


Convert a Java Writer to a Reader

If you have ever programmed using Java IO, you will quickly run into a situation in which a class creates data on a Writer and you need to send it to another class that expects to read the data from a Reader. You’ll soon be asking the question, “How do I convert a Writer to a Reader?”

Nowhere in Java will you find a WriterToReaderConverter class. Luckily, there are several ways to go about this.

(more…)