Engine dies, but turn the key off and back on it fires right back up

My pickup was doing this the other day would be driving along and then it just died. Sometimes it would start right back up and other times you have to wait for a few minutes and then it would start back up. Come to find out it was corrosion between the battery cable and the clamp.