I do all of my side work under an alias, just to keep this from happening. Making it one-step harder for lawyers is generally all it takes. Don't draw lines from your GitHub account that you use at work to the GitHub account that holds your side projects. Every time I start with a new company, I spin up a new GitHub account just for that company. Sorry this happened to you.
But in such a scenario, I'm not a loser. If I'm capable of writing software that my former company cares that much about, I'm winning. I'll hand over my Haskell code, laugh at the thought of them trying to understand it, purge all copies I posses, and immediately begin rewriting it in another language and under another anonymous profile.