This question already has an answer here:
Maybe I am not the first one who got this idea.
There are many programming questions asked and answered on these sites. My idea is when the question or answer consists of a lot of code and the user wants it, he must copy-paste it. So how about providing a download button which will download the code as a file?