# How to make longer programs available?

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.

• Perhaps it is worth emphasizing the importance of persistence - which some of the above proposed solutions do not guarantee. There is an analogous problem with persistence of images, which seems to be only temporarily resolved via SE and imgur. Sites can rot in many ways. The less rotten we can make it, the better. Have we yet had any code rot? Jan 4 '12 at 18:22
• Ah, that was the word I was looking for :-) That's what I meant by "sustainably". Jan 4 '12 at 20:03
• There's also Pastebin, but again there is no assurance of persistence. One would think SO would have already had such mechanisms in place before other SE sites like this one sprung up... Jan 5 '12 at 0:14
• The versioning aspect of gists is the biggest reason why I prefer them to pastebin. I also like that it's connected to my existing GitHub account. Jan 5 '12 at 17:53

• I wanted to thank you again for this suggestion; in the meantime I've linked to $31$ gists in math.SE answers :-) Jan 19 '13 at 18:30