Monday, March 18, 2013

Analysis of post-workout chocolate milks available in the UK

It's fairly well known that the right combination of carbohydrates and protein after a work out is important in getting the body back in shape and building muscle. And a common way of getting those nutrients is by drinking chocolate milk.

Working from a basis of a 5:1 carbohydrate to protein ratio with 15g of protein after a work out (i.e. 75g of carbohydrates) I wanted to find out which commonly available chocolate milk would be the best. Best being defined as have the closest possible ratio to the ideal 5:1 and low in fat.

I gathered all the nutrition data on 15 commonly available chocolate milks: Frijj Chocolate Milkshake, M&S Belgian Chocolate Milk, Tesco Chocolate Milk, Mars Refuel On The Go, Milky Way On The Go, Galaxy On The Go, Yazoo Chocolate Milkshake, Shaken Udder Chocolush Milkshake, Waitrose Belgian Chocolate Milk, Waitrose Essential Chocolate Milk, Daioni Chocolate Flavoured Organic Milk, Sainsbury's Fresh Chocolate Flavoured Milk, Galaxy Thick Shake, Galaxy Smooth Chocolate Milk and Mars Thick Shake. None of these are sold as workout recovery drinks.

For each, I calculated the carbs:protein ratio and the total fat per 100ml. The following scatter plot shows the results. Drinks in the upper right quadrant are 'better' (good carbs:protein ratio, low fat).


Although M&S, Waitrose and Shaken Udder drinks likely taste good they are stuck out on the left there because of their high fat content. The winner, at least for me, is Galaxy On The Go with a carbs:protein ratio of 4.4 and 1.2g of fat per 100ml. It comes in a 400ml bottle containing 312 kcal, 4.8g of fat, 62.8g of carbohydrates, and 14.8g of protein. It costs £1.29 per bottle.

A close second is Galaxy Chocolate Milk which comes in 1l bottles containing 790 kcal, 11g of fat, 136 g of carbohydrates, and 35g of protein.

PS A comment below asked for a fully labeled version of the chart. To get the full details here's the spreadsheet containing the source data I used.

Tuesday, March 12, 2013

An itch I scratched: SnoozeTil

I really like to get email out of my inbox, but some emails I need to deal with later. So, what I wanted was a way to say "remind me about this tomorrow at 3pm" or "I don't want this in my inbox until next Thursday".

So, I built it.

Initially, it was just for me, but I think others might like to use it so I put a pretty face on it. The service is called SnoozeTil. You forward emails that you want 'snoozed' and type a plain English description as the first line of the forward.


And then you can archive the email knowing that it'll come back when you requested. This works by parsing the first line (the parser is quite flexible and fuller details are on the site) and then keeping track of the message Subject and Message-ID (the actual text of the message is not stored).

When the appointed time comes SnoozeTil replies to the message (with the appropriate Subject and Message-ID) which causes your email client to attach the message to the original message (or thread) and 'wake' it up.

Currently, I've only tested this with Thunderbird and Google Mail. YMMV but I would be happy to work with people to make it work for them.

Signing up is simple: send a message to SnoozeTil and that email address is registered. You get a unique forwarding email sent back to you.

PS People have pointed out that other similar services already exist. SnoozeTil is a little different because it doesn't store the emails forwarded to it (so no need to worry about their contents being revealed) and it support sophisticated dates/times such as using specific time zones. And SnoozeTil generates a unique email address for each user to prevent the service being used to spam.

Monday, March 11, 2013

Automatic bookmarking of locations in Emacs

One of the things I find myself doing over and again in Emacs is returning to the last place I was editing a file. Sometimes that's because I've killed a buffer before I should have done (thinking I was finished), sometimes it's because I've exited Emacs and sometimes it's because I simply return to something a day or two later.

Since it was incredibly annoying to have to search for the last place I was working I created a simple system in Emacs that automatically remembers where I was and then lets me jump there by hitting C-l (obviously you can choose whatever key binding you like, I choose that because I never use C-l for its real purpose).

