Last night I started working on a new XMPP library for Javascript; I'll explain later ;). Anyway, I was wrapping it up for the night, separating Javascript from the monolithic HTML file I was working in (because I'm Agile like that), when I accidentally deleted the bottom half of my code and saved without realizing (doh!).
Tragic story, but the funny part is that I had unit tests for all the code I deleted, so within about 15 minutes I was able to re-build all lost functionality. My tests weren't fantastic, but they at least covered basic expectations of the methods' output.
Unit tests FTW.