What is the use of magnets around electrical cables?

They're not actually magnets, but rather ferrite which is a paramagnetic material. A ferrite bead with a conductor through it is an inductor and so is used as a low pass filter. Typical use is for power cables to reduce EMI (electromagnetic interference).

They are ferrite (magnetic) rings, over cables in order to suppress noise and filter out unwanted external interference. They are often placed over USB cables, I got one included in my Nikon camera box. Check out the Wiki article for more in depth descriptions and some pictures.