Theory of the Nernst effect near quantum phase transitions in condensed matter and in dyonic black holes