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 Link
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 Code
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 Search
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 Link
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 Snippets48
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.
Snippi is a repository for Magento code. Currently there are more than 60 snippets included, from a number of different contributors.
10 Code Snippets for PHP Developers52
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 Project56
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 Link
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 https://www.smashingmagazine.com/2009/01/15/45-new-jquery-techniques-for-a-good-user-experience/
- 3 https://www.smashingmagazine.com/2009/03/24/10-useful-php-tips-revisited/
- 5 https://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://snipt.net/public/tag/css
- 13 http://snipt.net/public/tag/css
- 14 http://snippets.dzone.com/
- 15 http://snippets.dzone.com/
- 16 http://www.koders.com/
- 17 http://www.koders.com/
- 18 http://codesnippets.joyent.com/
- 19 http://codesnippets.joyent.com/
- 20 http://www.bytemycode.com/
- 21 http://www.bytemycode.com/
- 22 http://www.krugle.org
- 23 http://www.krugle.org
- 24 http://www.naslu.com/
- 25 http://www.naslu.com/
- 26 http://codecodex.com/wiki/index.php?title=Main_Page
- 27 http://codecodex.com/wiki/index.php?title=Main_Page
- 28 http://www.jonasjohn.de/snippets/
- 29 http://www.jonasjohn.de/snippets/
- 30 http://www.codase.com/
- 31 http://www.codase.com/
- 32 http://www.snipiti.com/
- 33 http://www.snipiti.com/
- 34 http://snippetsmania.com/
- 35 http://snippetsmania.com/
- 36 http://serverfault.com/
- 37 http://serverfault.com/
- 38 http://www.refactory.org/
- 39 http://www.refactory.org/
- 40 http://www.code-sucks.com/code/
- 41 http://www.code-sucks.com/code/
- 42 http://www.djangosnippets.org/
- 43 http://www.djangosnippets.org/
- 44 http://sebsauvage.net/python/snyppets/
- 45 http://sebsauvage.net/python/snyppets/
- 46 http://phpsnips.com/
- 47 http://phpsnips.com/
- 48 http://wiki.greasespot.net/Code_snippets
- 49 http://wiki.greasespot.net/Code_snippets
- 50 http://codebeach.org/
- 51 http://codebeach.org/
- 52 http://htmlblog.net/10-code-snippets-for-php-developers/
- 53 http://htmlblog.net/10-code-snippets-for-php-developers/
- 54 http://www.phpclasses.org/
- 55 http://www.phpclasses.org/
- 56 http://www.codeproject.com/
- 57 http://www.codeproject.com/
- 58 http://www.eclipse.org/swt/snippets/
- 59 http://www.eclipse.org/swt/snippets/
- 60 http://rubyforge.org/snippet/browse.php?by=lang&lang=17
- 61 http://www.rubyinside.com/8-more-useful-ruby-code-snippets-171.html
- 62 http://erikveenstra.nl/rubycodesnippets/index.html
- 63 http://rubyforge.org/snippet/browse.php?by=lang&lang=17
- 64 http://dotnetslackers.com/default.aspx
- 65 http://dotnetslackers.com/default.aspx
- 66 http://snipt.org/
- 67 http://snipt.org/
- 68 http://github.com/cnprog/CNPROG/tree/master
- 69 http://github.com/cnprog/CNPROG/tree/master
Hold on, Tiger! Thank you for reading the article. Did you know that we also publish printed books and run friendly conferences – crafted for pros like you? Like SmashingConf New York, on June 14–15, with smart design patterns and front-end techniques.