Its very easy to mistake an Idiot for and A-hole. Sometimes the two go hand in hand. But sometimes the offender is completely clueless about the world and is just an idiot. This is something that there is no cure for. The idiots intentions are usually not malicious, even though they may appear to be inconsiderate and selfish. It's a very tough call and difficult to determine.
For example, take the dude that runs his mouth of for no reason. He means well, but he has no filter. He says things because he has a low self esteem, needs attention and wants to make people laugh. In the process of doing so, he pisses off a bunch of people. He spends his free time watching Daniel Tosh and listening to Howard Stern. He thinks shock humor and jokes about rape are hilarious. Even though he might not be misogynistic himself, he believes that he can make people laugh with his offensive one liners. This prompts him to make these awful jokes, not realizing that he is offending several people because he hasn't learned to shut his mouth. This dude isn't and A-hole. This dude an idiot. Deep down he is actually not a bad guy, he's actually pretty nice. He just doesn't know any better and doesn't realize the things he says might hurt other people.
So how do you deal with this brand of of idiot? Well, for starters, you certainly can't confront him on the spot. If he says something really offensive, he probably doesn't really mean it. He's only saying it because he wants a reaction. He wants a laugh. The best way to deal with this situation is to look at the person and say "funny", but don't laugh. Or just don't say anything. Do NOT let him get a rise out of you. If he sees that you are getting angry, he will immediately go on the defense. He made the joke because he wants instant gratification. If you give him sh*t about it right on the spot he will probably say "oh lighten up"..or try his best to defend his remark, even if he didn't mean it or doesn't buy into the BS that is coming out of his mouth. His ego is at stake and he is no longer defending his remark. He is now defending himself. Take a breath and walk away. There is no point in trying to get into with him at that moment.
So ...what you can do to stop him from making these types of remarks around you in the future? If the idiot is continuously making these obnoxious remarks, you might want to either call and talks to him at another time or pull him aside.. AT ANOTHER TIME..PRIVATELY.. NOT after he has made the comment, and politely tell him you were kind of offended by his remarks. Make sure this is a one on one conversation and that nobody else is around. He will probably say he was only "joking" and maybe even apologize. If he still goes on the defense at this point or tries to justify his remarks after learning that they bothered you, then he is not an idiot. He is an A-hole. Please refer to my guide on this website about this epidemic.