Categories

Introducing Archer Kevin Williams

If any of the three people that read this website are wondering where I’ve been for the last several weeks, let me proudly refer you to the picture below.

Archer Kevin Williams was born January 3rd, 2012 at the PeaceHealth Nurse Midwifery Birth Center in Springfield, OR. 8lbs 2oz, 20″ long and, like his father, a head like a melon. Sorry wife.

Archer’s arrival was a lightening-fast adventure. We arrived at the birth center around 9:30 a.m. At 10:11 a.m., we had a baby. No time to call any family, no time to set up the laptop we had loaded with 8 hours of music to soundtrack the journey of birth. Again, sorry wife, next time we will leave earlier.

So, how did I celebrate the arrival of my first child? I started by opening a bottle of Hellshire I. And not just any bottle of Hellshire I, mind you. I opened the very first bottle of Hellshire I that was sold at the release last May. A bottle I acquired by being the first to arrive at the event, a bottle tucked away specifically for this occasion.

A big night for my father too; first grandchild and first barleywine, though the baby trumped the beer somewhat.

Well, that’s all for right now. I have a bunch of stuff coming down the pipe; Ninkasi Renewale 2012 and Critical Hit Barleywine, Falling Sky Brewing, Eugene Beer Week ’12 planning, a bunch of Active Directory Group Policy stuff and a DIY guide for building a custom FightStick with genuine Sanwa arcade parts (Ultimate Marvel vs Capcom III is doing a number on my Xbox 360 controllers). Oh, and when I got home from work today, I found a couple packages waiting on the doorstep – Widmer W’12 Dark Saison and Redhook Nut Brown.

Now I just need to find some time between the coffee grinding and diaper changing…

Cheer!
Kevin

Homebrew Tools: Force Carb Calculator and Web Coding Techniques

Last week, in my Beer and Coding at Two post, I stated that I would have the first in a series of Homebrew Tools done this week. I am happy to report that I have actually managed to meet a deadline. Albeit a self imposed deadline, but when the norm is deadlines coming and going, while your projects sit in committee hell, you take a win when you can get one. The force carb calculator can be found under the Homebrew Tools tab at the top of the page.

So, why this calculator? Well, a couple reasons. First, I picked a force carb calculator because, unlike most beer related formulas, this is one I am not able to do on my fingers (or toes, or with a relatively small number of button presses for that matter). The formula for determining required PSI is:

P = -16.6999 – 0.0101059 T + 0.00116512 T^2 + 0.173354 T V
+ 4.24267 V – 0.0684226 V^2

P = PSI
T = Temperature
V = Desired Volumes of Carbonation

The second part of the ‘why?’ is that it gives me an opportunity to talk about coding design. Most of the force carb calculators available on the interwebs, use a Javascript Get/Post method, which reloads the entire page to display the results. There is nothing wrong with this design (and it does drive up the ad views – Beer and Coding Monetization Editor), but it is a little clunky, and with tools like JQuery, completely unnecessary. Now, before I delve any further into my web programming philosophies and techniques, you get the disclaimer.

While I write software for a living, I am by no means a web programmer. My opinions about web programming design and technique should be taken for what they are, my opinions.

Ok, with that out of the way, we can get started. As I stated above, I like to avoid using Get/Post within the Javascript if I am working within a single page. Instead, I like to leverage the jQuery Post method to fetch PHP/HTML from an external file and insert in onto the current page. This not only keeps the entire page from reloading every time the code fires, but it makes to code much more streamlined. The entire code for the Homebrew Tools page is:

<?php

echo “<p>”;
echo “<p>”;
echo “<div id=\”carb_calc\”>”;
echo “</div>”;

$initialize = 0;
if ($initialize == 0) {
echo “<script>init_page();</script>”;
$initialize = 1;
}

?>

Sexy, right? Along with this we also have the Javascript function init_page(), to initialize the page and place some PHP in the carb_calc <DIV>. The code for the Javascript header and init_page() function is:

<script type=”text/javascript”>

var $j = jQuery.noConflict();

function init_page() {
$j(‘#carb_calc’).html(‘<input type=”button”
onclick=”show_tool(\’carb_calc\’);” value=”Force
Carbonation Calculator”></input>’);
}
.
.
.
.
</script>

