The beauty of code snippets is their ability to save you time when developing a site. Whether you keep a file with your own often-reused snippets or turn to one of the many online repositories, snippets can really speed up your site development.
There are plenty of places online to find code snippets and get answers to your coding questions. And many of these places let you upload your own snippets, either for personal use or to share with the community. They can also be a great place to find inspiration if you’re trying to figure out the best approach for any aspect of your site’s development.
Be sure to check out some of our previous articles:
- 45+ New jQuery Techniques For Good User Experience2
- 10 Advanced PHP Tips Revisited3
- 70 Expert Ideas For Better CSS Coding5
1. General Snippet Repositories and Resources
The repositories and resources featured below cover multiple languages and platforms. Some have thousands of code snippets while others might only have a couple hundred. Most of them let you search by language, tag, author, or keyword. And most of them let you upload your own snippets or questions.
Stack Overlow is a great site to check out if you have a programming question. Post your question and wait for answers. You and other users can then vote on the answers posted. You can also search questions based on keywords or tags, view unanswered questions, and sort by newest, oldest, featured, and other criteria.
Tipster, from Carsonified (the producers of the Future of Web Design conference), is a place to share and find tips from other web designers. In addition to searching tips, you can also view hot tips and vote tips up the charts.
Snipt is a code repository that allows you to save public or private snippets. There are snippets available in just about every programming language and web technology you could ask for. Some of the snippets are incredibly useful, such as prebuilt HTML test pages for creating your CSS.
Koders is a code repository with nearly 2.5 billion lines of open source code. The search engine they use is very powerful and allows you search based on a variety of different criteria, including by class, method, interface, and more.
Here’s another public source code repository that lets you share your code or keep it private. Currently, there are more than 4,000 users sharing snippets. One of the nicer features of this particular repository is the ability to subscribe to an RSS feed of all snippets or just those tagged with particular keywords.
ByteMyCode splits up their snippets based on programming language. There are tags for CSS, HTML, MySQL, Java, PHP, and just about anything else you could think of. You can browse by tag, new snippets or top snippets, or search by keyword.
Refactor My Code24
This is a great resource if you want to get others to check your code for errors or inefficiencies. Just post some code, let other members know what you need help with, and wait for responses. You can also browse through “refactorings” and codes based on language.
CodeCodex is a wiki-based code repository that lets members not only share code, but also improve code shared by others. It also lets users reorganize the library to make it more efficient and easier to find specific bits of code.
Github offers a number of forked repositories in a huge variety of languages. You can browse repositories based on what’s popular, or search based on keyword, size, the number of forks, and more. Popular repositories include Rails, Scriptaculous, and MaNGOS.
Google Code Search38
This code search engine from Google lets you search public source code from across the web. The advanced search lets you search within languages, licenses, packages, files, and more.
Code:Keep is a repository of nearly 15,000 snippets in just about every language out there. You can browse or search, or even look up code based on an author’s email address (great for finding your own contributed code).
DevSnippets is an online snippet gallery that provides snippets as well as useful development articles for a variety of platforms and languages. Snippets are located off-site, generally on the blogs of their respective creators.
Server Fault is a question and answer site aimed at IT pros and system administrators. It’s completely free and there’s no registration required. Just post a question and wait for answers. You can see how many times your question has been viewed, how many answers have been offered, and how many votes the question has received.
Refactory is a community-maintained collection of snippets available for public use. There’s no registration required to contribute. You can view snippets based on language or other tags (like “image” or “forms” or “anchor”).
2. Language- and Platform-Specific Repositories
The code repositories below are all dedicated to a single language or platform. These are excellent resources if you’re stuck on a certain function and the general repositories have failed you. They’re also a great place to keep your code snippets or share them with others who are more like-minded than general repository users. While most of the repositories here are small, with only a few dozen to a couple hundred snippets, there are some that offer more.
This repository contains snippets of code specific to the Django web framework. You can view snippets based on rating, tag, author, language, or how many times they’ve been bookmarked. You can also subscribe to a feed of the latest snippets.
Snyppets is a repository of Python code, mini-guides, recipes, links, tutorials, examples and ideas. They include basic code right up through advanced topics. The entire site is built on a single HTML page to make saving for offline reference easy.
This is a CSS repository that focuses on snippets for building grid and columb-based layouts. It doesn’t contain a huge number of snippets, but those it does include are very useful, and it’s easier to find what you’re looking for.
This site offers a huge repository of Visual Basic code snippets. You search by language (C#, Visual Basic, XML, or J#). It’s not a huge repository, with a little over 100 snippets, but it’s still a valuable resource for Visual Basic programmers, and it does let you add your own snippets to the site.
GreaseSpot Code Snippets64
This is a wiki-based site that serves as a repository for GreaseMonkey scripts. It includes a ton of useful scripts for everything from getting elements based on CSS selector to adding commas to numbers to forcing links to open in new windows and a lot more.
Code Beach is a repository for Mac developers. You can find code available under a variety of open source licenses (though everything on the site has to be available for commercial use). They also have an open submission policy, so anyone can contribute snippets and classes without having to register.
10 Code Snippets for PHP Developers70
This is a blog post covering ten useful code snippets. It includes an email address check, random password generator, get IP address, XSL transformation, force downloading of a file, string encoding to prevent harmful code, sending mail, uploading of files, list files in directory, and querying RDBMS with MDB2.
This is a PHP code repository that lets you search PHP Class Scripts, tutorials, and more. There are a huge number of scripts and snippets covering almost any aspect of PHP coding included. The site is mirrored all over the world and does require that you select a mirror before browsing.
The Code Project74
The Code Project has nearly 24,000 development and design articles, code snippets, and other resources available. It focuses on Microsoft-based and related languages like ASP.NET and C#.
This is a huge repository of snippets for SWT (The Standard Widget Toolkit). Code includes snippets related to accessibility, browser functions, cursors, display, grid layouts, and more.
This is a small collection of Ruby and Ruby on Rails snippets from Arto Bendiken. There are snippets included for generating random passwords, simple RSS parsing, and determining image size, among others.
3. Other Code Snippet Resources
Here are a few other resources for finding code if the repositories above have failed you, for sharing your code outside of a repository, or even creating your own snippet or Q & A site.
Codefetch lets you search code snippets within programming books and makes it easy for you to then order the books that fit your needs. It covers a variety of different languages, including PHP, Java, Python, and Perl.
- 2 http://www.smashingmagazine.com/2009/01/15/45-new-jquery-techniques-for-a-good-user-experience/
- 3 http://www.smashingmagazine.com/2009/03/24/10-useful-php-tips-revisited/
- 5 http://www.smashingmagazine.com/2007/05/10/70-expert-ideas-for-better-css-coding/
- 6 http://stackoverflow.com/questions/tagged/css
- 7 http://stackoverflow.com/questions/tagged/css
- 8 http://snipplr.com/popular/language/css
- 9 http://snipplr.com/popular/language/css
- 10 http://www.smipple.net/
- 11 http://www.smipple.net/
- 12 http://tipster.carsonified.com/
- 13 http://tipster.carsonified.com/
- 14 http://snipt.net/public/tag/css
- 15 http://snipt.net/public/tag/css
- 16 http://snippets.dzone.com/
- 17 http://snippets.dzone.com/
- 18 http://www.koders.com/
- 19 http://www.koders.com/
- 20 http://codesnippets.joyent.com/
- 21 http://codesnippets.joyent.com/
- 22 http://www.bytemycode.com/
- 23 http://www.bytemycode.com/
- 24 http://refactormycode.com/
- 25 http://refactormycode.com/
- 26 http://www.krugle.org
- 27 http://www.krugle.org
- 28 http://www.naslu.com/
- 29 http://www.naslu.com/
- 30 http://codecodex.com/wiki/index.php?title=Main_Page
- 31 http://codecodex.com/wiki/index.php?title=Main_Page
- 32 http://www.jonasjohn.de/snippets/
- 33 http://www.jonasjohn.de/snippets/
- 34 http://github.com/popular/forked
- 35 http://github.com/popular/forked
- 36 http://www.codase.com/
- 37 http://www.codase.com/
- 38 http://www.google.com/codesearch
- 39 http://www.google.com/codesearch
- 40 http://www.snipiti.com/
- 41 http://www.snipiti.com/
- 42 http://codekeep.net/
- 43 http://codekeep.net/
- 44 http://snippetsmania.com/
- 45 http://snippetsmania.com/
- 46 http://devsnippets.com/
- 47 http://devsnippets.com/
- 48 http://serverfault.com/
- 49 http://serverfault.com/
- 50 http://www.refactory.org/
- 51 http://www.refactory.org/
- 52 http://www.code-sucks.com/code/
- 53 http://www.code-sucks.com/code/
- 54 http://www.djangosnippets.org/
- 55 http://www.djangosnippets.org/
- 56 http://sebsauvage.net/python/snyppets/
- 57 http://sebsauvage.net/python/snyppets/
- 58 http://phpsnips.com/
- 59 http://phpsnips.com/
- 60 http://konstruktors.com/Main/HomePage
- 61 http://konstruktors.com/Main/HomePage
- 62 http://www.gotcodesnippets.net/default.aspx
- 63 http://www.gotcodesnippets.net/default.aspx
- 64 http://wiki.greasespot.net/Code_snippets
- 65 http://wiki.greasespot.net/Code_snippets
- 66 http://codebeach.org/
- 67 http://codebeach.org/
- 68 http://snippi.net/
- 69 http://snippi.net/
- 70 http://htmlblog.net/10-code-snippets-for-php-developers/
- 71 http://htmlblog.net/10-code-snippets-for-php-developers/
- 72 http://www.phpclasses.org/
- 73 http://www.phpclasses.org/
- 74 http://www.codeproject.com/
- 75 http://www.codeproject.com/
- 76 http://www.eclipse.org/swt/snippets/
- 77 http://www.eclipse.org/swt/snippets/
- 78 http://bendiken.net/snippets/ruby
- 79 http://bendiken.net/snippets/ruby
- 80 http://rubyforge.org/snippet/browse.php?by=lang&lang=17
- 81 http://www.rubyinside.com/8-more-useful-ruby-code-snippets-171.html
- 82 http://erikveenstra.nl/rubycodesnippets/index.html
- 83 http://rubyforge.org/snippet/browse.php?by=lang&lang=17
- 84 http://dotnetslackers.com/default.aspx
- 85 http://dotnetslackers.com/default.aspx
- 86 http://www.codefetch.com/
- 87 http://www.codefetch.com/
- 88 http://snipt.org/
- 89 http://snipt.org/
- 90 http://github.com/cnprog/CNPROG/tree/master
- 91 http://github.com/cnprog/CNPROG/tree/master