Your first response would be to laugh, and frankly that is not a good time. It makes a person feel even worse about whatever they are doing. There is also the fear that you could make them feel bad and that makes you feel awkward. In the worse case scenario, you encourage them. Instead of laughing, try smiling at them and going about your way. Maybe even pretending you did not see what you saw, or did not hear what they said.
For example, if you are having a conversation with someone and they make a racist joke, instead of being like, “omfg, stfu!”, say something that is completely irrelevant from the conversation. “Oh, did you see the new Harold and Kumar movie?” Yes. You now have successfully countered the oopsie situation. Hopefully they take the hint and do not try to make any more.
On a different note, if something happens continually, you should consider that they are just weird. If you have a friend that constantly says weird stuff like, “I collect toe-nail clippings” it is time to say good bye. These facts and phrases are not accidental. They are just odd and need help you can not give them.
Of course everyone has that one friend that occasionally says something off. And those moments can be forgiven because if you know they did not mean what they said it is easy to laugh it off. Also, if you are best friends you could just make the best of the situation and play along. Nobody likes a stuck up person that can’t take a joke.