Managing Code Snippets
Use mahpastes as a personal code snippet library. Store, organize, and reuse code fragments across projects.
Why Use mahpastes for Snippets?
- Quick access: Faster than searching through old projects
- Cross-project: Snippets available regardless of current project
- Editable: Modify snippets before using
- Searchable: Find snippets by filename or content type
Saving Code Snippets
From Your Editor
- Select code in your editor
- Copy (Cmd/Ctrl + C)
- Switch to mahpastes
- Paste (Cmd/Ctrl + V)
The code is saved as a text clip.
Tips for Saving
Use descriptive paste context: When you paste, the clip is named pasted_text_<timestamp>.txt. For better organization, consider:
- Creating a text file with a descriptive name
- Pasting your code into it
- Dragging the file into mahpastes
Example names:
react-useEffect-cleanup.jspython-async-retry-pattern.pysql-pagination-query.sql
Organizing Snippets
Archive Important Snippets
Keep valuable snippets in the archive:
- Find the snippet in the gallery
- Open the clip menu (three dots) and click Archive
- Snippet moves to Archive view
Benefits:
- Won't be accidentally deleted
- Separate from temporary clips
- Easy to find in Archive
Use Search
Filter snippets by filename or content type:
- Type in the search bar
- Results filter instantly
- Find your snippet quickly
Search matches against the filename and content type (MIME type), not the full snippet body. For example, searching text matches clips with a text/plain content type, and searching python matches a file named python-retry.py.
Search tips:
- Include the language in the filename:
python,react,sql - Include the snippet purpose in the filename:
retry,pagination,auth - Include the project name in the filename when it matters
Using Snippets
Copy and Paste
- Find your snippet
- Open the clip menu (three dots), hover over Copy, and click Contents
- Paste into your editor
Modify Before Using
Often you need to customize a snippet:
- Open the clip menu (three dots) and click Edit
- Modify the code in the editor
- Either:
- Click Save to overwrite the current clip
- Click Save As (creates a new clip with your changes)
- Copy the text and close the editor (keeps original unchanged)
Copy Path for CLI
Some tools work better with file paths:
- Open the clip menu (three dots)
- Hover over Copy, then click Path
- Path is copied to clipboard
- Use in terminal:
# View with syntax highlighting (if bat installed)
bat "$(pbpaste)"
# Source a shell script
source "$(pbpaste)"
# Run a Python script
python "$(pbpaste)"
If you are not on macOS, replace pbpaste with your platform's clipboard command.
Snippet Categories
Configuration Templates
Store config file templates:
// package.json template
{
"name": "my-project",
"version": "1.0.0",
"scripts": {
"start": "node index.js",
"test": "jest"
}
}
Archive these for repeated use.
Utility Functions
Common helper functions:
// Debounce function
function debounce(fn, delay) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(...args), delay);
};
}
API Patterns
Request patterns you use often:
# Retry with exponential backoff
async def retry_request(fn, max_retries=3):
for attempt in range(max_retries):
try:
return await fn()
except Exception as e:
if attempt == max_retries - 1:
raise
await asyncio.sleep(2 ** attempt)
SQL Queries
Reusable query patterns:
-- Pagination query
SELECT *
FROM items
WHERE id > :last_id
ORDER BY id
LIMIT :page_size
Shell Commands
Complex commands you want to remember:
# Find and delete node_modules
find . -name "node_modules" -type d -prune -exec rm -rf {} +
# Git log with graph
git log --oneline --graph --all --decorate
Workflow Examples
Starting a New Project
- Open Archive in mahpastes
- Search for "template" or project type
- Copy configuration files
- Paste into new project
- Customize as needed
Implementing a Pattern
- Search for the pattern name
- Open snippet in editor
- Customize for current context
- Copy the modified version
- Paste into your code
Sharing with Team
- Find relevant snippets
- Select multiple (Shift-click)
- Download them as a ZIP archive
- Share with team
- Each person imports into their mahpastes
Tips
Naming Conventions
Use consistent naming:
language-purpose-variant.extreact-form-validation.jspython-db-connection-pool.py
Keep Snippets Focused
Each snippet should do one thing:
- ✅ Single function
- ✅ One config file
- ❌ Entire module with many functions
- ❌ Multiple unrelated utilities
Update Regularly
When you improve a snippet:
- Edit it in mahpastes
- Use Save to overwrite it, or Save As to keep the original and create a new version
Version Control Alternative
For extensive snippet libraries, consider:
- A Git repository of snippets
- Watch folder pointing to the repo
- mahpastes auto-imports updates
Limitations
mahpastes is great for quick access to snippets but isn't a replacement for:
- Full-featured snippet managers with variables
- IDE snippet expansion
- Version-controlled snippet repositories
Use mahpastes for:
- Quick capture of useful code
- Cross-project code storage
- Temporary code storage during development