Spectral Pollution and How to Avoid It (With Applications to Dirac and Periodic Schrödinger Operators)