I quite often write some code for answering a question, while exploring the problem and/or after solving it to visualize or enumerate the results. If it's just a short code fragment, I sometimes include it in the answer, but often it's longer than seems appropriate for an answer, and sometimes it uses code from other packages I have that would have to be included to make it work. Since I sometimes put quite a bit of work into such code and could imagine that at least some of the readers might be interested in it (see here for an example where some said they are), but probably not sufficiently many to warrant badly cluttering the answer, I'm wondering what might be a good approach to making such code available conveniently and sustainably.
Some options that come to mind, with various pros and cons, are
- Put it into my own web space
- Upload it to some free file storage
- Put it on some open-source site like sourceforge
- Request attachments as a stackexchange feature
- Offer to email it to interested readers
- Include it directly in the answers after all
Any thoughts on this would be much appreciated.
[Update:]
I might try out one of the two solutions suggested so far, gist and Pastebin, so thoughts on their relative merits would be helpful. My tendency would be to use gist because of the versioning aspect.