Sunday, May 06, 2007

Honey Wheat (or White) Bread



We got a new food processor and I decided to take advantage and start making some bread. I'd rather use a mixer with a dough hook, but there's a lot on the wish list right now.

Anyway, I wanted to share. The recipes from Cook's Illustrated are great, but I'm never one to leave well enough alone. I've made two versions of the bread - one white and one brownish with grains and seeds. Here's the recipe:

White
  • 1 1/3 cup whole milk
  • 2 tbs unsalted butter
  • 3 tbs Really Raw Honey (that shit's good)
  • 1 packet active dry yeast
  • 1lb 2 1/2 oz unbleached all-purpose flour
  • 2 tsp salt


Wheat
The process is the same for both.

Heat the liquids in a small saucepan until the temp is 110 or 115 using an instant read thermometer. I like the tase of the honey and am usually a little heavy handed with it. With bread, since there's so few ingredients, the taste of the individual pieces really comes through. The raw honey has a great strong taste - try it! Once the butter's melted and it's all still 110 degrees, whisk in the yeast to dissolve. Most recipes call for you to "proof" the yeast, but just getting it dissolved is good enough.

[The following assumes you're using a food processor - if you're not, I'm sure any other method will work just as well]
Add the flour and salt to the processor - but not the seeds or grains. Pulsing the processor, add the yeast/liquid mixture only as fast as the flour will absorb it. The dough should form a ball and pull away from the sides - if not, sprinkle in some flour until it does.

Remove the dough ball and knead for about 3 minutes. The dough will be a little sticky, but try not to add too much flour. Knead in the grains and seeds at this point if you are adding them. Place the kneaded dough in an oiled bowl and allow to rise for 1-2 hours in a warm spot until it's doubled in size.

Remove the dough and puch it down into a size that will fit into a 5x9 bread pan. Place it into a buttered bread pan and allow to rise for another 30-45 minutes.

Put a sheet pan or pie pan with 2-3 cups of warm water in the bottom rack of a 350 degree oven. Brush the top of the bread with olive oil and place on the second rack. Cook until the internal temperature of the bread reaches 195 degrees using an instant read thermometer. Remove from the pan and place on a wire rack to cool. Don't forget to pull out the water pan before it boils dry. Wait for the bread to cool completely before slicing.


#    Comments [0] |
 Monday, April 23, 2007

Warm-weather-driving season and Earthday hangovers

The warm-weather-driving season kicked off this weekend! I've decided to make sure that Norton is completely taken care of in the next month or two with a plan to give him a new shell by this time next year!

I took care of a bunch of small stuff like changing the headlights from UK style Wipacs to Hella DOT lenses, new wipers, tightened the drop arm (damn thing won't stay!), and pulled out all the damp carpet.

The one big thing that I took care of is rewiring the starter. The PO had used some #1 copper that I could barely bend by hand and kept the battery box from shutting completely.  I had previously used some #1 welding wire for the winch which worked out GREAT - and took an afternoon to rerun all of the ground/starter wires in #2 welding wire. What a difference. Everything is so much more tidy now.

Another big item that I'm really looking forward to is swapping out the Sparco Evos for some standard Defender items. The Sparcos served me well, but I think my butt's getting a little big for them.

In other news, I have to say that I was totally surprised to hear about Bloomberg's plan to increase the number of bike lanes as part of his plan to reduce emissions. I can't say that I believe that the conjestion charge will do more than make more money for the city, but the rest of it is great.

Also - I rode in to work this morning and saw two things that I've never seen before. First, a traffic cop signaling traffic yelled at a guy in a van to watch the bikers (who were, admittedly, running a red light). Then a couple of blocks further, a patrol car had pulled over a guy on a Vespa for buzzing along in the bike lane!

It’s probably just some earth-day overrun and will revert back to standard operations soon enough, but I thought I’d share.

#    Comments [0] |
 Wednesday, November 15, 2006

Quick and easy passwords for ASP.NET

There are quite a few samples on the net which will provide alternate password protection schemes for ASP.NET. There are also built in authentication and authorization mechanisms which are great at what they do, are robust, proven, and super flexible. Occasionally, however, you need something a little simpler.

In my case, I generally need to provide a basic password protection for simple admin/reporting tools or development environments I want to keep away from prying eyes. The optimal solution for me would be something that I can simply set up in web.config and forget about.

This article will outline the basics of getting something as simple as that set up and how you'd configure your web application once the code is running.

Setting up browser-based authentication involves the following steps:

  • Derive from the HttpModule base class
  • Interpret the appropriate HTTP Headers
  • Validate against a configuration or data store
  • Modify the appropriate HTTP Headers based on the result

Code

In setting up our HttpModule, the event that we are most interested in is Application.AuthenticateRequest. We need to setup a handler for it in the HttpModule.Init() method.

Once that's done, we can handle the bulk of the HTTP work that needs to be done. This little bit of code sets up the variables and tests to see if we can even handle this request.

HttpApplication app = (HttpApplication)source;
string authStr = app.Request.Headers["Authorization"];

/* If there's nothing in the header, then it's an anonymous request */
if (authStr == null || authStr.Length == 0)  return;

/* If the authtype isn't Basic, then assume someone else will handle it. */
authStr = authStr.Trim();
if (authStr.IndexOf("Basic",0) != 0) return;

Next, we need to interpret the header information which is stored in Base64 for basic authentication.

string encodedCredentials = authStr.Substring(6);
byte[] decodedBytes = Convert.FromBase64String(encodedCredentials);

string s = new ASCIIEncoding().GetString(decodedBytes);
string[] userPass = s.Split(new char[] {":"});
string username = userPass[0];
string password = userPass[1];

Finally, authenticate the user using the credentials we were presented with and modify the headers to reflect the results. If we are successful, give the current context a Principal based on our credentials in case that information is needed further down the line.

if (AuthenticateUser(app, username, password, out roles))
{
    string realm = "dieselrover";
    app.Context.User = new GenericPrincipal(new GenericIdentity(username, realm),
roles);
}
else
{
    DenyAccess(app);
}

The AuthenticateUser method simply checks the credentials against some settings in the web.config. If you are interested in seeing that, just download the project and browse through it. You can easily override that method with your own if you want a more complicated data store for usernames and passwords, but I would strongly suggest evaluting a more robust solution if you need "real" authentication.

Configuration

Now lets look at how to set this up and get it running. For those of you not interested in how it really works, you can just download the binary, put it in your bin folder, and edit the web.config file.

First, set up the configuration handler:

<configSections>
   <section name="MonoSite.Authentication"
type
="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>

Second, configure the authentication settings by setting the username, password, and realm. The realm is used by the client to organize saved passwords.

<MonoSite.Authentication>
  <add key="username" value="admin" />
  <add key="password" value="admin1234" />
  <add key="realm" value="dieselrover" />
</MonoSite.Authentication>

Third, setup the HttpModule.

<httpModules>
  <add name="Authentication"
type
="MonoSite.Http.AuthenticationModule,MonoSite.Http.Authentication" />
</httpModules>

Lastly, tell ASP.NET that you want there to be some sort of authentication.

<system.web>
 <authorization>
  <deny users="?"/>
 </authorization>
</system.web>

If you want to only password protect certain subfolders of your application, you can do that easily by using the location tag.

<location path="admin">
 <system.web>
  <authorization>
   <deny users="?"/>
  </authorization>
 </system.web>
</location>

Source code and binaries

#    Comments [0] |
 Tuesday, July 04, 2006

Landrover list archive

I made a small update to the land rover list archive. I have been meaning to index each list individually so that you could search one at a time, but only now got around to it.

I think the next big change will be automatically archiving as much as possible since the last time I've done any of that was August 2005.

Another item on the road map is tagging and ranking. I'm not sure if anyone is really using the archive but me, but I'd find it a lot more useful if I could mark entries by subject and come back to them later.

#    Comments [0] |
 Monday, July 03, 2006

After a 17 hour haul in Norton...

I was just pulling in to NYC after a long 17 hour haul from Indianapolis (and before then, southern missouri for some canoeing) when I saw a bearded guy with a tan 88" wagon stopped at the gas station right before the Holland Tunnel.

We both waved and I felt that he was a little more eager to greet me than I was him for a chance run-in at 12:30 in the AM. As I pulled away and paid my toll, I realized that he had his hood up and may not have just been checking his oil.

If that's the case, my karma has gone to hell. If anyone knows who this might be, please send my apoligies... I couldn't have done much since I wasn't carrying any spares to speak of. I doubt there's much aside from a few electrical connectors that our trucks may share. Even so, being in the same situation, I know that even having someone to commiserate with at 1:00AM is as helpful as anything else.

#    Comments [0] |
 Friday, June 02, 2006

Offroading in Morocco

I'm finally getting around to putting up these pictures that have been sitting around far too long. It was about this time last year when Barb and I were tooling around Morocco in a land rover with Trailmasters.

I have to admit I was VERY nervous, but the trip was amazing. Anyone who has the ability to do something like this should do it without hesitation. I've divided the pictures up into three sections to make navigating them a little easier.

#    Comments [0] |
 Monday, April 10, 2006

Smooth Alpha Layers with GDI+ [Part III]

Previously, I had applied an RGB Euclidean distance vector to the alpha channel of a jpeg and ended up with better results than Bitmap's MakeTransparent. There was, however, still a slight halo around the opaque parts of the image and I promised to show you a way that you might be able to improve upon that.

The plan to help get rid of the halo is to truncate the map at a lower an upper threshold and rescale the values in between. In other words, we know that there are lots of colors close to white that we want to throw away, and there's only a few colors around blue that we want to keep.

I chose to scale my thresholds to 8 bits instead of making the user guess (or know) the range of possible values for the distance map. Here's the code to truncate and rescale:

public static void SetThreshold(Bitmap bm, double[][] distanceMap, int limit1,
int limit2)
{
double maxDistance = GetMaxDistance(bm);
double lim1 = Scale255ToDouble(limit1, maxDistance);
double lim2 = Scale255ToDouble(limit2, maxDistance);

for (int x = 0; x < distanceMap.Length; x++)
{
for (int y = 0; y < distanceMap[x].Length; y++)
{
distanceMap[x][y] = ScaleDistanceToRange(distanceMap[x][y],
maxDistance, lim1, lim2);
}
}
}

private static double ScaleDistanceToRange(double val, double maxVal,
double lim1, double lim2)
{
if (val <= lim1) return 0;
if (val >= lim2) return maxVal;

return ((val - lim1) / (lim2 - lim1)) * maxVal;
}

And here's the results... (Again, this doesn't work fully in IE because it won't make PNGs transparent!)

Original:

Original with alpha channel:

This is about as good as you can expect, however, I haven't tried with a wider array of colors. I have a feeling that with more colors, it might be worth transforming the image to CSV and processing based on one or more of those channels.

#    Comments [0] |
 Saturday, April 08, 2006

Smooth Alpha Layers with GDI+ [Part II]

As I was saying before, I need to make an image with a smooth transparency. In other words, pick a transparent color and base an alpha layer on that with smooth edges.

The basic process is to base each pixel's alpha value on its euclidean distance from the transparent color. You could do that directly to the 8-bit alpha channel of a 32bpp ARGB image, but I forsaw a little more math down the line, so I chose to do the processing to a 2 dimensional array of doubles the same size as the image.

Here's the code to generate the map:

public static double[][] GetDistanceMap(Bitmap bm, Color c)
{
double[][] distanceMap = new double[bm.Width][];

for (int x = 0; x < bm.Width; x++)
{
distanceMap[x] = new double[bm.Height];
for (int y = 0; y < bm.Height; y++)
{
distanceMap[x][y] = GetEuclideanDistance(c, bm.GetPixel(x, y));
}
}

return distanceMap;
}

private static double GetEuclideanDistance(Color c1, Color c2)
{
int r1 = Convert.ToInt32(c1.R);
int g1 = Convert.ToInt32(c1.G);
int b1 = Convert.ToInt32(c1.B);
int r2 = Convert.ToInt32(c2.R);
int g2 = Convert.ToInt32(c2.G);
int b2 = Convert.ToInt32(c2.B);
return Math.Sqrt(((r1 * r1) - (r2 * r2)) +
((g1 * g1) - (g2 * g2)) +
((b1 * b1) - (b2 * b2)));
}

If you wanted to apply this directly to an image's alpha channel, you would certainly get improved results over GDI+'s MakeTransparent method which just finds a color and turns a pixel on or off. This, on the otherhand, will turn pixels more opaque the farther they are away from the chosen transparent color.

In order to apply our double precision values to an 8-bit (256 value) channel of an image, we're going to need to scale the numbers to the theoretical maximum Euclidean distance. We can calculate that if we know the number of bits per color (not pixel) which were used in our source image. For now, I'm going to assume that we'll be working with 24 bit RGB images and anything that is not will be converted beforehand.

     Dmax = SQRT(2552 + 2552 + 2552)

And here's the code we'll use to apply a distance map to an image:

public static Bitmap ApplyDistanceMap(Bitmap sourcebm, double[][] distanceMap)
{
Bitmap bm = new Bitmap(sourcebm.Width, sourcebm.Height,
PixelFormat.Format32bppArgb);
double maxDistance = GetMaxDistance(bm);

for (int x = 0; x < bm.Width; x++)
{
for (int y = 0; y < bm.Height; y++)
{
Color c = sourcebm.GetPixel(x, y);
int val = ScaleDoubleTo255(distanceMap[x][y], maxDistance);
bm.SetPixel(x, y, Color.FromArgb(val, c));
}
}

return bm;
}

This will turn the following image with a white background into the one with the red background. NOTE: You can't see the transparent layer of the PNG unless your browser supports it. You're out of luck, IE users. Go get Firefox.

Original:

Original with alpha channel:

Not bad. The transparency is smooth, but there's still a halo of white around it. Next time I'll show how to improve on that just a tad.

#    Comments [0] |

-