Snippets section - a catalogue of solutions to common problems
I’ve added a snippets section to my website. It hosts a catalogue of short solutions to common problems that can be easily copied and pasted. Here are the initial 3 problems I tackled, it should give you the gist of what it’s all about:
Why are you doing this?
I don’t know about you, but generally I find that if I am researching certain problems, the results can be noisy. It takes time to pore over different eras of answers and opinions. For example, in 2025 I’m no longer concerned with Internet Explorer. Generally, I would prefer a solution that does not require a library. There is not a good filter for criteria or preferences like that.
This issue is very prevalent with JavaScript. JavaScript has had a meandering evolution. The need to deal with shortcomings of the language and inconsistencies across browsers means that many solutions are not straightforward. You will find a lot of answers use jQuery. You may not want to use that library now.
Over time, simpler solutions become possible as the language becomes more capable, and browser interop issues get resolved. While answers are updated on Stack Overflow, the information skews towards the prevailing wisdom of that time. Some threads have not aged well, but may be the first place that you are directed to when you search.
When you couple this with search engines struggling to surface high quality results, I think that there is a considerable benefit to keep your own catalogue. It does reflect your own taste to an extent.
The format
The loose format is:
- The code snippet along with a brief summary of the problem it solves
- A demo utilising the snippet
- An explanation. The detail will vary depending on the complexity of what is being explored. I like to include demos and interactive playgrounds to make things more approachable.
- Attribution, if someone else came up with the solution. It is good karma to give credit where it is due.
Secondary benefit
Another part of this is personal. I don’t want to blindly copy and paste code ad nauseam. I want to understand why something does what it does. Sometimes, I find that someone else’s explanation doesn’t quite click with me. I may need to read the spec or play with some code to understand something completely. This exploration can help to understand a topic more deeply and help to build more lasting knowledge. And it may provide an example that benefits you too.
Subscribe to the RSS feed
There is a RSS feed for snippets that can be found at: https://www.roboleary.net/snippets/feed.xml.
Final thoughts
I hope to form a healthy habit to regularly add to this catalogue as I encounter problems. If the solution is generic and is used regularly, I will also add the snippet to a snippets file in VS Code. It is convenient to be able insert a snippet directly into a codebase with a few keystrokes.
I haven’t made many forays into AI-based code assistance, but having inputs that reflect your own preferences and are of a high quality may also be benefical in the future.
If you have any thoughts, you can let me know!