Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
2 snippets tagged #port · Show all
SQL
October 20, 2026
MySQL group by month and count rows per period
Counts rows per month for reports and charts. DATE_FORMAT builds the month label to group on.
SELECT DATE_FORMAT(created_at, '%Y-%m') AS month,
COUNT(*) AS orders,
SUM(total) AS revenue
FROM orders
Bash
October 17, 2026
Linux find and kill a process by port or name
Finds what is listening on a port and stops it. Try a normal kill first and only use kill -9 if the process won’t stop.
ss -tulpn | grep :8000 # who is using port 8000
lsof -i :8000 # same, with lsof
kill <PID> # graceful stop
kill -9 <PID> # force stop