Friday, December 24, 2010

Hacking your kitchen: making a sous vide

[caption id="attachment_170" align="alignright" width="200" caption="The crock-pot portion of my sous vide -- with three thermometers monitoring (and three different temperature readings )."]The sous vide.[/caption]

I recently found the cookbook ["Cooking for Geeks"](http://www.cookingforgeeks.com) , and it inspired me to build a [sous vide](http://en.wikipedia.org/wiki/Sous-vide) (the section on making a sous vide at home is also covered in a blog post by the author [here](http://www.cookingforgeeks.com/blog/posts/diy-sous-vide/)). If you're not familiar with the term, sous vide lets you very carefully control the temperature you're cooking at, so you *can't* over heat foods.

Sous vide is similar to using a crockpot, but it requires *much* more control over the temperature than a typical crockpot provides. If cooking with a crockpot is like sketching dinner, then sous vide is analogous to using finely-tuned drafting instruments.

Jeff Potter (Author of Cooking for Geeks) provided part numbers for a suitable thermocouple (a probe thermometer) and a corresponding temp switch (a switch that controls a gate based on the temperature it sees from the attached thermocouple). I would have had some trouble getting the right set-up without that guidance, but still ended up diverging a bit on accident. I ordered an AC version of the temp switch instead of a DC version, but in the end I think it worked better this way.

The biggest problem I have with Jeff's suggestions is that the book and blog show the temp switch and wiring sitting un-enclosed on the counter, with everything hard-wired together. I'm not comfortable with 115vac running around on my kitchen counter, so I needed some sort of enclosure. I also wanted to be able to detach the thermocouple to easily clean it, and I didn't want to modify my crockpot much at all. (I really don't want *another* appliance, and I still want a functional crockpot.)

# Parts

[caption id="attachment_175" align="alignleft" width="200" caption="The top view of the enclosed sous vide controller. AC power comes in the top, the crockpot is powered out the right, and the thermocouple is plugged into the bottom edge."]Sous vide controller - top[/caption]

Given that I don't have access to a fab. plant (or a maker bot!) I opted to go with a simple locking tupperware container for a housing. They lock shut, have a gasket for a tight seal, and the plastic is very easy to modify to hold all the ports that the sous vide control needs.

At this point it's probably reasonable to think of the control as a temperature-controlled power outlet, rather than something specific to a sous vide, since the purpose is really irrelevant for now.

I'm not going to go into great detail about the specific parts (although I'll talk about the connections somewhat), but you can see the full parts list [here](http://bit.ly/fBbj4M).

## Housing ##
The pictures show the housing fairly well. We started by cutting out holes for all the components with a hot exacto knife (heated in a blow torch -- as Mike put it, it cut through plastic like hot butter through a knife ;). Pretty much all the parts had some sort of template we could go by:
- temp switch: we used the wire cover to draw out the opening
- power outlet: I had a cover plate that I was intending to use, instead, we just used the cover plate to mark out the large round plug hole and the two screw holes, then used the cover plate screws to hold the plug in.
- thermocouple jack: just drilled it out with a drill.
- AC input: traced around a pc-style power cord, then cut to the outside of the sharpie line, then drilled out the screw holes (marked after we had the main hole in, and could test-fit the plug).

[caption id="attachment_182" align="aligncenter" width="500" border-bottom="1em" caption="The water for my eggs was at 120f, gradually heating to 147."]Digital temperature display.[/caption]


## Thermocouple connections ##
The temp probe arrived with a bare pair of wires on one end, which wasn't going to work that well, so we (I was working with a friend who has a soldering iron :) attached a 1/8" headphone plug to the cables, then soldered a corresponding jack to some 22-gauge wire that eventually went to the temp switch inputs (ports 7 & 8 on the TCS-4010).

## AC input ##
I was initially going to use a standard pigtail power cable to hook this up to the wall, but when shopping for parts I found a PC-style (D-shaped) power plug, which works beautifully, and it was cheap!

[caption id="attachment_176" align="aligncenter" width="500" caption="The back-view of the controller, showing the pc-style AC input, crockpot in the background."]the rear view of the controller[/caption]


## Power outlet ##
Locating a cheap power plug that would fit in a small container, and only had one plug was actually pretty difficult. The outlets I found with a flange were more expensive than I could justify ($15-20), and everything else had two + plugs, or a plug and a switch, or so on. Eventually, I settled on a 20-amp single-outlet plug, designed for a standard outlet box. In the future, I think I'll go with a dual-outlet 15amp plug, or look more. The 20-amp outlet is very hard to plug things into, and I'm not entirely sure why. It works just fine once you get everything plugged in, though.

## Wires ##
I went with 12-gauge solid copper, in three colors, for the internal wiring. It was quite difficult to form to the right shape, though, and we needed to solder it in place. The wire was so stiff that we ended up re-soldering quite a bit: we'd solder a connection, then bend the wire to make the next connection, and the solder would break. Eventually, we wired it all together and did the soldering in one go. This worked, but it meant we couldn't easily cover some of the connections with heat-shrink tubing. In particular, the three connections to the AC input were bare, so we covered those with hot glue to keep fingers and other potential conductors from shorting it out (and delivering quite a shock).

We were able to heat-shrink most of the connections, however, and everything is soldered in place, so I think it will hold up :).

