A.) Minimize visual stimuli in your work area. Get everything off your desk, and shove your face in a corner. (I've turned my desk to face away from the hallway.)
B.) Take notes as you work. I will write 15 minutes of code, take a note on what I'm doing, then get (purposefully) distracted for a minute or two. When I come back to my work, I can look at my note to see what I was doing and pick back up where I left off. It really minimizes the impact of distraction on my work. You can start out with lower chunks of "productive" time if you want. Practicing focus helps you to build up amount of time you can focus. Relevant talk on Youtube: https://www.youtube.com/watch?v=IlU-zDU6aQ0
A.) Minimize visual stimuli in your work area. Get everything off your desk, and shove your face in a corner. (I've turned my desk to face away from the hallway.)
B.) Take notes as you work. I will write 15 minutes of code, take a note on what I'm doing, then get (purposefully) distracted for a minute or two. When I come back to my work, I can look at my note to see what I was doing and pick back up where I left off. It really minimizes the impact of distraction on my work. You can start out with lower chunks of "productive" time if you want. Practicing focus helps you to build up amount of time you can focus. Relevant talk on Youtube: https://www.youtube.com/watch?v=IlU-zDU6aQ0