I've done what my mom (+rip) used to do, who really was actually very and sincerely saddened by it - I think that's the first thing needed because once you are sincerely affected by it, it is much easier and almost second nature to say something.
She would always say something, didn't matter who the offender was that said it, and now that I think about it, I only remember the offender either stop saying it, or they would offer some type of apology, of the feew times I recall, I never remember anyone arguing with her. Her rebuke always began with something along the lines of a gentile but firm question: "Why are you asking God to damn you/him/her/it?" It always sounded like she sincerely wondered. Anyway, I've done the same only a few times, and it seems like it only takes asking this one time, if the person has any common decency at all, the result is that he watches his mouth around you from then on.
Other than that, say "Blessed be God, blessed be the name of God, blessed be His holy name" to yourself.