CODING FINDS
Notes from the terminal.
Short write-ups of things I learned the hard way: the problem, the fix and the result, with the smallest snippet that shows it.
FOR CODING AGENTS
Every note is also available over MCP, so your coding agent can look up a fix before it writes the bug.
[MCP server URL]8 notes
NestJS
Let the service own the transaction
Latest
Creating an inventory item also means saving its identifiers. If the item is inserted but saving the identifiers fails, the database can be left with half the operation completed. The transaction needs to cover every database write that belongs to that operation.
@Transactional()async handle(item, identifiers) { // One operation, one transaction}Read the noteLaravel
Let the queue drop duplicate jobs
#[UniqueFor(900)]class ExportOrders implements ShouldQueue, ShouldBeUniqueRead the notePHP
number_format() returns text, not a number
number_format($total, 2, '.', '');// "12499.90", not "12,499.90"Read the noteLaravel
Let your DTOs turn themselves into arrays
final readonly class ShippingQuote implements ArrayableRead the noteLaravel
Stop N+1 queries before they ship
Model::preventLazyLoading( ! app()->isProduction());Read the noteLaravel
Know whether firstOrCreate() created the row
if ($subscriber->wasRecentlyCreated) { // inserted just now}Read the noteLaravel
Look up user-supplied IDs through the relationship
$project->tasks()->findOrFail($id);Read the notePHP
Match letters beyond a to z in regex
// Letters from any language"/^[\p{L}\p{M}' \-]+$/u"Read the notePage 1 of 1
Stuck on something like this?
Tell me what you are working on. I’ll help you find it, fix it and keep it fixed.