I agree that not keeping things that are unhealthy, in the house, are the best ways to avoid them. If it's not there, you'll think twice about making a trip out to buy it.
If it's in the house because another person eats it without worrying about weight (my husband does this), then whenever you get the urge to eat it... distract yourself. Read a book, sweep the floors, vacuum, fold laundry, etc. Typically, if you can resist the urge for 10-20 minutes, it will fade away.
Another thing that helps me is to say "I don't want this" rather than "I can't have this". I'm making the decision on whether or not to eat it and that puts me in control, not my "diet".
I would suggest drinking more water as it makes you feel like your stomach is full
Also not buying stuff like that helps :)