The power of being grateful the moment you accidenrally hurt yourself, instead of swearing and wallowing in self-pity, cannot be overstated.
It's very easy: Just realize immediately that it could have been so much worse. Breathe, pray, feel the pain without reacting. No reason to let the inner animal run wild.