One technique that i have found useful to stay focused and avoid distractions is Pomodoro Technique. In it, you lock in for 25 minutes of focused work and then take a break for 5 minutes. You do it for 3-4 times and then you take a long break of 15-30 minutes. It helps with keeping you productive. Try it and you will find it very useful.