As I’ve mentioned in other posts, WordPress doesn’t play nice if you use the typical jQuery variable name ‘$’, so I have instead taken to using ‘$j’. Now, let’s pause for another quick talk about design ideals. Rather that loading tools directly onto the page, I decided to load buttons instead. By not immediately executing code to build the tools, the page loads much quicker. Not a big deal right now, seeing as there is only one tool, but this will become more important as the number grows. This will also keep the page looking clean, something that is becoming more and more important as the number of smartphone/pad users increases. In this design, clicking a button will load the corresponding tool into the <DIV> containing the button. This allows tools to be opened or closed without reloading the page, or affecting the values of other open tools.

Defining the carb_calc button in the init_page() function was another design choice. It could just as easily have been defined directly within the carb_calc <DIV> in the PHP, but by placing the code in the Javascript function, we can more easily control whether or not a button is loaded. Not so important in this example, where the carb_calc button is immediately loaded, but it could prove helpful down the road, if I want to suppress certain buttons, depending on how the user arrives at the page.

Another technique I like to use is passing the name of the <DIV> to my Javascript functions. This allows me to write very light, modular Javascript functions, eliminating long If/Else statements. The code for the show_tool() function is:

function show_tool(homebrew_tool) {
$j.post(“../” + homebrew_tool + “.php”, function (data) {
if (data.length > 0) {
$j(‘#’ + homebrew_tool).show();
$j(‘#’ + homebrew_tool).html(data);
} else {
$j(‘#’ + homebrew_tool).hide();
}
});
}

By using the same name for the PHP file as the <DIV>, in this case ‘carb_calc’, the name can be passed straight through to the jQuery Post method without any extra conversion or validation. And as long as I preserve this naming convention, I can continue creating tools that call the show_tool() function without ever adding code to the function itself. Instead, all the work is done in the PHP file. The code for the carb_calc.php file is:

<?php
echo “<b>Force Carbonation Calculator</b>”;
echo “<table>”;
echo “<tr>”;
echo “<td>Temperature</td>”;
echo “<td><input type=\”text\” id=\”temp\”
maxlength=\”3\” size=\”4\”/></td>”;
echo “<td>(°F)</td>”;
echo “</tr>”;
echo “<tr>”;
echo “<td>Volumes</td>”;
echo “<td><input type=\”text\” id=\”vol\”
maxlength=\”3\” size=\”4\”/></td>”;
echo “<td>Desired Volumes of CO2</td>”;
echo “</tr>”;
echo “<tr>”;
echo “<td>PSI</td>”;
echo “<td><input type=\”text\” id=\”psi1\”
maxlength=\”4\” size=\”4\”/></td>”;
echo “<td>Slow Force Carb (> 5 days @ PSI)</td>”;
echo “</tr>”;
echo “<tr>”;
echo “<td>PSI</td>”;
echo “<td><input type=\”text\” id=\”psi2\”
maxlength=\”4\” size=\”4\”/></td>”;
echo “<td>Fast Force Carb (24 hours @ PSI)</td>”;
echo “</tr>”;
echo “<tr>”;
echo “<td><input type=\”button\” onclick=\”calculate_psi()\”
value=\”Calculate\”/></td>”;
echo “<td></td>”;
echo “<td><input type=\”button\”
onclick=\”close_tool(‘carb_calc’,'Force Carbonation Calculator)\”
value=\”Close\”/></td>”;
echo “</tr>”;
echo “</table>”;
?>

The carb_calc.php file is where the actual defining of the tool occurs. The show_tool() function retrieves this file and posts the PHP code within to the carb_calc <DIV>, replacing the button that called show_tool(). By designing the tools to work this way, the code on the page stays light and the Javascript functions become very reusable. When it comes time to add, say, a gravity calculator, all I have to do is add a ’grav_calc’ <DIV> to the main PHP, initialize the tool’s button in init_page() and place the tool’s code in grav_calc.php. The close_tool() function, which (surprise, surprise), closes the tool, works in much the same manner as the  show_tool() function. The code for the close_tool() function is:

function close_tool(homebrew_tool,tool_name) {
$j(‘#’ + homebrew_tool).html(‘<input type=”button”
onclick=”show_tool(\” + homebrew_tool + ‘\’);”
value=”‘ + tool_name + ‘”></input>’);
}

This function simply replaces all the carb_calc.php code in the carb_calc <DIV> with the tool’s button. Again, reusable by any future tools. Finally, we have the function calculate_psi(), where all the hard maths are performed:

function calculate_psi() {
var temp = document.getElementById(“temp”).value;
var vol = document.getElementById(“vol”).value;
var psi1 = -16.6999 – (0.0101059*temp) +
(0.00116512*(temp*temp)) + (0.173354*(temp*vol)) +
(4.24267*vol) – (0.0684226*(vol*vol));
var psi2 = psi1*3;
psi1 = Math.round(psi1*Math.pow(10,1))/Math.pow(10,1);
if (psi1 < 0.1) {
psi1 = ‘< 0′;
}
psi2 = Math.round(psi2*Math.pow(10,1))/Math.pow(10,1);
if (psi2 < 0.1) {
psi2 = ‘< 0′;
}
$j(‘#psi1′).val(psi1);
$j(‘#psi2′).val(psi2);
}

This function retrieves the temperature and volume values using the document.getElementById method. The maths are performed and the two PSI values are displayed in the input fields using jQuery. Since none of the input variables are being used in mySQL queries, I did not bothering to perform any validation on them. The lengths of the input values are controlled by the ‘maxlength’ attribute, set for each input field in carb_calc.php. If a non-numeric is entered in either field, NaN (Not a Number) will be returned. The only case I am trapping for is when the required PSI would be less the 0.1. In this case I am returning ‘ < 0′ in the PSI fields, rather than a negative number.

So, there you have it, a force carb calculator and a glimpse into the design decisions behind it. I still plan on adding a little polish to the calculator, like an option for Celcius and a warning if the determined PSI is over 60 (the limit of many homebrew CO2 regulators).

If anyone finds this kind of post useful, let me know and I will continue writing them as I code more tools for the Homebrew Tools page.

Cheers!
Kevin

Beer and Coding at Two

Following an 11th hour reminder from GoDaddy to re-up my expiring domain and a frantic scour of the old grey matter for the password required to do so, Beer and Coding has now safely reached its second birthday. And with another anniversary in the books comes the near-requisite look backward and the even nearer-requisite look forward that tend to accompany such an event. Here we go.

Where Has All the Coding Gone?

Yes, it has been another coding-lite year on the old blog. The bulk of my coding over the last year has revolved around credit card security and the black hole that is PCI-DSS. If you know this acronym, then you understand what I am talking about. If you don’t, consider yourself lucky but be warned, if any aspect of your job deals with the accepting of credit-type cards, it is only a matter of time. Doom and gloom aside, the nature of my work, coupled with a new “Social Media” policy at work, has severely limited what I can discuss. One thing I can say is that 8+ hour days of attempting to meet ambiguous PCI standards and security auditor requests, all the while doing the real work necessary to keep customer information safe, has left me more than a little coded-out at the end of the day. And with my PCI workload continuing to progress on what seems like an exponential curve, I don’t foresee my situation changing anytime in the near future. The way I see it, I have two options at this point. I can either buck up and find something to talk about, or I can find a new name for the blog. And since I just paid for another year of hosting, I’ll be going with the former.

So, what is the plan for year three? How about some brewing tools? Sure, there are plenty of them out there already, but most are long abandoned and like any (good?) programmer, I am fully confident that my re-invention of the wheel will be the design that finally gets it right. Failing that, we will still have a series of coding exercises to discuss. First up, a force carbonation calculator with a “burst carbing” schedule for those of us who don’t want to wait for the keg pressure to normalize on its own. It should be up next week.

No Brewery Yet, But an Assistant Brewer on the Way

Another year spent refining my home brewing skills, a couple of ribbons from the last Sasquatch Brewfest and a few extra bucks in the bank account had me ready to plunge headfirst into the exciting, fast-paced world of nanobrewing. I even got the green light from the wife. I started with a couple very helpful exchanges with Mike at Beetje Brewery on equipment options and techniques. After deciding that it would be possible to fund a home-based brewery out of pocket, I then participated in a couple exchanges with the TTB, which proved less helpful.

For those of you who haven’t seen the Brewers Association’s newest figures, there are over 700 US breweries currently in the planning stage. Many of these are nanos, and a good portion of which are home-based operations. This run on variances has caused the TTB to become much stricter on what types of residential structures get the stamp of approval. I wish I could have known the importance of the phrase “detached garage” a few years back when my wife and I bought our house, with its 500+ square feet of open, gas-plumbed and completed attached garage. Of course there is also the whole proximity to a grade school thing, another no-no for which the Feds seemed none-to-keen on granting a variance.

About the time I was deciding between sending out the feelers for interest in an alternating proprietorship and scouring the area for dirt-cheap warehouse space, I received some news that put the whole venture on hold. With any luck, by the first of the year, my wife and I will be the proud parents of our first child and my yet-to-materialize brewery will have its first assistant brewer. Here is a shot of the guy/gal, already hard at work refining his/her palette.

I detect a strong note of Amniotic Fluid...

So, with the brewery plans on the back burner while we enjoy the run-up to parenthood, I’ll have some extra time to do my homework. Over the next year, expect a good number of posts dedicated to over-analysis of equipment, DYI projects and my attempts to create a “brand” for myself. In the mean time, if any of you local breweries would like for some free evening or weekend labor, shoot me an e-mail. I can use any hands-on experience I can get, especially washing kegs.

Onward, Upward

As I’ve mentioned before, each day it gets a little easier to blog about beer in Eugene. 16 Tons was a boon to the craft beer community last year. Mike and Jeff’s arrival and the first Eugene Beer Week were no coincidence. And the guys’ newest venture, The Union, can only help to further cultivate it. Add in The Pantry and Pub and Cornucopia’s newest restaurant, The Maize, and we have several new options for craft beer around town. But this is a topic better suited for the next State of Beer in Eugene post.

So, let me end by saying thank you to everyone who makes Oregon the greatest craft beer state; brewers, bloggers, publicans and enthusiasts.

Cheers to another year!
Kevin

A New Toy

I am writing this post from my newest toy, a ViewSonic G Tablet that my wife gave me for Christmas. The device is a 10.1″ (1024 x 600) Android tablet, powered by Nvidia’s new Tegra 2 processor. The Tegra 2 is currently the fastest mobile processor available, combining a dual-core 1Ghz ARM Cortex-A9 CPU, an ultra-low power GeForce GPU and a dedicated video processor, capable of full 1080p playback.

The tablet was completely unusable at first due to some very buggy software. But, after getting it online and pulling down the latest patch, it was moving right along. So far I haven’t done much with the it besides play Angry Birds, set up my E-mail and install Adobe’s Flash beta drivers, but I can’t imagine it will be long before I get the itch and start writing apps.

I will probably begin by dusting off the Android port of my Beer Test, which I started working on earlier his year. My other initial thought is to write a brewing calculator, as the tablet seems like a great format for such a tool. Jeff did a Survey of Beer Apps earlier this month, which lists several that are currently available for Apple and Android phones, but the ones I have tried so far have all felt a bit fiddly. Any ideas for a beer app you would like to see on a tablet? Or suggestions for features missing from the current crop of mobile brewing calculators?

Cheers!
Kevin

More on Kinect Hacking

In my Holiday Gift Guide, I talked a little about the hacking potential of the new Xbox 360 Kinect device. Since then, some interesting things have developed, so I thought I would spend a few additional minutes on the topic.

Since Hector Martin released his prize-winning Kinect driver, libfreenect, on Nov. 10th, the community OpenKinect has sprung up to continue developing and maintain his code. Libfreenect is fairly robust at this point, including not only a device driver, but also a cross-platform API that works on Windows, Linux and OSX, and wrappers for ActionScript, C#, C Sync, OpenCV and Python. The software supports access to the device’s RGB and depth images, motors, accelerometer and LED.

A few of my favorite projects using the libfreenect open-source library are:

While libfreenect is a nice, lightweight C library, another option became available last Thursday. PrimeSense, manufacturer of the PrimeSensor reference camera, which Microsoft used for the Kinect, open-sourced its driver and framework API. The driver, while not Kinect specific, does attempt to implement all features of the PrimeSensor reference spec.

PrimeSense also partnered with Willow Garage and Side-kick to found OpenNI, a not-for-profit organization to certify and promote compatibility and interoperability of NI (natural interaction) devices. OpenNI has released a C++ framework based on PrimeSense’s driver. And through OpenNI, PrimeSense has released a beta of their NITE skeletal tracking system.

Like I said, a lot of interesting stuff in the last couple weeks. One of the most appealing aspects of Kinect hacking is that no “hacking” of the device is required; the camera system uses a stardard USB interface. So, download one of the above libraries, plug the device into your computer and you’re off to the races.

I have been trying to come up with a beer related Kinect project to justify buying the device, but so far I’m coming up blank. There is already some object recognition code written, so it wouldn’t be too much work to detect when a glass is held in front of the camera and determine the SRM of its contents. Not the most creative idea, but hey, it’s what I could come up with on the spot. If you have a more beery idea for a Kinect project, let’s hear it. It may be the motivation I need to open the wallet.

Finally, for anyone interested in Kinect hacking, I’ll leave you with some required reading.

http://openkinect.org – OpenKinect
http://groups.google.com/group/openkinect - OpenKinect Google Group
https://github.com/OpenKinect/libfreenect - Libfreenect library
http://openni.org - OpenNI

Cheers!
Kevin