Friday, February 27, 2009

Checking for open files

A coworker presented me with an interesting problem today. We have an SFTP server set up, where a client is uploading a series of files on a pretty regular basis. My coworker needed to process the files as soon as they were finished uploading, but he didn't know how to tell when it was finished. Since the SFTP server would be keeping the file open until it was finished writing it, all we needed to do was find out whether the file was still open.

In Bash, there's an easy way to check for this. When called without any arguments, the lsof program shows a list of all open files on the system. You can also call it with the full path of the filename that you are checking, and it will show only the processes that have that file open. For example, we can look at /dev/null, which seems to pretty much always be open on my system:

$ lsof /dev/null
gconfd-2 6668 jhall 0u CHR 1,3 6663 /dev/null
gconfd-2 6668 jhall 1u CHR 1,3 6663 /dev/null
gconfd-2 6668 jhall 2u CHR 1,3 6663 /dev/null

The lsof program also has an exit status of 0 if it returns any information, and an exit status of 1 if it did not. Since we're only interested in that error status and not in any of the information returned, we can throw it away by redirecting STDOUT and STDERR to /dev/null with &>:

$ lsof /dev/null &> /dev/null && echo "The file is open" || echo "The file is not open"
The file is open

Breaking this down a little further, if "lsof /dev/null &> /dev/null" was successful (returned an error status of 0), then it will run the first echo command. If not, that will make both the lsof command and the first echo command unsuccessful (error status of 1 for both) and the echo command after the pipes will run.

If it's a little confusing having "/dev/null" in that command twice, try running it on a file that's likely to not be open, like /proc/cpuinfo:

$ lsof /proc/cpuinfo &> /dev/null && echo "The file is open" || echo "The file is not open"
The file is not open

Just a handy little bit of Bash Fu to brighten your day.

Wednesday, February 25, 2009

Ginger Beer Test #1

Those who know me well know that one of my favorite things in life is a good ginger beer. Not sugary-sweet ginger ale, but real, spicy, knock-you-off-your-feet ginger beer. I've been wanting to make it for a couple of years now, I just hadn't gotten around to it. Well, this week I finally got off my butt and gave it a try. This batch was a test run, to help me get my bearings. There will be more.

But first, we need to define what exactly makes a good ginger beer. It depends on who you are really, and I'm going to guess that my definition is probably not the same as yours. My three favorite brands are, in order:

Okay, so Vernors is really a ginger ale, but it's still up there. There are a few properties to look for in ginger ale and ginger beer. First of all, ginger ales are generally divided into two categories: golden and dry. I've found golden to be a little darker, sweeter, and more strongly-flavored. Unfortunately, it's near-impossible to find. Dry ginger ale is lighter, and extremely common. Being a Utah boy, I grew up on Canada Dry and Schweppes, but when I lived in New Hampshire I got used to Seagrams too.

But these really lack something in my opinion, and that's real ginger. I like mine spicy, but not harsh. Smoothness is also important to me, but not so much as spiciness. And that's where ginger beer comes in. It's stronger, tastes more like ginger, is often brewed, and the good stuff almost always has little fibers of real ginger in it.

I've tried a lot of different kinds of ginger beer, and I've divided (most of) my favorites into two categories: Jamaican-style and Australian-style. Jamaican ginger beer is spicy, strong, and has been known to make me cough, just getting a whiff of a newly-opened bottle. Unfortunately, it generally seems to be harsh, overly-spicy, and flavored with other spices in addition to ginger. In the small, relatively unknown world of ginger beers, this seems to be the most common, and I've probably tried a good 20 or 30 different brands, but few more than once.

Australian ginger beer is different. I've had a good dozen or so different types of this, and few of them miss their mark. They're strongly-flavored, spicy, but also smooth. They seem to be true to the ginger flavor, and when I get ahold of a few bottles, they don't remain full for long. It was this variety that I was looking to reproduce.

The first task of course was to find some recipes. I wasn't sure yet whether I was going to make a composite recipe, I was just looking to see what I could find. Most of the recipes I came across were long and ridiculously complex. One of them had a longer list of equipment than actual ingredients. Finally, I found a recipe on Recipezaar that was simple, but kind of long and very poorly-written. It seemed to be more of a Jamaican recipe, but I figured you've gotta start somewhere.

I didn't use the recipe as-is of course. I made a few changes, and then took notes while I more or less followed their directions. My ingredient list was as follows:

1/2 tsp yeast
1/2 cup warm water (110F)
1 3/4 liter water
3/4 oz/wt freshly-grated ginger
1/4 tsp anise
5 whole cloves
1/2 cup sugar

I sprinkled the year in the 1/2 cup of warm water and set it aside. I then mixed together all of the other ingredients in a sauce pan, brought it to a boil, and then dropped it to a simmer for 5 minutes. I then killed then heat and let it cool on the counter to 110F (actually, 112F to be exact, but anything below 120F is fine), and then poured in the yeast/water mixture.

I poured all of this (whole spices and all) into a clean 2-liter bottle, pressed in the sides a little, screwed on the cap and let it sit overnight on the counter. In the morning, the bottle was completely inflated, and you could tell by feeling it that there was a lot of pressure inside. I moved this to the fridge and let it sit until the next evening.

I tasted the brew before I added the yeast, and I knew I was already in trouble. It was extremely spicy, and the anise overpowered everything. But I was determined to let it age for a couple of days so that I could get a good idea of what it would be like.

