From f514a3b9c7929026b8a3df42d6f81a9169b2687f Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:53:55 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 11 + README.md | 3 + commands/git-master.md | 337 ++++++++++++++++++++++++++++++ commands/performance-optimizer.md | 285 +++++++++++++++++++++++++ plugin.lock.json | 49 +++++ 5 files changed, 685 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/git-master.md create mode 100644 commands/performance-optimizer.md create mode 100644 plugin.lock.json diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..e7d5f81 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,11 @@ +{ + "name": "productivity-skills", + "description": "Workflow optimization skills for Git, performance profiling, and security auditing", + "version": "1.0.0", + "author": { + "name": "Claude Skills Marketplace" + }, + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ac6164d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# productivity-skills + +Workflow optimization skills for Git, performance profiling, and security auditing diff --git a/commands/git-master.md b/commands/git-master.md new file mode 100644 index 0000000..46bda19 --- /dev/null +++ b/commands/git-master.md @@ -0,0 +1,337 @@ +# Git Master + +**Description**: Master Git workflows, branching strategies, and advanced techniques + +## Git Workflow + +### Feature Branch Workflow +```bash +# 1. Create feature branch +git checkout -b feature/user-authentication + +# 2. Make changes and commit regularly +git add . +git commit -m "Add login form component" + +# 3. Push to remote +git push -u origin feature/user-authentication + +# 4. Keep branch updated with main +git fetch origin +git rebase origin/main + +# 5. Create pull request (via GitHub/GitLab UI) + +# 6. After merge, clean up +git checkout main +git pull origin main +git branch -d feature/user-authentication +``` + +## Essential Git Commands + +### Committing +```bash +# Stage specific files +git add file1.js file2.js + +# Stage all changes +git add . + +# Commit with message +git commit -m "Add user authentication" + +# Amend last commit +git commit --amend -m "Updated message" + +# Add to last commit without changing message +git add forgotten-file.js +git commit --amend --no-edit +``` + +### Branching +```bash +# Create and switch to branch +git checkout -b feature/new-feature + +# Switch branches +git checkout main + +# List branches +git branch # Local +git branch -r # Remote +git branch -a # All + +# Delete branch +git branch -d feature/old-feature +git branch -D feature/old-feature # Force delete + +# Rename branch +git branch -m old-name new-name +``` + +### Syncing +```bash +# Fetch changes +git fetch origin + +# Pull changes (fetch + merge) +git pull origin main + +# Pull with rebase (cleaner history) +git pull --rebase origin main + +# Push changes +git push origin feature/my-feature + +# Force push (use carefully!) +git push --force-with-lease origin feature/my-feature +``` + +### Undoing Changes +```bash +# Discard unstaged changes +git checkout -- file.js + +# Unstage files +git reset HEAD file.js + +# Undo last commit (keep changes) +git reset --soft HEAD~1 + +# Undo last commit (discard changes) +git reset --hard HEAD~1 + +# Revert a commit (creates new commit) +git revert abc123 +``` + +## Advanced Techniques + +### Interactive Rebase +```bash +# Clean up last 3 commits +git rebase -i HEAD~3 + +# In editor: +# pick abc123 First commit +# squash def456 Second commit +# fixup ghi789 Third commit + +# Squash = combine commits, keep both messages +# Fixup = combine commits, discard this message +``` + +### Cherry-Pick +```bash +# Apply specific commit from another branch +git cherry-pick abc123 + +# Cherry-pick multiple commits +git cherry-pick abc123 def456 ghi789 +``` + +### Stash +```bash +# Save work in progress +git stash + +# Stash with message +git stash save "WIP: working on feature X" + +# List stashes +git stash list + +# Apply stash +git stash pop # Apply and remove +git stash apply # Apply and keep + +# Apply specific stash +git stash apply stash@{2} + +# Delete stash +git stash drop stash@{0} + +# Clear all stashes +git stash clear +``` + +### Finding Issues +```bash +# Search commits +git log --grep="bug fix" + +# Show changes in file +git log -p file.js + +# Find who changed a line +git blame file.js + +# Find when bug was introduced (binary search) +git bisect start +git bisect bad # Current commit is bad +git bisect good abc123 # Known good commit +# Git will checkout commits to test +git bisect good/bad # Mark each +git bisect reset # When done +``` + +## Commit Message Best Practices + +``` +# Good commit message format +type(scope): Short description (max 50 chars) + +Longer explanation if needed (wrap at 72 chars). +Explain WHAT and WHY, not HOW. + +- Bullet points are okay +- Use present tense: "Add feature" not "Added feature" + +Closes #123 + +# Types: +feat: New feature +fix: Bug fix +docs: Documentation +style: Formatting (no code change) +refactor: Code restructuring +test: Adding tests +chore: Maintenance tasks +``` + +Examples: +``` +feat(auth): Add JWT authentication + +Implement JWT-based authentication system with refresh tokens. +Users can now login and maintain session across page reloads. + +Closes #456 + +--- + +fix(cart): Prevent duplicate items being added + +When clicking "Add to cart" rapidly, duplicate items were added. +Added debouncing to prevent this issue. + +Fixes #789 +``` + +## Git Configuration + +```bash +# User identity +git config --global user.name "Your Name" +git config --global user.email "you@example.com" + +# Default editor +git config --global core.editor "code --wait" + +# Useful aliases +git config --global alias.st status +git config --global alias.co checkout +git config --global alias.br branch +git config --global alias.cm "commit -m" +git config --global alias.lg "log --oneline --graph --all --decorate" + +# Auto-setup remote tracking +git config --global push.autoSetupRemote true +``` + +## .gitignore Best Practices + +``` +# .gitignore - Common patterns + +# Dependencies +node_modules/ +venv/ +__pycache__/ + +# Build outputs +dist/ +build/ +*.pyc +*.class + +# Environment files +.env +.env.local +.env.*.local + +# IDE files +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store + +# Logs +logs/ +*.log + +# Test coverage +coverage/ +.nyc_output/ +``` + +## Resolving Merge Conflicts + +```bash +# 1. Attempt merge +git merge feature/other-branch + +# CONFLICT message appears + +# 2. Check conflicted files +git status + +# 3. Open files and resolve conflicts +# Look for markers: +# <<<<<<< HEAD +# Your changes +# ======= +# Their changes +# >>>>>>> feature/other-branch + +# 4. Edit file to resolve +# Remove markers, keep desired code + +# 5. Mark as resolved +git add resolved-file.js + +# 6. Complete merge +git commit +``` + +## Branch Strategies + +### Gitflow +``` +main - Production code +develop - Integration branch +feature/* - New features +hotfix/* - Urgent fixes +release/* - Release preparation +``` + +### Trunk-Based +``` +main - Always deployable +feature/* - Short-lived (< 1 day) +``` + +## When to Use This Skill + +- Managing Git repositories +- Resolving merge conflicts +- Cleaning up commit history +- Implementing branching strategies +- Debugging with Git +- Setting up Git workflows + +--- + +**Remember**: Commit often, write clear messages, and keep branches short-lived! diff --git a/commands/performance-optimizer.md b/commands/performance-optimizer.md new file mode 100644 index 0000000..9c52c58 --- /dev/null +++ b/commands/performance-optimizer.md @@ -0,0 +1,285 @@ +# Performance Optimizer + +**Description**: Profile, measure, and optimize application performance systematically + +## Performance Optimization Process + +1. **Measure** - Profile to find bottlenecks +2. **Analyze** - Understand the root cause +3. **Optimize** - Implement improvements +4. **Verify** - Measure again to confirm + +## Frontend Performance + +### Measuring Performance +```javascript +// Using Performance API +const perfData = performance.getEntriesByType('navigation')[0]; +console.log('Page load time:', perfData.loadEventEnd - perfData.fetchStart); + +// Core Web Vitals +import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals'; + +getCLS(console.log); // Cumulative Layout Shift +getFID(console.log); // First Input Delay +getFCP(console.log); // First Contentful Paint +getLCP(console.log); // Largest Contentful Paint +getTTFB(console.log); // Time to First Byte +``` + +### React Optimization +```javascript +// 1. Memoization +const MemoizedComponent = React.memo(ExpensiveComponent); + +// 2. useMemo for expensive calculations +const sortedItems = useMemo(() => { + return items.sort(compareFunction); +}, [items]); + +// 3. useCallback for function references +const handleClick = useCallback(() => { + doSomething(id); +}, [id]); + +// 4. Lazy loading +const HeavyComponent = lazy(() => import('./HeavyComponent')); + +// 5. Code splitting +const routes = [ + { path: '/', component: lazy(() => import('./Home')) }, + { path: '/dashboard', component: lazy(() => import('./Dashboard')) } +]; + +// 6. Virtualize long lists +import { FixedSizeList } from 'react-window'; +``` + +### Browser Performance +```javascript +// Debounce expensive operations +function debounce(func, wait) { + let timeout; + return function(...args) { + clearTimeout(timeout); + timeout = setTimeout(() => func.apply(this, args), wait); + }; +} + +const handleSearch = debounce((query) => { + fetch(`/api/search?q=${query}`); +}, 300); + +// Use Web Workers for heavy computation +const worker = new Worker('worker.js'); +worker.postMessage({ data: largeDataset }); +worker.onmessage = (e) => { + console.log('Result:', e.data); +}; +``` + +## Backend Performance + +### Node.js Profiling +```bash +# CPU profiling +node --prof app.js +# Generates isolate-*.log + +# Process the log +node --prof-process isolate-*.log > processed.txt + +# Memory profiling +node --inspect app.js +# Open chrome://inspect in Chrome +``` + +### Database Optimization +```javascript +// ❌ Bad: N+1 query problem +const users = await User.findAll(); +for (const user of users) { + const posts = await Post.findAll({ where: { userId: user.id } }); + user.posts = posts; +} + +// ✅ Good: Use eager loading +const users = await User.findAll({ + include: [{ model: Post }] +}); + +// ❌ Bad: Select all columns +const users = await User.findAll(); + +// ✅ Good: Select only needed columns +const users = await User.findAll({ + attributes: ['id', 'name', 'email'] +}); + +// Add indexes +await queryInterface.addIndex('users', ['email']); +await queryInterface.addIndex('posts', ['userId', 'createdAt']); +``` + +### Caching +```javascript +// Redis caching +const redis = require('redis'); +const client = redis.createClient(); + +async function getUser(id) { + // Check cache first + const cached = await client.get(`user:${id}`); + if (cached) return JSON.parse(cached); + + // Fetch from database + const user = await User.findByPk(id); + + // Store in cache (expire after 1 hour) + await client.setex(`user:${id}`, 3600, JSON.stringify(user)); + + return user; +} + +// In-memory caching +const NodeCache = require('node-cache'); +const cache = new NodeCache({ stdTTL: 600 }); + +function expensiveOperation(key) { + const cached = cache.get(key); + if (cached) return cached; + + const result = doExpensiveCalculation(); + cache.set(key, result); + return result; +} +``` + +## Performance Testing + +### Load Testing with Artillery +```yaml +# artillery.yml +config: + target: "http://localhost:3000" + phases: + - duration: 60 + arrivalRate: 10 # 10 users per second + - duration: 120 + arrivalRate: 50 # Ramp up to 50/sec + scenarios: + - name: "API test" + flow: + - get: + url: "/api/users" + - post: + url: "/api/users" + json: + name: "Test User" + email: "test@example.com" +``` + +```bash +# Run load test +artillery run artillery.yml +``` + +### Benchmarking +```javascript +// Simple benchmark +console.time('operation'); +performOperation(); +console.timeEnd('operation'); + +// Detailed benchmark +const Benchmark = require('benchmark'); +const suite = new Benchmark.Suite; + +suite + .add('Array#forEach', function() { + [1,2,3].forEach(x => x * 2); + }) + .add('Array#map', function() { + [1,2,3].map(x => x * 2); + }) + .on('cycle', function(event) { + console.log(String(event.target)); + }) + .on('complete', function() { + console.log('Fastest is ' + this.filter('fastest').map('name')); + }) + .run(); +``` + +## Common Optimizations + +### 1. Bundle Size (Webpack) +```javascript +// webpack.config.js +module.exports = { + optimization: { + splitChunks: { + chunks: 'all', + cacheGroups: { + vendor: { + test: /[\\/]node_modules[\\/]/, + name: 'vendors', + priority: 10 + } + } + } + }, + performance: { + maxEntrypointSize: 512000, + maxAssetSize: 512000 + } +}; + +// Analyze bundle +npm install --save-dev webpack-bundle-analyzer +``` + +### 2. Image Optimization +```bash +# Convert to WebP +cwebp image.jpg -q 80 -o image.webp + +# Optimize PNG +pngquant image.png --output image-optimized.png + +# Responsive images +convert image.jpg -resize 400 image-400w.jpg +convert image.jpg -resize 800 image-800w.jpg +``` + +### 3. HTTP/2 & Compression +```javascript +// Express with compression +const compression = require('compression'); +app.use(compression()); + +// Nginx configuration +# gzip compression +gzip on; +gzip_types text/plain text/css application/json application/javascript; +``` + +## Metrics to Track + +- **First Contentful Paint (FCP)**: < 1.8s +- **Largest Contentful Paint (LCP)**: < 2.5s +- **Time to Interactive (TTI)**: < 3.8s +- **Cumulative Layout Shift (CLS)**: < 0.1 +- **First Input Delay (FID)**: < 100ms + +## When to Use This Skill + +- Application is slow +- Optimizing page load time +- Reducing server response time +- Improving database query performance +- Analyzing bundle size + +--- + +**Remember**: Measure first, optimize second. Don't guess where the bottleneck is! diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..386a765 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:samuelgarrett/claude-code-plugin-test:productivity-skills", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "e2895386bedf1e6168529ad9e43d2c3f486a0262", + "treeHash": "cb105bea723cbda8f7a61d4ab58bbafb9f4738566a0084508f4bc7eacaca51bc", + "generatedAt": "2025-11-28T10:28:08.228904Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "productivity-skills", + "description": "Workflow optimization skills for Git, performance profiling, and security auditing", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "8cbf946e8d6c098a3b61bac339de31a100ff82babf5f87c5d5f54c90325485f6" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "32f662e777956667c0f27d606a10d7d7cdeda15536c7a61f89a1b9431d200a12" + }, + { + "path": "commands/git-master.md", + "sha256": "54a3c56c1ed48e6bfdc47098f7fa4329f75d21a0199244e678d63667055b252c" + }, + { + "path": "commands/performance-optimizer.md", + "sha256": "f74419ee094c50ba6eec682cfb7954d3631c932a782170f05c73634e8a83a87b" + } + ], + "dirSha256": "cb105bea723cbda8f7a61d4ab58bbafb9f4738566a0084508f4bc7eacaca51bc" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file