[caption id="attachment_183" align="aligncenter" width="500" caption="The appliance plug is on the side, to the right of the display."]showing the AC-output[/caption]


## Calibration

I did a test run with eggs to see how this worked, with multiple thermometers to compare readings (you can see one of the other thermometers in the first picture). I did a quick calibration based on those readings, but the controller was still off by about 5 degrees (that initial calibration was pretty drastic, there was a difference of over 10 degrees!). That became evident when I cracked the eggs and they were a bit under-cooked---the book suggested flash-boiling them anyway, so I had boiling water handy and re-calibrated based on that. Don't do what I did, or if you do, cook something cheap in the first run :)

## Next time...

1. Use stranded 12-gauge wire. It should be more flexible, and hold solder better.
2. Use a 15-amp power plug, so it's easier to plug/unplug appliances.
3. Be careful about the locking tabs on the tupperware housing: These are really, really, close to interfering with the plug and temp switch.
4. I actually wanted to have the switch upside down, but because of the wire flexibility, we had to cut things to be very short. That meant that we couldn't reach the screws to mount the temp switch, since the bottom of the housing would have been in the way. I'd try and do this differently next time -- using stranded cable may work, or attach the temp switch first, then insert it, and finally solder the power input/output in place.
5. Add an LED to the power supply that leads directly to the device. It would be very nice to know when the appliance is actually getting power.

Wednesday, December 22, 2010

cabal-dev: sandboxing your Haskell development (and now with ghci!)

Reproducing builds is pretty much essential if you intend to do sustainable software development, and while it's generally possible, it's been fairly difficult to do so with Haskell. One of the challenges has been that there are only generally two local databases of installed packages for any given (user, ghc-version) pair. Each ghc install has a global package database, and each user has a user package database for each version of ghc. This is perfectly suitable in most situations, but it becomes problematic when you need conflicting packages to be installed for disparate development projects. Cabal-dev removes the user package database from the picture, and it is relatively simple (with some self-control :) to maintain a minimal global package database: just don't install anything system-wide with cabal.

Cabal-dev does this by creating a per-project sandbox that contains a package database of all the dependencies as well as the project under development. Therefore, it was simple to add support for launching ghci with this package database in place of the user package database. That's been added in cabal-dev-0.7.3.1, which is available on hackage now, allowing you to do things like this (using my Haskell Version Space Algebra library as an example):


$ cd havsa
$ ls
LICENSE Setup.hs src/ versionspaces.cabal
$ cabal-dev install
Resolving dependencies...
Configuring mtl-1.1.1.1...
Preprocessing library mtl-1.1.1.1...
Building mtl-1.1.1.1...
[ 1 of 21] Compiling Control.Monad.Identity ( Control/Monad/Identity.hs, dist/build/Control/Monad/Identity.o )
....
Registering VersionSpaces-0.0...
Installing library in
/home/creswick/development/havsa/cabal-dev//lib/VersionSpaces-0.0/ghc-6.12.3
Registering VersionSpaces-0.0...
$ cabal-dev ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :m + AI.VersionSpaces
Prelude AI.VersionSpaces> showBSR EmptyBSR
Loading package syb-0.1.0.2 ... linking ... done.
Loading package base-3.0.3.2 ... linking ... done.
Loading package mtl-1.1.1.1 ... linking ... done.
Loading package logict-0.4.1 ... linking ... done.
Loading package VersionSpaces-0.0 ... linking ... done.
"Empty"
Prelude AI.VersionSpaces>


This is still far from perfect: you can't easily load code into the ghci session without exiting, re-running cabal-dev install and cabal-dev ghci, but it's a good start.

Wednesday, October 06, 2010

Prezi: scalable, navigable presentations

Edit:Prezi now has support for customizing colors / themes, and even documentation for the css! I'm happy to see official support for these features, but the layout problems are still a show-stopper for me./Edit

