Two-loop helicity amplitudes for quark-gluon scattering in QCD and gluino-gluon scattering in supersymmetric Yang-Mills theory