Thank you for contributing to this code snippet repository! This guide will help you maintain consistency and quality.
Place your snippet in the most appropriate category folder:
-
csharp/- C# and .NET code -
python/- Python scripts and code -
javascript/- JavaScript/TypeScript code -
sql/- SQL queries and database code -
bash/- Bash scripts and shell commands -
powershell/- PowerShell scripts -
algorithms/- Algorithm implementations -
design-patterns/- Design pattern examples -
web/- HTML, CSS, web development -
docker/- Docker and containerization -
git/- Git commands and workflows -
utilities/- General utility scripts
If your snippet doesn't fit any existing category, consider creating a new one.
Copy the SNIPPET_TEMPLATE.md file and fill it out completely:
cp SNIPPET_TEMPLATE.md snippets/[category]/[snippet-name].mdFile Names:
-
Use lowercase letters
-
Use hyphens to separate words
-
Be descriptive but concise
-
Examples:
string-truncate.md,retry-pattern.md,docker-compose-example.md
Snippet Titles:
-
Use title case
-
Be clear and descriptive
-
Examples: "String Truncate", "Retry Pattern with Exponential Backoff"
Code Quality:
-
Write clean, readable code
-
Follow language-specific conventions and style guides
-
Include helpful comments for complex logic
-
Handle edge cases and errors appropriately
-
Use meaningful variable and function names
Examples:
-
Provide practical, real-world usage examples
-
Show different use cases when applicable
-
Include expected output or results
-
Demonstrate error handling
After adding a snippet, update the category's readme.md:
## Index
- [Your New Snippet](your-new-snippet.md) - Brief description
- [Existing Snippet](existing-snippet.md) - DescriptionInclude all relevant information:
-
Description: Clear explanation of purpose
-
Prerequisites: Dependencies, versions, platform requirements
-
Notes: Important considerations, limitations, alternatives
-
Tags: Relevant keywords for searchability
-
Related Snippets: Links to similar or complementary snippets
Before submitting a snippet, ensure:
-
Code is tested and working
-
Template is completely filled out
-
Code follows language best practices
-
Usage examples are clear and practical
-
Edge cases are handled or documented
-
Prerequisites are listed (if any)
-
Notes section includes important information
-
Related snippets are linked (if applicable)
-
Category README is updated
-
File name follows naming conventions
-
Code syntax highlighting is correct
-
No sensitive information (passwords, keys, etc.)
-
Clarity over Cleverness: Write code that's easy to understand
-
Completeness: Include all necessary imports, dependencies
-
Error Handling: Show proper error handling patterns
-
Comments: Explain "why" not "what" (code should be self-explanatory)
-
Security: Never include credentials, API keys, or sensitive data
C#:
-
Follow Microsoft C# coding conventions
-
Use meaningful names for variables, methods, classes
-
Include XML documentation comments for public APIs
-
Use async/await for asynchronous operations
Python:
-
Follow PEP 8 style guide
-
Use type hints where appropriate (Python 3.5+)
-
Include docstrings for functions and classes
-
Use list comprehensions appropriately
JavaScript:
-
Use modern ES6+ syntax
-
Prefer
constandletovervar -
Use arrow functions appropriately
-
Include JSDoc comments for complex functions
SQL:
-
Use UPPERCASE for SQL keywords
-
Use clear table and column aliases
-
Format queries for readability
-
Include comments for complex queries
Keep snippets organized by:
-
Primary language/technology (e.g., all Python in
python/) -
Specific subdomain if needed (e.g.,
python/data-science/) -
Related functionality (e.g., all string operations together)
When snippets are related:
-
Link to related snippets in the "Related Snippets" section
-
Mention alternative approaches
-
Create "See also" references where helpful
-
Start with what the snippet does
-
Explain when to use it
-
Mention key benefits
-
Include all necessary imports/using statements
-
Add inline comments for complex logic
-
Keep examples focused and concise
-
Show realistic examples
-
Include expected output
-
Demonstrate common use cases
-
Show error handling when relevant
-
Performance implications
-
Security considerations
-
Platform/version requirements
-
Known limitations
-
Alternative approaches
-
Common pitfalls
When updating a snippet:
-
Update the "Last Updated" date
-
Document what changed in git commit message
-
Ensure all sections are still accurate
-
Test the updated code
If a snippet becomes outdated:
-
Add a "DEPRECATED" warning at the top
-
Explain why it's deprecated
-
Link to the replacement snippet
-
Consider moving to an
archived/folder
Good examples in this repository:
-
csharp/string-truncate.md- Clear, well-documented, includes edge cases -
csharp/retry-pattern.md- Shows advanced pattern with good explanations -
python/file-operations.md- Comprehensive coverage with multiple methods -
javascript/array-methods.md- Multiple related examples organized well -
git/common-commands.md- Well-organized reference material
If you're unsure about:
-
Where to place a snippet
-
How to format something
-
Whether a snippet belongs here
Look at existing snippets in similar categories for guidance.
We follow the Conventional Commits standard.
Use one of the following types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
Run this once after cloning:
git config commit.template .gitmessage.txt
By contributing to this repository, you agree that your contributions will be subject to the same license as the repository.
Happy coding and snippet sharing!