I have been adopting a presentation style that diverges from the traditional bullet-point style promoted by Open Office and PowerPoint (although, PowerPoint 2007 diverges from pure bullets to more interesting shapes, using shading and encapsulation to show hierarchy. It's a large improvement, but it still falls short of my ideal). Instead of bullets and text, I try to make use of imagery and visual examples whenever possible.

My experience has reinforced what I've come across in the literature about balancing your audience's attention between the content on the wall and your narration. Too much text or detail and you risk loosing your audience because they're overwhelmed or, if you're lucky, because they are focusing on the slide content instead of listening to your explanations. It is also much easier to trigger emotional responses with visuals than it is with text, which explains some of the motivation for promotional/motivational presentations that are virtually devoid of text. (
Seth Godin's talks come to mind. One way in which my presentations differ substantially from Seth's is that I generally talk about fairly technical topics. The difficulties associated with finding high-quality, emotional, images to convey the intricate details of ptrace(2) is not the topic of this post, however.)

A number of years back, I found a mention of using Scalable Vector Graphics (SVGs) for unconstrained presentations and that idea has stuck. I've been developing slides in PowerPoint (OpenOffice has not yet reached the point where I can create professional-looking content), but I've never been happy with the traditional slide-based presentation style. SVGs promise the ability to move between arbitrary locations, following a pre-defined path from "slide" to "slide". Furthermore, since the content is scalable, you can literally zoom in to a portion of content to go into more detail, or zoom out to show context. This presentation mode would also make it easy to diverge from your plan based on audience feedback. This can be done with PowerPoint, but it is extremely difficult.

Prezi promises these benefits, so I spent the last few days building a presentation with Prezi at Galois: portable build systems. (The prezi presentation is near the bottom of this post.) The rest of this entry discusses my experiences with Prezi.

The Good, the Bad and the Ugly



I initially found the Prezi interface to be very intuitive. The translation "zebra", a stripped round mult-function circle, appears whenever you select an object. You then use the zebra to move, scale, rotate, or otherwise manipulate the selected object. Other options are presented through a bubble menu that rotates and scales to show more detailed options as you select sub "bubbles". It is well worth the few minutes it takes to sign up for a free account and try it out. If you happen to be using 64-bit linux, you probably won't be able to use the flash app, however. Prezi doesn't appear to work under that environment. (if you can interact with the presentation embedded on this page, then you should be Ok.) There is also an Adobe Air-based desktop app, which I used extensively.

I was off and brainstorming a presentation mind-map style after only a few minutes playing with the interface. The freedom to create a few words of text, zoom in and flesh out more details, jump back out and pull in an image, all without concern for the layout of final form of the presentation was extremely motivating and liberating.

I was able to be quite productive with Prezi until I began to consider the need for a unifying theme. Two things stood in the way:

  1. Only eight options were provided for the overall look and feel of the presentation, and none were close enough to the Galois color scheme. There is also no way to add new look and feel options, and each option changes all the colors, fonts, backgrounds, and general style of the presentation.

  2. The set of shapes and drawing tools is very limited. You can create: Thin free-hand lines, thick free-hand "highlighter" lines, circular rings (round frames), square brackets (square frames), gradient-filled rounded rectangles (roundrect frames), arrows, text in one of three fonts (optionally with bullets).

None of the pre-defined colors can be changed through the user interface, aside from the eight styles mentioned above, which change all the colors / styles and fonts. You can include arbitrary images, which helps with the limited set of shapes, however, you can only include pdfs if you are using the web-based client, the desktop client does not currently support pdf importing.

I stumbled across a solution to the limited selection of colors by unzipping the .pez file that holds a Prezi presentation on-disk and exploring the contents:

prezi/
├── content.xml
├── preview.png
└── repo/
├── 13177749.png
├── 13177754.jpg
├── 13177758.png
├── 13177835.swf
├── codetree.png
└── Personal_computer,_exploded_5.png

content.xml defines the SVG-like presentation content, and it ends with a set of css styles:



The colors in these styles can be adjusted, and you can even add new styles here (although you will need to manually insert them into the xml where you wish to use the new styles). After editing the content.xml, zip up the presentation tree, taking care to maintain the correct hierarchy and no compression:

$ ls
prezi/
$ zip -r -0 enabling-portable-build-systems-biuinv2vus9x.pez prezi/

One surprising benefit is that the updated styles are actually adopted by the UI widgets in the Prezi application, once you load a modified .pez file.

The "Title | Title | Body" buttons change according to the css stylesheet in content.xml.

These changes also persist across saves, loads, uploading to Prezi.com, and they appear to render properly when embedded, granting quite a lot of power, if you're able and willing to work with xml and css periodically.

Editing content.xml also proved to be the best way to spellcheck the presentation content, although the text that is actually displayed is in CDATA nodes, which your editor may skip over when running a spell checker. Thankfully, the text is duplicated as plain text nodes, so you are still alerted to spelling errors when running ispell-buffer in emacs. You can then fix the CDATA entry with a recursive edit. (I suspect that the duplication is there to simplify text searching.)

I'm rather satisfied with these workarounds: The ugly aspects could be automated with some simple tools to update the content.xml as needed, and the hacks I found worked surprisingly well.

Background images and "refactoring"



Unfortunately, I don't think Prezi is ready for prime-time, despite my success with css styles and spellchecking. There are simply no facilities to precisely align or distribute objects with respect to each-other. Further complicating this is the lack of a "group" option to create aggregate objects. You can select multiple objects by dragging a rectangle if you hold shift, but that isn't possible if the objects are on top of other objects -- the first click of a shift-drag must occur on the background of the Prezi, or you will simply select the lower object. While this sounds a bit like a minor quibble, it is impossible to accurately position complex sets of objects if they are layered on top of other content (such as a background image). I often need to add or remove "slides", and with Prezi, that can include a lot of object translations to provide or absorb space while fitting with the high-level overview of your presentation. Without alignment tools, you also take the risk that a title will display askew with respect to the screen borders when you are mid-presentation.

I eventually adopted the following practice to help keep content square:

  • Press 'space' to enter "show" mode, and position the screen as it would be to show the "slide", then pres 'space' again to return to edit mode.

  • Create a roundrect frame, it will be square with the current view.

  • Use the borders of the roundrect as visual guides to make the slide content as square as possible. I usually place the baseline of the title text with the top of the roundrect and then position it after the angle has been fixed.

  • Delete the roundrect


Now, never rotate any individual components of that slide again. Use shift-clicking to select everything in the slide each time you need to rotate or move the slide. If you need to add new content, first enter 'show' mode and click on the frame to make the camera rotate properly with respect to the slide.

Summary



I'm excited to see how Prezi evolves, and I will be one of the first in line once the selection / alignment problems are fixed. I hope that Prezi will motivate other implementations with similar capabilities, there is plenty of room for some healthy competition.

Monday, July 26, 2010

Recovered Puzzles

I used to collect puzzles--back when I had a wiki to post them to--but that content was lost to me a few years ago when the system hosting my personal content had a slew of hard drive issues. I was lamenting that loss last week when a coworker suggested that I could possibly find the content on the way-back machine at archive.org, and indeed, I did!

Without further ado, here's a short list of brainteasers (none are of my creation, and I do not have citations--if you know who to credit for any of these, please let me know and I will add proper attribution info.)


Calendar Cubes

A man has two cubes on his desk. Each face of each cube has a single-digit number wirtten on it. With these two cubes, the man is able to enumerate all the days in any month, and each morning he arranges the cubes so that the number of the current day is on top, *always* using both cubes. How are the numbers distributed on the cubes?

Pennies 1

You are blindfolded in a room with 100 pennies. 30 of the pennies are heads-up, the remainder are tails-up. You can interact with the pennies in any way, but your fingers are not dexterous enough to feel the contours of the coins (so you can't feel one to see which side is heads, or tails). Since you are blindfolded, you can't see them either. Your task is to manipulate the coins such that there are two sets and each set has an equal number of coins that are heads-up. (The sets must be disjoint, non-empty, and all pennies must be in one of the two sets.)

Pennies 2

Given N pennies, one of which is counterfiet (and therefore is of different weight from the remainder) and a balance, how can you find the counterfeit coin in less three weighings on the balance.

Eggs

You are in a 100-floor building on a planet with oddly low gravity and/or surprisingly durable eggs. You happen to have two of these eggs (unfertilized, I assure you). Your task is to find the highest floor from which you can drop an egg and have it remain intact.

Numbers

Given 99 unique integers between 1 and 100, provide an optimal algorithm to find the remaining integer in that range that is not in the set.

Hint: Bcgvzny gnxrf yvarne gvzr naq pbafgnag fcnpr.

Prisoners

50 people are inprisioned, and during their imprisonment the captor will invite people randomly in to visit with her. All visits are one-on-one, and each prisoner has a unique tunnel from their cell to the captor's office (so you can't look out your cell and see who is going in). In the captor's room is a bowl that the prisoners can optionally turn over, or turn right-side up during their visit(s). The initial state of the bowl is known to everyone.

The imprisonment may last for an infinite period of time, during which each prisoner will be invited into the captor's office many, many times (essentially infinite, but it needs not be infinite, it could just be a reasonably small number in the optimal case). The imprisonment ends when one prisoner says: "Everyone has been in to see the captor at least once." If a prisoner says this and they are wrong, all prisoners are killed immediately. Because the captor may decide not to visit anyone for a while, it is as if the prisoners have no concept of time, so they can't bound the number of people seen based on the passage of time.

To give the prisoners a chance, they are allowed to convene briefly before their imprisonment, during which time they can plan a strategy. How do they do it?

Sequences
What is the next line in this sequence?


1
1 1
2 1
1 1 1 2
3 1 1 2
2 1 1 2 1 3