snippet library.
a collection of code chunks i always forget and end up googling. now centralized.
Undo Last Commit
#git#version-control
bash
git reset --soft HEAD~1Undo the last commit but keep changes in staging.
Kill All Docker Containers
#docker#devops
bash
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)Stop and remove all running containers.
Simple Email Regex
#regex#validation
regex
^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$A basic regex for validating email addresses.
JS Sleep Function
#javascript#utils
javascript
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));Promise-based sleep function for async/await.
Absolute Centering
#css#layout
css
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}The classic way to center a div.
React useEffect Once
#react#hooks
typescript
useEffect(() => {
const controller = new AbortController();
// do work
return () => controller.abort();
}, []);Run an effect only once on mount (strict mode safe-ish).
Grid Centering
#css#layout
css
.center {
display: grid;
place-items: center;
}The modern way to center a div.
Git Nuke Branch
#git#destructive
bash
git branch -D branch_name && git push origin --delete branch_nameDelete a branch locally and remotely.
TS Typed Sleep
#typescript#utils
typescript
const sleep = (ms: number): Promise<void> => new Promise(r => setTimeout(r, ms));Sleep function with proper typing.
Docker Rebuild
#docker#devops
bash
docker-compose up -d --build --force-recreateForce rebuild containers.
Postgres Backup
#postgres#db
bash
pg_dump -U username -h localhost dbname > backup.sqlDump a postgres database to a file.
Debounce Function
#javascript#utils
javascript
const debounce = (fn, delay) => {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), delay);
};
};Limit how often a function can fire.
Docker System Prune
#docker#cleanup
bash
docker system prune -a --volumesClean up unused containers, networks, images.
React Memo Component
#react#optimization
typescript
const MyComponent = React.memo(({ prop }) => {
return <div>{prop}</div>;
}, (prev, next) => prev.prop === next.prop);Prevent unnecessary re-renders.
Random Hex Color
#javascript#colors
javascript
const randomColor = () => "#" + Math.floor(Math.random()*16777215).toString(16);Generate a random hex color code.
Git Amend (No Edit)
#git#workflow
bash
git commit --amend --no-editAdd staged changes to previous commit without changing message.
Hide Scrollbar
#css#ui
css
.no-scrollbar::-webkit-scrollbar {
display: none;
}
.no-scrollbar {
-ms-overflow-style: none;
scrollbar-width: none;
}Hide scrollbar but allow scrolling.