These days rapid Google searches are an invaluable tool for developers who are constantly getting to grips with a new language, framework or technique, where reading lengthy documentation would be a waste of time when the problem is simply a matter of finding the correct syntax.
For this reason I am very careful to record in short scripts all such useful examples and commit and push these into source code repositories that I maintain for myself. I have structured the repositories in a way (one repository per language, split into
projects directories), that they are highly amenable to searching by automated tool (usually ZSH function), so that usually to find the answer to a problem it is a matter of running one command from wherever I happen to be, and I am instantly reminded of the code that I need.
Holding onto your precious code is also a matter of pride in craft. Code does not often come cheap and can require significant expenditure of your time to find good solutions. I do not want that time to go to waste by having to repeat the process in future.