This one probably sounds phony at first, but there's a web site called brain.fm that has tracks for focus. It claims to alter the frequency of your brain waves or something; I don't know if that's legit.
I do know that whatever it's doing, it works. It's paid, at like seven bucks a month, but worth it.
I used to use music, which is okay and if you've got the right music (one that improves your mood while not being distracting), it can help. Audiobooks are too distracting for me to listen while working--they keep the part of my brain that's focused on language busy, and it shuts everything else out. Silence is sometimes golden but is also easy to walk away from.
The site has built-in timers for certain intervals, but you can also set it to run until you stop it. I usually get three really productive hours in before I just have to walk away from the code for a while because it's sucking out my brain.
The site also has tracks for relaxation, which also work; and sleep, which I haven't really used.
I'm not affiliated, I just think this site is worth it.