
code library
包含多种编程语言的实用代码片段,帮助学习和应用。
Repository Info
About This Server
包含多种编程语言的实用代码片段,帮助学习和应用。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
Code Library
Welcome to the Code Library! This repository contains categorized examples and snippets for various programming and scripting languages. Each section is designed to provide practical, real-world examples to help you learn and apply concepts effectively.
Table of Contents
- Python
- Basic Examples
- Advanced Examples
- Shell Scripting
- Basic Examples
- Advanced Examples
- SQL
- Basic Examples
- Advanced Examples
- Rust
- Basic Examples
- Advanced Examples
- Node (JS)
- Basic Examples/basic-examples.md)
- Advanced Examples/advanced-examples.md)
- Prerequisites & Environment
- How to Use This Repository
- LLM / Tooling Integration
- Using as an MCP Server
- Contributing
Python
Explore Python examples ranging from beginner-friendly snippets to advanced use cases. Assumes Python 3.
- Basic Examples: Foundational concepts like file I/O, JSON handling, environment variables, basic logging, and argument parsing.
- Advanced Examples: Concurrency (
multiprocessing,asyncio), performance (Parquet, memory profiling), scientific computing (scipyinterpolation, optimization), ML utilities (sklearnscaling, splitting, persistence, metrics), and robust utilities (YAML, SQLAlchemy Core, regex).
Shell Scripting
Master shell scripting with examples covering file management, text processing, and robust scripting practices. Primarily uses bash.
- Basic Examples: Robust script templates (
set -euo pipefail,trap), argument parsing (getopts),find/xargsusage, text processing (awk,sed,join), and basiccurl/jqinteraction. - Advanced Examples: Advanced
parallelusage, database interaction (psql), cloud CLI scripting (AWS example), file locking (flock), checkpointing/resuming, and advanced parameter expansion.
SQL
Learn SQL concepts with examples demonstrating querying, data manipulation, and analysis patterns. Examples aim for ANSI SQL but note dialect differences.
- Basic Examples: Core DML/DDL (
SELECT,INSERT,UPDATE,DELETE,CREATE TABLE), filtering (WHERE), joins (INNER,LEFT), aggregation (GROUP BY,HAVING), subqueries, CTEs (WITH), basic window functions (ranking,LAG/LEAD),CASE WHEN, andNULLhandling. - Advanced Examples: Recursive CTEs, pivoting/unpivoting, sessionization, cohort analysis, querying complex types (JSON, arrays), and statistical functions.
Rust
Examples demonstrating common tasks and advanced features in Rust. Requires the Rust toolchain (cargo).
- Basic Examples: Core I/O (file reading/writing), JSON handling (
serde_json), command-line parsing (clap), logging (env_logger), and basic web requests (reqwest). - Advanced Examples: Concurrency (
tokiotasks,mpscchannels), advanced error handling (thiserror), custom derive macros, WebSockets (tokio-tungstenite), advanced pattern matching, parallelism (rayon), and structured logging (tracing).
Node (JS)
Leverage Node.js for backend development and scripting with these examples.
- Basic Examples/basic-examples.md): Covers core JavaScript data structures and manipulation (Strings, Arrays, Objects, Types) alongside fundamental Node.js modules like
fs(async/sync file I/O, JSON),path, basichttpserver creation, Promises, and utilities (console, timers). - Advanced Examples/advanced-examples.md): Explores advanced concepts including Streams (reading large files, piping), concurrency/parallelism (
worker_threads,child_process), web development withexpress(middleware, routing, error handling), database interaction (pgfor PostgreSQL), real-time communication withws(WebSockets), and configuration management (dotenv).
Prerequisites & Environment
- Examples are generally tested on macOS/Linux environments.
- Python: Assumes Python 3. Specific libraries needed are usually imported within the snippets.
- Shell Scripting: Primarily targets
bash(v4.0+ recommended for features like associative arrays). Relies on common utilities (grep,sed,awk,find,xargs,curl). Advanced examples may require specific tools likejq,parallel,psql, or cloud CLIs (aws). - SQL: Examples aim for ANSI SQL, but syntax for specific functions (dates, JSON, arrays, window functions) varies significantly between databases. Always test against your target system (PostgreSQL, MySQL, SQL Server, etc.).
- Rust: Requires the Rust compiler and
cargo(the package manager) installed. Dependencies are listed in comments or would typically be in aCargo.tomlfile.
How to Use This Repository
- Navigate to the relevant section based on the language or topic you are interested in.
- Open the linked Markdown files for detailed examples and explanations.
- Copy and adapt the code snippets to your own projects as needed.
LLM / Tooling Integration
An index file (llm.json) is provided at the root of the repository. This file contains metadata about each example set, including language, level, keywords, and paths to associated standalone snippet files. It is designed to help language models or automated tools efficiently navigate the code library and locate relevant examples based on specific queries.
Using as an MCP Server
This repository can be integrated as an MCP (Multi-Code Provider) server in various development environments using the gitmcp.io service. This allows AI assistants within these tools to directly access and reference the code snippets from this library.
Below are the configuration instructions for common tools:
Cursor:
Update your ~/.cursor/mcp.json:
{
"mcpServers": {
"code-library Docs": {
"url": "https://gitmcp.io/dperussina/code-library"
}
}
}
Claude Desktop:
Update your claude_desktop_config.json:
{
"mcpServers": {
"code-library Docs": {
"command": "npx",
"args": [
"mcp-remote",
"https://gitmcp.io/dperussina/code-library"
]
}
}
}
Windsurf:
Update your ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"code-library Docs": {
"serverUrl": "https://gitmcp.io/dperussina/code-library"
}
}
}
VSCode:
Update your .vscode/mcp.json (within your workspace):
{
"servers": {
"code-library Docs": {
"type": "sse",
"url": "https://gitmcp.io/dperussina/code-library"
}
}
}
Cline:
Update your ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json:
{
"mcpServers": {
"code-library Docs": {
"url": "https://gitmcp.io/dperussina/code-library",
"disabled": false,
"autoApprove": []
}
}
}
Contributing
Contributions are welcome! If you have additional examples or improvements, feel free to submit a pull request.
Happy coding!
Quick Start
Clone the repository
git clone https://github.com/dperussina/code-libraryInstall dependencies
cd code-library
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.