tags:

views:

877

answers:

10

So I assume I'm not the only one. I'm wondering if there are others out there who have compiled a personal code library. Something that you take from job to job that has examples of best practices, things you are proud of, or just common methods you see yourself using over and over.

I just recently started my C# library. It already has quite a few small items. Common Regex validations, interfaces for exception handling, some type conversion overloads, enum wrappers, sql injection detection methods, and some common user controls with AJAX toolkit examples.

I'm wondering what kind of things do you have in yours?

+3  A: 

I have found that using Snipplr makes this incredibly convenient. You can tag items, save favorites, search by keyword, etc. I mostly use it for Vim-related snippets (common commands, vimrc file, etc.), but it can be used for anything. Check it out.

Ben Hoffstein
+5  A: 

Because I primarily do web development, I've abstracted out some common features that I end up doing frequently on sites for clients.

  • Ajax Emailer. Nearly every site I work on has some type of contact form. I wrote a utility that allows me to drop some HTML on a page, having JavaScript field validation, and a PHP library that requires me to change a few parameters to work with each client's mail server. The only thing I have to write is CSS each time I include it on to a page.

  • Stylesheet skeleton generator. I wrote a small JavaScript utility that walks the DOM for whatever page it has been included on and then stubs out a valid CSS skeleton so that I can immediately start writing styles without having to do the repetitive task for every site I work on.

  • JavaScript Query String Parser. Occasionally I need to parse the query string but it doesn't warrant any major modifications to the server (such as installing PHP), so I wrote a generic JavaScript utility that I can easily configure for each site.

I've got other odds and end utilities, as well, but they are kind of hacked together for personal use. I'd be embarrassed to let anyone see the source.

Update

Several people have asked for my stylesheet skeleton generator in the comments so I'm providing a link to the project here. It's more or less based on the way that I structure my XHTML and format my CSS, but hopefully you'll find it useful.

Tom
Care to share the stylesheet skeleton generator? That sounds very interesting and helpful!
Chris Marasti-Georg
Wow, I totally agree with Chris. Your own perogative of course, but it would be very kind :)
thesmallprint
I was also going to ask for the js query string parser, because I will need something like that soon. If it intrigues anyone else, I found some nice code here to do the trick: http://groups.google.com/group/jquery-en/browse_thread/thread/c43ee339e0b3960f/527c5ab71c2e92bc
Chris Marasti-Georg
+8  A: 

I use my own wiki where I post code snippets and commentaries.

I find that more useful than having my own library. And since they are essentially notes and not full programs there isn't a problem with who owns the code (you or your employer ).

PS: I don't hide the fact that I have that from my employer. In fact most of them were positive and even asked for a copy.

Luka Marinko
@Luka For a while, I was using a wiki to keep personal notes, snippets, etc. for things I was doing at work; however, I ended up moving to Google Docs to do that. Nonetheless, I find that having something like this is really useful!
Tom
If you're interested in a personal wiki, but want it now check out http://tiddlywiki.com/
CrashCodes
+1  A: 

Back in the days of C programming on MacOS 7, i did write a fairly extensive OO library (yes, OOP in very old C) mostly to handle dialog windows. I abandoned it for PowerPlant (a nice C++ from Metrowerks) during the switch from 68k to PPC processors.

A little after that, i began writing web apps, first in PHP, recently in Django. On this aspect, my reusable code is limited to some tricks and code style.

But for all non-web (or with only small web componets), i've been using Lua. It's so fast to write and rewrite code, that there's very little incentive in reusing code. I mean, what's the point of copying a 10 line function and then adapt it? it's faster to rewrite it just for this project.

That's not so wasteful as it sounds. Lua code is so succint that my apps can be very complex, but seldom have more than a couple thousands lines.

At the same time, several Lua projects imply interfacing to C libraries. It's very easy to write bindings to existing libraries, so i just do that as a subproject. And these modules are what i do reuse! once and again... with very little (if any) changes from one project to the other.

In short: non-web projects are usually one-off Lua code, and some heavily reused binding modules.

Javier
A: 

I have several utility MATLAB functions that I have taken with me as I move from job to job, particularly ones that enforce W3C standards on the plots I make to ensure that text and background colors have a good luminosity ratio. I also have a function that uses ActiveX to insert a MATLAB figure into PowerPoint.

Scottie T
A: 

I keep my personal code libraries on CPAN. I'm not even sure how I'd do this in other languages anymore. It's just too integrated in the way that I think about programming now.

Tanktalus
+1  A: 

I have my personal C++ cross platform library here: http://code.google.com/p/kgui/

It's open source LGPL, I use it in my hobby / volunteer projects. I started it about 3 years ago and have been slowly adding functionality to it.

KPexEA
A: 

For my PHP work I started with a small file of simple things: a mail function that checks inputs for header attacks, and email validator, an input srubber, that type of thing. Over time it has grown into a application framework for quickly developing one off applications that can be templated by our graphic designer.

acrosman
A: 

I have a library that i use quite extensively. I started fresh with c# and kinda threw all of the legacy stuff out the window. I find them very handy and i rewrite/refactor them often (some of them). Some of the stuff i have is:

  • Auxiliary (things like IsRunningLocal, InternetDetection)
  • Standard Classes or Structs for: Address, CreditCard, Person
  • I have .dll's for both win and web stuff, some very logical like a .dll for shopping cart stuff
schmoopy
A: 

I wrote a quick and simple library in Java which I can add code snippets to. I plan to extend it to a full framework for development at some point but only when time allows. I have all sorts in there from simple functions to full blown pages and features. Its so helpful to have when developing because as a web designer, all I need to do is change the CSS of the page.