In the moment I find a couple things help me get my focus back.
Take some time to do a quick meditation, 5-10 minutes. 90% of the time this gets me out of whatever rut I was in. I'm a big fan of the Headspace app for guided meditations, but other apps will work just as well.
Go on a walk. If time is scarce I'll just do a couple laps around the office. If it's around lunch time I'll try and hop over to a greenway or park and walk around for most of my lunch break.
Chat with a coworker/friend about what they're working on. Being in the presence of someone who is focused tends to make me feel a bit more attentive myself.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.