Live data from Hacker News

Ask HN: How do you keep track of small pieces of useful code?

news.ycombinator.com

21–30 of 30 posts

Re: Ask HN: How do you keep track of small pieces of useful code?

#21

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…

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 cas…

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.

Re: Ask HN: How do you keep track of small pieces of useful code?

#23
post #5

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.

Re: Ask HN: How do you keep track of small pieces of useful code?

#25
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.

Re: Ask HN: How do you keep track of small pieces of useful code?

#26
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.

Post reply on HN