How do I ask a question on Stack Overflow if the question itself has tons of code in it?

You could sign up for a Github account Build software better, together, post the code there, post important snippets in the question, and otherwise reference the Github URL for your project for people to get a better look at the whole thing. You can set it to be available for review, without allowing it to be edited.