I think a good way to show code (until we wait for all servers to have Markdown like #QOTO, at least) is to show a generated code image (from one of several online tools, or screenshot if you must) and add the code as the ALT text/description of the image, as in the quoted toot.
If, as in this case, the code is too long for the ALT text (this will only happen for long code snippets like this) the code could go in an unlisted reply to the toot with the image (or in the same toot, if you prefer/have space)
I think it's useful to have both a properly-formatted version for those who just want to read code and text which people can copy-paste
gist and other solutions means you need to leave the site - not ideal, I think