Enjoy these free Code Nuggets?
Your support helps us create more high-quality content and unlocks exclusive premium nuggets via a personal activation link.
Support Our Work & Get Exclusive AccessLearn to code with AI, not just about it.
Beyond free snippets, we run hands-on training in AI-assisted coding — teaching developers, teams and beginners how to build real software faster using modern AI tools. You bring the ideas; we show you how to ship them with an AI pair-programmer at your side.
- ✔ Prompting & pairing with AI coding assistants to write, debug and refactor real code
- ✔ Turning plain-English ideas into working apps, scripts and automations
- ✔ Reviewing AI output safely — spotting bugs, security gaps and hallucinations
- ✔ Live cohorts, team workshops and 1-on-1 mentoring — remote or on-site in Kenya
# You describe it…
"Build me a booking form that emails the client."
# …the AI drafts it…
▸ generating form + mailer…
â–¸ 24 lines written, 0 errors
# …and we teach you to lead it.
✱ You stay the engineer. AI is the tool.
All Code Nuggets
45 nuggets found
Composable Request Handling with Express Middleware (Premium)
Express middleware are just functions that run in order on every request. Chain them to add logging, authentication and error handling without repeating yourself in each route.
const express = require("express");
const app = express();
// Simple request logger
app.use((req, res, next) => {
console.log(`${req.method} ${req.url}`);
next();
});
// Reusable auth guard
function requireAuth(req, res, next) {
if (!req.headers.authorization) return res.status(401).json({ e...
Processing Large Files with Node.js Streams (Premium)
Reading a whole file into a Buffer does not scale. Streams process data piece by piece and can be piped together, so you can transform gigabytes with a tiny, constant...
const fs = require("fs");
const zlib = require("zlib");
const { pipeline } = require("stream/promises");
const { Transform } = require("stream");
// Uppercase each chunk as it flows through
const upper = new Transform({
transform(chunk, _enc, cb) {
cb(null, chunk.toString().toUpperCase());...
Keeping Controllers Skinny with Service Objects (Premium)
When a controller action does five things, it becomes hard to test and reuse. A service object captures one business operation in a single, callable class you can test in...
# app/services/register_patient.rb
class RegisterPatient
def self.call(**args) = new(**args).call
def initialize(name:, email:)
@name = name
@email = email
end
def call
patient = Patient.create!(name: @name, email: @email)
WelcomeMailer.with(patient: patient).greeting.deliv...
Readable Queries with ActiveRecord Scopes (Premium)
ActiveRecord scopes name your common queries so they read like intent, not SQL. They are chainable, composable, and keep filtering logic on the model where it belongs.
class Appointment < ApplicationRecord
scope :upcoming, -> { where("starts_at > ?", Time.current) }
scope :for_doctor, ->(doctor) { where(doctor: doctor) }
scope :confirmed, -> { where(status: :confirmed) }
# Combine scopes into a higher-level one
scope :doctor_agenda, ->(doctor) { upcomi...
Mastering Controllers in Laravel: A Deeper Dive (Premium)
Laravel controllers drive traffic in your application - they receive requests, orchestrate your core logic, and provide return responses. While you will get a lot of examples and explanations on...
public function saveBulkDraft(Request $request)
{
try {
// Relaxed validation to handle string JSON and boolean strings from frontend
$request->validate([
'draft_id' => 'nullable|integer|exists:rfqs,id',
'category_id' => 'requ...
Laravel Startup Kit (Comprehensive & Progressive) (Premium)
IntroductionLaravel is a framework for web artisans. It has been termed a progressive framework because it caters to both burgeoning programmers (including kid programmers) and senior developers, giving the latter...
Laravel in 2026: Modern Patterns, Lessons & Architectural Evolution
Enterprise Lessons Learnt Building Production Systems with Laravel Modern Laravel has matured into a powerhouse for enterprise banking, hospital management systems (HMIS), and mission-critical multi-tenant SaaS. Scaling Laravel requires moving...
<?php
declare(strict_types=1);
namespace App\Services\Wallet;
use App\Models\Wallet;
use App\Models\Transaction;
use Illuminate\Support\Facades\DB;
final class AtomicWalletCreditService
{
public function credit(int $userId, float $amount, string $reference): Transaction
{
return...
The 100 Lines Challenge: High-Performance Data Ingestion Pipeline in PHP
Architecting Zero-Memory Streaming for Millions of Records A classic rite of passage for enterprise backend engineers is the 100 Lines Challenge: writing a concise, single-purpose file that solves a complex...
<?php
declare(strict_types=1);
namespace App\Services\Ingestion;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Facades\DB;
use Generator;
use RuntimeException;
final class StreamCsvIngestionService
{
public function import(string $filePath, int $chunkSize = 1000): int
{...
Do the Hard Things First: Refactoring Legacy Monoliths for Scale
Why Tackling Technical Debt Early Determines System Longevity In high-velocity engineering teams, the easiest path is often adding another if-else block to an already bloated 2,000-line controller or running raw...
<?php
declare(strict_types=1);
namespace App\Actions\Checkout;
use App\Models\Order;
use App\Models\User;
use App\DTOs\CheckoutData;
use App\Events\OrderPlacedEvent;
use App\Services\Payment\MpesaPaymentGateway;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Throwable;...