Pen and paper. I find that writing down ideas related to a piece of code I'm currently working on, or writing down the next tasks I have to work on helps me stay focused and productive throughout the day. If I get stuck on something, I'll also brainstorm on pen and paper.
My solution isn't perfect, but its helped tremendously. It also serves as an ever-present todo list if my mind wanders a little.