A great hack which I use (still not very good at it though) is the 2 minute technique in the GTD book. Although in the book, the author advocates it in a different manner, I prefer to use it to stop my procrastination.
So I say to myself, let me just work on the code for 2 minutes, not more. And believe me, 2 minutes is a long time! By the time the 2 mins is over I don't even notice and continue coding. This also really helps me in guitar practice. Learning a new song, or a a lick is pleasant. It's the mundane repetitive exercises one needs to do to increase the strength and endurance of your fingers. So again I say to myself, let me just do it for 2 minutes. Believe me, on certain days, that 2 minutes ends up to 4-5 hours of practice.
So I say to myself, let me just work on the code for 2 minutes, not more. And believe me, 2 minutes is a long time! By the time the 2 mins is over I don't even notice and continue coding. This also really helps me in guitar practice. Learning a new song, or a a lick is pleasant. It's the mundane repetitive exercises one needs to do to increase the strength and endurance of your fingers. So again I say to myself, let me just do it for 2 minutes. Believe me, on certain days, that 2 minutes ends up to 4-5 hours of practice.