Increase your vocabulary so that you can express yourself without resorting to expletives. Swearing only makes one look coarse, vulgar, classless and uneducated. I understand the occasional slip when you slam a finger with a hammer, but when it comes to the point that you "slip" in front of a teacher, that is beyond acceptable. Learn to express yourself more appropriately.
Keeping your mouth shut is the best solution to spot yourself from cursing. Practicing silence shows that you are in control of yourself and your emotions. You can also practice meditation, such prayer, yoga, falun gong or continued thought and reflection.
Cursing is a HABIT. Like smoking (for example).......My suggestion is to substitute your habit with another one. Example: When people stop smoking, they sometimes chew gum instead....so instead of cursing.....(if you cannot just keep silent)....then say another word in its place. Practice the word and have it on hand and ready to pull out and use on a moments notice. Example: Pickles! You could say "Oh pickles" or "Son of a pickle". Get the idea? It has always been my opinion that only UNEDUCATED people fill their sentences with curse words......so learn some new words so that someday you can substitute "pickles" with a new, more educated sounding word. People will admire and respect you much better than having a potty mouth and so will your mother!