Snippets databases

This is a longish post… there were bunches of ideas rattling around in
my head.

I’ve been wondering how I can manage my snippets of code. I try to
experiment with self-contained examples whenever I have a particularly
interesting problem I want to remember the solution to. But it’s all
disorganized, and sometimes it’s housed past my END statements at
the end of various half-finished scripts. That’s a great way to lose my
snippets. =)

It’s a horror for me to suspect that I know how to solve a problem, and
that I’ve done it before, and not quite remember how I did it before
because I can’t find that one block of code.

The one thing I know about myself is that I will never entirely and
reliably remember enough of my past solutions. I know this is
unrealistic for most people but I know that it’s entirely impossible for
me. Nomatter how I absorb myself with something, I’ll always forget
bits of the knowledge. On the plus side, this makes me great with
documentation since I write everything down. =)

So, I want to house all of my snippets within a useful and
easily-used/searched documentation structure of some kind. Because this
is an itch, my personal rule/habit is for me to lay down some code to
solve the problem for myself. But this seems like a large-ish project.

What I really wanted to learn is:

Do you use a snippets-helper of some kind? If so, what?
Do you think it’s a good idea for me to make my own tool and then
outgrow it and use someone else’s afterwards?

It’s not a problem for me to reach out and find a couple of dozen
websites and applications which would solve this problem. But I just
wanted to hear some opinions/testimonials for existing tools. Some
people may use some interesting solutions that I might not find by
googling.

But a self-created database feel simple on the surface – just a few
fields, each are searchable: topic(s), title, abstract, keywords, code
code, example code, example output, ‘see also’ links, notes and maybe
some other stuff. I’d learn a bit of database stuff and some helpful
new libraries. It sounds like a definable project whose
completion-payoff would be incalculable. Actually, it sounds like a
Rails project, but I’m not ready to go there.

But I kindof imagine being able to search through all of my existing
projects to find real-world examples of the code in use. And then I
could somehow embed comments within my code which talked about the code
and helped the searchability. That’s definitely way over my head, but
if it were implemented elsewhere I’d love to use it.

There are some nice documentation systems out there but they seem
focused around single-project documentation and not on gathering info
and searching through an entire messy and unrelated collection of
scripts like what I’d want.

On Jul 14, 2007, at 11:31 AM, sy1234 wrote:

outgrow it and use someone else’s afterwards?
few fields, each are searchable: topic(s), title, abstract,
about the code and helped the searchability. That’s definitely way
over my head, but if it were implemented elsewhere I’d love to use it.

There are some nice documentation systems out there but they seem
focused around single-project documentation and not on gathering
info and searching through an entire messy and unrelated collection
of scripts like what I’d want.

Have you considered just setting up a blog (public or private). The
typical features therein would cover most of what you mentioned. Use
tags to help categorize and create refined searches. Comments to
keep notes, titles. The body could be your abstract + the code.

A second option might be to put your Abstract + Snippet up as a
Pastie and then file them with del.icio.us.

If you’re looking for software, there’s four or five competing
organizers for Macs. Most have silly names I can’t remember. Since I
don’t use any of these products, don’t consider this an endorsement,
but Yojimbo comes to mind.

Corey

On 7/14/07, sy1234 [email protected] wrote:

some other stuff. I’d learn a bit of database stuff and some helpful
There are some nice documentation systems out there but they seem
focused around single-project documentation and not on gathering info
and searching through an entire messy and unrelated collection of
scripts like what I’d want.

I think that is a good idea to start doing learning tests
(http://c2.com/cgi-bin/wiki?LearningTest). Just organize your
self-contained examples in unit test cases and give them proper names.
Then “grep” will do.

On 7/14/07, Aureliano C. [email protected] wrote:

I think that is a good idea to start doing learning tests
(http://c2.com/cgi-bin/wiki?LearningTest). Just organize your
self-contained examples in unit test cases and give them proper names.
Then “grep” will do.

I did this while dabbling with Haskell. Definitely recommendable.

On 7/14/07, sy1234 [email protected] wrote:

some other stuff. I’d learn a bit of database stuff and some helpful
There are some nice documentation systems out there but they seem
focused around single-project documentation and not on gathering info
and searching through an entire messy and unrelated collection of
scripts like what I’d want.

I usually pastie it with a =begin/=end block at the top explaining it,
then I del.icio.us that pastie. It’s pretty simple, and you can tag
and search.

Gregory B. said the following on 07/14/2007 04:55 PM:

On 7/14/07, Aureliano C. [email protected] wrote:

I think that is a good idea to start doing learning tests
(http://c2.com/cgi-bin/wiki?LearningTest). Just organize your
self-contained examples in unit test cases and give them proper names.
Then “grep” will do.

I did this while dabbling with Haskell. Definitely recommendable.

I can’t believe I didn’t remember this. I’ve even had this mentioned
before. This is definitely something I ought to get into!

I could also hack together a little search tool which would help me
search through the headers for my keywords or abstracts. Ooh… I like
it.

Corey J. said the following on 07/14/2007 03:04 PM:

Have you considered just setting up a blog (public or private). The
typical features therein would cover most of what you mentioned. Use
tags to help categorize and create refined searches. Comments to keep
notes, titles. The body could be your abstract + the code.

A blog might not be a bad idea. Right now I’ve got some notes dumped
into my wiki:
http://jrandomhacker.info/Ruby_code_snippets

But searchability goes way down, unless I start using categories as
tags… but it’s still messy unless I begin using namespaces and all
sorts of other nonsense. Basically my non-snippets efforts would get in
the way.

But something specialized which could also do code highlighting or even
some code execution like how Chris P.'s tutorial is set up – that
would be interesting.

Argh, I’m craving a hand-coded solution…

Ok, a blog is an interesting idea. I’ll note it.

A second option might be to put your Abstract + Snippet up as a Pastie
and then file them with del.icio.us.

If you’re looking for software, there’s four or five competing
organizers for Macs. Most have silly names I can’t remember. Since I
don’t use any of these products, don’t consider this an endorsement,
but Yojimbo comes to mind.
My first impression was negative. I think my main reasoning is the fact
that someone else would own that setup. Is there an easy way for me to
back up my snippets database?

I’ll write down a set of questions and check them off when I’m
researching this as a solution.

Thanks for the tips…

Chris C. said the following on 07/14/2007 05:07 PM:

I usually pastie it with a =begin/=end block at the top explaining it,
then I del.icio.us that pastie. It’s pretty simple, and you can tag
and search.
I’m leaning towards test cases now… but adding good headers would
definitely be nice. Plus I could probably unleash some third-party
documentation engine on the test snippets tree and have it build a fancy
browser-accessible interface…