I'm not advocating alcohol abuse here, but I've always found that a raging hangover helps. I think it's a partly to do with feeling so awful (gurgling stomach, throbbing head, you know the feeling) and I need some thing (anything!) to take my mind off things.
So coding is perfect. I get to slam on a pair of headphones, put on some relaxing music and start working. Hours can pass. And here is the really good bit: when I come out of the 'coding zone' not only have I written some good stuff but my hangover has receded considerable.
Something else has just occoured to me. In a normal day I get dozens of interuptions which really break my train of thought. I like to think of myself as a pretty approachable guy so I can't complain too much about this really. But I know when I'm hungover I look different - generally I'm unshaven and have a big ole scowl on my face. So people tend to stay away which helps me concentrate, thus I get more done.