I have found the Pomodoro Technique (http://en.wikipedia.org/wiki/Pomodoro_Technique) to be helpful. I can't do it for a whole day, but a short sprint to grind through something is a near, achievable goal. For extended, head-banging frustrations, it's helpful to step away, think about it without the distraction of the screen, and coming back at it with fresh eyes. The time AFK is not to be underestimated: http://www.paulgraham.com/top.html