When we uncorked it, there was a lot of sediment. This is to be expected with home-brewed drinks. But it's not something I would want to drink, so I poured it through a tea strainer into some cups and tasted it with my wife and her friend visiting from Wisconsin. Unfortunately, this means I also strained out the ginger fibers, but since we were just about to drink it, I figured it wouldn't be adding any more flavor anyway.

First of all, the color. It was more cloudy than I expected. I'm okay with that. Next, the carbonation. It was lightly carbonated, not as much as commercial ginger beer, but still decent. Finally, the flavor. It was very spicy, but not as bad as I had feared. The anise still overpowered everything, but it still had a lot of ginger in the finish, to come back and bite you. I suspect the clove was about right (if you like that sort of thing; I'm currently undecided), but that anise just screwed it all up. It was just a little bit sweet for me, but not bad.

Just a quick note on drinks carbonated with yeast. This is exactly how beer is made. When the yeast gets going, it produces lots of carbon dioxide and a little bit of alcohol. That's what makes bread rise, and makes beer fizzy. Since my brew had only a tiny amount of yeast, and was only allowed to ferment for a couple of days, the alcohol content was negligable. If that is of concern to you, this is the wrong recipe for you.

I will be starting another bottle tomorrow night, when this one is used up. Now that I have my bearings, I think I have an idea of where I want to take it. I'm going to try multiple changes at first, and then fine-tune it as I get closer to what I want. The next batch will have no anise. That was just a bad idea. I will leave the cloves in there, and probably use the same amount of ginger. This time I'm thinking I may add some lemon juice, and drop the sugar down to 1/3 of a cup. I hope to post results this weekend.

Wednesday, February 18, 2009

Plex Cake

It's been a while since I posted, and I'm going to blame that at least partly on being busy. But I did want to share a cake with you that I made this past weekend. It was my daughter's second birthday, and she is a huge Yo Gabba Gabba fan. In fact, she has been watching it almost since her first birthday, so it should come as no surprise that I've been looking forward to making this cake for several months.

Plex is a robot member of the cast, and is probably one of the most popular cakes for parents to try to make for their kids. But up until this point, I have't seen one with fondant like this, so I'm going to declare myself in the lead. First, the cake:

The yellow part is a white chocolate rolled fondant recipe that I've been working on for a while. It's not quite to where I want it, but it's getting there. The cake was a chocolate cake based on a recipe I found online. It it filled with a chocolate mousse based on a recipe by Alton Brown and fresh raspberries. Anything you see that is covered with white fondant (except for the eyes) is molded from crispy rice treats. And the antenna is a cigar cookie wrapped in semi-sweet chocolate.

The black square where his eyes are was actually about half an inch higher, but it seemed to have slipped down during transportation. I eventually gave up on trying to make the ball on the top of his antenna red, or trying to make his ears at all. And no, I never planned to attach even parts of his arms to his shoulders. Deal with it.

It was kind of a fun cake to build, but like all cakes that I make like this, I was reminded repeatedly why I don't often make cakes like this. The fondant didn't want to cooperate (I think I may have added just a touch too much white chocolate to it), keeping the chocolate in temper for that antenna was a miracle (the four backup antennas that I made all lost their temper) and speaking of the antenna, when I opened the tin of cigar cookies, they were all broken. Actually, that's pretty much why I decided to wrap it in chocolate; it was actually a couple of pieces of broken cigar cookie, reinforced with chocolate.

I'm going to go ahead and post my fondant recipe here, because I seem to keep losing it. It is not the easiest thing to make, and I only recommend it for those who are truly serious. I use a stand mixer for part of making this, but heed well this warning: if you try to make it from start to finish with any kind of electric mixer, you will burn out the motor! And yes, this recipe is measured entirely by weight. If you're not willing to weigh the ingredients, you're not serious enough to make it.

White Chocolate Rolled Fondant (still considered a test recipe)

0.5 oz/wt powdered gelatin
2.1 oz/wt cold water
0.8 oz/wt glycerin
9.6 oz/wt corn syrup
10.5 oz/wt white chocolate
2 lbs confectioners sugar + extra just in case

* Bloom the gelatin in cold water for 3 minutes.
* Start melting the white chocolate gently over a double-burner.
* Add the glycerin and corn syrup. Heat gently to dissolve, while whisking occassionally.
* Remove everything from the heat, and whisk in the white chocolate.
* Add the mixture and all of the sugar to a stand mixer use the paddle to mix on low.
* When the mixer starts to sound as if it is having trouble, turn it off and finish kneading the mixture by hand. I have found that using a bowl scraper to cut and mix the fondant helps keep your hands clean.
* If the mixture seems to be too wet and sticky, sprinkle in some more sugar.
* When you have formed a homogeneous ball of dough, move into an air-tight container for a couple of hours to let it rest.

Like I said, I still consider this recipe in a testing stage. It clearly requires more than 2 lbs of sugar, but I'm not sure how much more. If I had to guess, I'd say it was just a couple of ounces, maybe as much as half a cup. Also, I originally went with only 10 oz of white chocolate, and the fondant seemed a little too pliable. 10.5 oz made it a little too hard. Next time around, I'm going to go with 10.25 oz of white chocolate and see how it goes. I think that the rest of the ingredients are pretty solid, it's just a matter of getting the best measurements for the sugar and the chocolate.