Articles by Chris Metcalf

You are currently browsing Chris Metcalf’s articles.

Mt. Rainier

Photo from SparkyLeigh’s CC-licensed Flickr photo stream

Update: Well, as you can tell, I’ve failed miserably on the resolutions involving blogging and Flickring. Well, there’s always the last two quarters of the year…

Tags: , , , ,

Happy Holidays

Happy (belated) Holidays to all of you. I hope you got to spend some quality time with family and friends.

Ancient Trees

See you next year!

Lately I’ve been working on a pretty hefty spec for work (hint hint… it’s a REST API spec). I like writing my specs in TextMate using MediaWiki markup, so I can easily post them to our internal wiki once they’re ready.

One of the annoying things about this spec is that it involves dozens of examples in XML and JSON that are embedded in <pre> tags. I wanted to be able to develop and edit these samples as native XML and JSON files for convenience, but it was becoming a real pain to keep them updated in the main document via cut and paste. The obvious solution to this problem is a text preprocessor that would allow you to include a .xml file in the main .wiki document. There are dozens of these, but they’re all a pain in the butt to use and I didn’t feel like setting them up.

The solution, which couldn’t possibly be more obvious, was suggested, somewhat jokingly, by a coworker of mine:

cpp

Yup, the good old GNU C Preprocessor. If you run Linux, or you have a Mac (basically, any *nix), or you do any development whatsoever, chances are you have one hiding out on your machine somewhere. Chances are you’re also familiar with the #include "foo.h", which you’ve used since freshman year to have the preprocessor include the header for another C file before it passes it off to the actual compiler. But you never thought about using it to help you with your homework (or your specs) before.

Well cpp has a handy -P parameter that tells it to forgo the inclusion of the normal linemarkers it includes for the benefit of the compiler. This makes it perfect for simple stuff like embedding one text file in another.

In your main document, use a #include statement to include your example file:

document.txt:

== XML Example ==
The following is an example of the server's response in XML:

<pre>
#include "example.xml"
</pre>

example.xml:

<example>
      <message>Hello World!</message>
</example>

Then use a simple Makefile to build your output document:

Makefile:

all:
        cpp -P document.txt document.out.txt

Using a Makefile means you can use TextMate’s Makefile bundle to quickly and easily build your document.

There you go, a completely “duh” way of doing simple text includes on any *nix system.

Tags: , , , , , , ,

By popular request, I thought I’d write this one up. It’s a quickie.

Finished Product

A month or two ago, I was lucky enough to spot a pair of very cool vintage theater seats with a big “FREE!” sign on them sitting on them down the street from my apartment. After my eyes lit up with the possibilities, I convinced an anonymous neighbor to help me haul them to the elevator.

Then I asked my awesome father for some carpentry assistance, since I can’t fit a table saw in my apartment.

He totally came through for me with a great “floorboard” made from some gorgeous teak/holly flooring (commonly found in sailboats) edged in oak. Mounting it to the seats was pretty straightforward – just some 10-24 stainless bolts backed by fender washers and nylock nuts. I added some standoffs made from nail-on nylon “magic mover” pads to make them easy to move around.

The result is awesome. They work great as a couple of extra seats for guests that stay out of the way when I’m not using them. And I love the quizzical look friends get on their faces when they try to figure out how I managed to steal them from the movie theater.

Tags: , , , , , ,

Apparently I was too busy to even mark the passing of my own birthday.

Birthday Candles

Monday was the big-two-seven for me. My god I’m getting old…

Photo from luvtequila2005’s CC-licensed photostream

Tags: , ,

« Older entries § Newer entries »