The automatic bookmarking works by using three Emacs hooks: when kill-buffer-hook or after-save-hook are called it records the current line number of the buffer in an internal hash table; when kill-emacs-hook is called it makes sure that the line number in each current buffer is saved and serializes the hash table to ~/.emacs.d/last-location.

There are probably lots of improvements wizard elisp hackers can make, but here's what works for me (you need my-emacs-d to be the path to your .emacs.d directory):


PS As a commenter points out there's already saveplace.el that I had failed to find before writing my own.

Tuesday, March 05, 2013

A simple illustration of Go interfaces

Go's approach to object orientation is somewhat different to the familiar 'hierarchy of classes'. In place of classes with methods, Go has interfaces. An interface specifies a set of behaviors (functions that can be called). If a Go type has that interface (i.e. has all the functions specified in the interface) then it can be used wherever that interface is required.

A commonly used interface in Go is io.Writer. An io.Writer interface is defined as follows in the io package:
type Writer interface {
    Write(p []byte) (n int, err error)
}
Any user-defined type that has a function with signature Write(p []byte) (n int, err error) is an io.Writer and can be used wherever an io.Writer is needed. For example, the bufio package can be used to create a buffered version of any io.Writer by passing it to bufio.NewWriter.
func NewWriter(wr io.Writer) *Writer
bufio.NewWriter's argument is itself an interface (an io.Writer), so anything that has the Write(p []byte) (n int, err error) function can be passed to it. At the same time bufio.Writer (the type returned by bufio.NewWriter) is itself an io.Writer (because it too has the Write(p []byte) (n int, err error) function.

This style makes it possible to define other io.Writers that can be used with any type requiring an io.Writer. In one project I was working on it was helpful to have an io.Writer that kept count of how many bytes were written. Here's that package (called rather unimaginatively counter).

With that package any existing io.Writer could be wrapped with a call to counter.New() and the return result used as if it were the original io.Writer.

Monday, March 04, 2013

Some Pig

In the past I've written about writing. In my previous blog post I recommended three books:
On Writing Well, by William Zinsser. This book is an example of its own title. It's a delightfully well written book about writing that reads with the slippery ease of a Malcolm Gladwell. It's both enjoyable and informative. 
The AP Manual of Style. Although the AP book is about writing for newspapers it is full of useful advice about clarity. The fight for clarity is at the heart of non-fiction. Your goal is not to delight the reader with the breadth of your vocabulary, but to inform them about a subject in which you are claiming to be knowledgeable. News writing has to aim to be succinct, accessible and accurate; those are all good attributes for any non-fiction writing. 
The Elements of Style, by Strunk and White. The surprising thing about Strunk and White is that I can pick it up after years and years of owning it and rediscover its lessons. If you only buy one book from my list buy this one.
The fourth book I'd recommend isn't actually about writing, but reading it is a lesson in writing. The book is Charlotte's Web. If you've read or heard of Charlotte's Web you are likely wondering why I'm recommending children's fiction when the subject is writing. There's a simple reason.

Charlotte's Web was written by E. B. White: the White in Strunk and White.

If you read Charlotte's Web and think about the writing you'll notice that many of the lessons from The Elements of Style are clearly illustrated. The book is a pleasure to read as an adult despite being aimed at children.

The words are small and appropriate. The sentences clear and the prose flows easily. I think Charlotte's Web epitomizes a style that many writers should emulate no matter for whom they are writing. The actual subject of the book is quite difficult for children to digest, but White's writing makes them swallow a difficult tale with ease.

The clearest example of Strunk and White style is illustrated by the spider Charlotte. Writing in her web she's restricted by space and her own ability to form words. Yet she saves the pig's life by writing SOME PIG. Just two simple words express what's essential: this isn't just any pig. This is Wilbur.

When the reader first meets Charlotte she greets Wilbur with "Salutations". Wilbur doesn't understand the word and Charlotte is forced to explain:
"Salutations are greetings," said the voice. "When I say 'salutations', it's just my fancy way of saying hello or good morning. Actually, it's a silly expression, and I am surprised that I used it at all. [...]"
Charlotte seems to be echoing Strunk and White's command to 'Avoid fancy words'.

So, if you are writing something you hope others will read, remember the simplest of all writing rules: SOME PIG.