I use Git. Every code I write is versioned and pushed to some remote host like github or gitlab. If I need anything, I just go there and fetch from some other project I wrote before.
As for editor snippets, you can probably check if your editor supports backups of your configurations, like Atom or VSCode does.