I typically tar it up and store it somewhere safe. On occasion, I'll work on a new project that could use a piece of code I know I've got stored away. Other times, it's something I stumble upon years later and laugh at myself for my coding style & quality, which continues to improve. "Omg I can't believe I tried to solve X that way... wow..."
I've seen a few people open source their code for failed projects. Hadn't really thought about that, but it's something I'll keep in mind should I have an interesting, failed project.