The long hikes that PG mentioned are a good idea. I've started to do things that exercise my ability to focus. Reading challenging novels and writing are good drills.
I've also started trying to recognize when I try to do two things at once and look for opportunities to focus on only one thing. This can be trivial. I'll fold laundry while watching a tennis match, but I avoid browsing the web. I've noticed that if I do this while watching sports, I quickly lose track of what's going on in the game.
Lastly, I'm more certain than ever that you really need to be engaged (maybe even passionate) with your work to stand a chance against distraction. About 6 months ago, I was really enjoying my programming project, and focus came easily. It took no motivation to get started. I did check HN, but I wasn't killing time on it.