How to correctly customize equation numbering & referencing simultaneously?

I think the following solution is quite nice: Wrong numbering for the equation - #2 by Eric. Basically you don’t change the ref, but just reset the equation counter after each heading.