Removing distractions is one technique. Kill your IM apps and work in a quiet area. You'll still feel like checking those distractions out for a while, but once you get into the groove you can work smoothly with little effort.
The other thing is that once you done some work, and you're getting tired and finding it hard to concentrate, take a break. You tend to work more productively when you're fresh than when you're weary.