The physics of rock failure and earthquakes