What helps me is a moderate dose of amphetamines. It takes me from being someone who steps over something on the floor for a week because he's to lazy to put it away to writing code for 56 hours straight.
And the code isn't actually bad. The real problem is that it also makes you into a perfectionist who starts to write his own jpeg library if he finds anything about libjpg that he does't like.