Ask HN: How do you keep track of small pieces of useful code?
Is there some sort of Evernote for code? I'd love to be able to save small pieces of code with some accompanying documentation that describes how it works. I just have a giant .txt file, one for each programming language. Anything I google more than once goes there. It's an optimization. Useful for rare bits of code, but not so useful for common things like converting an int array to string array. The common things become muscle memory and are removed from the file. CTRL+F to search. Most of it is self-documenting, in the form of functions or methods that I can just copy into a project. I don't think any cloud based tools are useful for this because they're too slow with login and search. I use https://gist.github.com I have created two files everything.js and everything.php. Any time I find a useful function I just add it to those files with a comment and example (if php inside a !defined_fn block). For local weekend projects I'm not embarrassed to say that I sometimes just include the whole file. It saves me a lot of time and helps me work on the thing I intend to work on instead of searching the net or wasting time on thinking what implementation is the best. I mostly do frontend development, so I just use codepen, and tag all my codepens so its easy to search. Then I bookmark that page. I have all those files backed up by gists. I might try the "everything.php" or "everything.js" file, scrolling through a single page makes a lot of sense for me as well. But I find I just reference the actual repository in github for backend things, so I can see the context of the use case. Do you dump "everything.js" and "everything.php" in its own repo in dropbox? Would save the hassle of needing to commit it everytime, pull it from seperate PC's, etc. I'm still looking for a golden unicorn solution where I just look in one place while still offering micro-testing environments (like codepen). I've tried way too many code snippet solutions it just adds more friction to development Common snippets I have it all binded by macros. My goal is to have everything searchable in 3 steps max, one keyboard click, one file navigation button press, and grokking it to find the snippet. Yes I just used to dump everything in those file. But later on I realized that it makes more sense to segregate it into broad categories like net.php (google search, youtube, and website stuff related), mechanize.php (we crawler stuff) and everything.php (everything including the kitchen sink). It really doesn't even take me 3 steps to find it anymore since I name the functions quite intuitively (str_match_brackets_balanced) so anytime i type strbrackbal phpstorm automatically autocompletes the function for me. Similar for JS though I haven't been able to create any categories and everything.js is all that is. I like working in c#, so I have a folder in my Dropbox that holds a collection of linqpad files (.linq) about how to do something or other in c#. I also make sure to keep my custom classes/extensions in there as well as a folder within called "mockdata" which has exactly the content you'd expect; three versions of mock data I generated from Mockaroo: one that's a SQLite DB, a csv, and a json file. Also have a lorem.txt folder in there. I'd love to be able to reorganize that into three subfolders: one for .linq linq queries, one for .cs files instead of .linq files, and another for the mock data. Would be great if I could have all of my c# snippets in .cs files and play with them in VS Code, but I can only run the files in VS Code if I'm working with .NET Core. I've got a similar but far smaller collection for python snippets and experiments (i.e., playing with an API). Start a folder (or even a single file) for code snippets. If you want it accessible on many machines, put it in Dropbox, or a Github repo, or whatever you like. A separate "Evernote for code" is the last thing you need. Personally, I have "snippets.org" file in my "wiki/" subfolder on Dropbox. I second to this. The only difference on my use case is I treat each quality of life snippet as its own project, foldered with a sample executable if possible. Dropbox works perfect for non git, reference only code. Interesting question. I never have. I just search for it if I need it. Usually on the web, but sometimes in the codebase. I find the idea of a personal library of code snippets quite weird. The thought never crossed my mind and I know nobody who uses something like that. I feel like it would just add overhead; I remember what project I wrote that function for, now I also have to remember where it is in my everything library? Why? If you are on a Mac, you could try Quiver. It's a general purpose note taking app aimed at developers that handles code via Markdown. You can then tag and orgnaise everything. I use it along with Notability on iPad (for hand written stuff) I am the developer of canSnippet, a macOS (https://www.cansnippet.com/) and web-based (https://www.cansnippet.org/) snippet management tool. canSnippet allows the user to easily save and reuse pieces of useful code/text. In addition to the code itself, canSnippet also support tags and a description for your snippet. If it’s really that useful, I’ve probably used it once. So the next time I need it, I find the code where I used it last time. If I can find anything common that I think others would use, I'd blog it (under https://www.jvt.me/posts/categories/blogumentation/), and am looking at building common snippets into ie Ruby Gems that can be shared and improved over time I have a utilities library that I constantly expand and reference it in all projects. I have many code snippets, whih I keep either on Box Sync or Drive depending on platform. Would be happy to share them! Would you be interested? I'd definitely be interested in peeking at/copying other snippets too. I use both Gitlab snippets and a repository with a mkdocs website. Glad to hear that, if you need any help, feel free to reach out to community@gitlab.com. I think a git-like system complete with dependency resolution at function level like Ritch Hickey told in a podcast about would be a great sollution for code reuse. I have one giant emacs org-mode file. It contains most of my brain, I wish I started this when I was younger. I find MS OneNote to be a great tool. Easy to organize, easy to toss stuff into. Fast. I have a whole directory tree ~/useful/{scripts,snippets,values}/ etc. Private Github gists. But I also have a dropbox for bad code I find in projects. Thanks for mentioning this. Since my workflow and even setting up a new laptop, virtual machine, etc is all git based for me, using gists could be a great addition for me. In my zim-wiki Computer directory, I have a page called 0_Quickies. Editor snippets! GitHub gists very often a "remark" or a non compiling comment is included in the source code snippet.
e.g. rem "this code does nothing"
alternate functionalities may written as a "remark" and copypasted or edited to make it a compiling line of code so that you can quickly edit the source code and not have to type so much, or go looking through a codesnippit database to find the tool you need...
the actual source code script , depends of course on what language you are using, i chose a pseudo BASIC bcz , well its basic... let i=1
for i=0
beep
else end