Sometimes you're unlucky enough to have a dog in front of you that appears to feel like taking a good bite out of you.
Note that not every dog barking at you wants to attack. In fact, when a dog barks the chance of attack is a lot lower than when it's quiet. The signs of aggressiveness of a dog are: showing teeth, hairs standing up, ears folded back.
To greatly lower the risk of being attacked, follow these guidelines:
1. DON'T PANIC. Dogs are said to sense fear somehow. Even if you're practically wetting your pants, stay calm. Showing any sign of fear lets the dog know that it is superior and can do whatever it wants. Don't smile with your mouth open either, no matter how nervous you are. To a dog, showing your teeth is VERY threatening and provoking
2. Do not provoke the dog. Don't make eye contact, to dogs that's challenging and provoking. Make no sudden movements, or you'll instantly have the dog gnawing on one of your limbs. Don't run away either. Dogs are generally faster than humans, and running triggers the dog's hunting instincts: you become prey, and that's not a good thing.
People have been saying they would throw stuff at the dog, hit them or (for the cyclists among you) squirt the water bottle at them or "try to ram your bicycle pump down the dog's throat" (!)1
DON'T DO ANY OF THIS!
It'll probably do nothing but seriously piss off the dog, and you won't like that.
3. Look for help. The dog's owner or a passerby might be around to call the dog off, or at least help you some way or another.
4. Try to command the dog to go away. For best results, speak calmly, loudly and with a low voice.
5. Try distracting the dog. Throw something away, or pretend to. Food, balls or sticks make good throwing objects.
6. If all else fails, back away quietly. A dog is often aggressive because you're trespassing on its territory and will calm down if you leave. If you really need to be somewhere beyond the dog, go past it with as much distance as possible. While moving, keep facing the dog but remember to avoid eye contact.