Live data from Hacker News

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

news.ycombinator.com

11–20 of 30 posts

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

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

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

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

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

#15
post #12

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.

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

#17

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

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

#18

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?

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

#20
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).

Post reply on HN