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 Access
πŸ€– New β€” AI Training

Learn 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
ai-pair-session.md

# 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

KenyaVerified Gateway: National ID & Business Registry Verification API (Premium)

PHP php

Unified identity verification & anti-fraud gateway for verifying Kenya National ID numbers, business registration status, and tax compliance via secure REST webhooks.

// KenyaVerified National Registry Verification API
namespace App\Services;

use Illuminate\Support\Facades\Http;

class KenyaVerifiedService {
    public static function verifyNationalId(string $idNumber, string $dob): array {
        $response = Http::withHeaders([
            'X-API-KEY' => confi...

Polling the Meta Graph API with Auto-Pagination in Python

Python python

The Meta Graph API returns results one page at a time. Every response that has more data includes a paging.next cursor URL. The pattern below wraps that into a single...

import requests
import time
from collections import Counter

BASE = "https://graph.facebook.com/v20.0"


# ── helpers ──────────────────────────────────────────────────────────────
def g(url: str, token: str, params: dict = None) -> dict:
    """GET a Graph API endpoint, automatically injecting the...

Generating Styled Excel & PowerPoint Reports Automatically with Python

Python python

After collecting data from APIs or scraping, the next step is usually turning it into a document a non-technical stakeholder can open and read. openpyxl writes styled Excel workbooks; python-pptx...

# pip install openpyxl python-pptx

import openpyxl
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
from openpyxl.utils import get_column_letter

from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor


# ── shared theme ────────────...

Automating FTP Deployments in Python with Smart Change Detection & Retry

Python python

Manually uploading files over FTP after every code change is error-prone and slow. A Python script using the built-in ftplib module can automate this completely β€” uploading only changed files,...

"""
ftp_deploy.py β€” upload only changed files, retry on drop, clear caches.

Usage:
    python ftp_deploy.py
"""
import ftplib
import io
import os
import socket
import time
import urllib.request
import urllib.error

# ── config ────────────────────────────────────────────────────────────────
FTP_HOS...

Offloading Slow Work with Laravel Queues: High-Throughput Job Architecture

Eliminating Request Timeouts with Asynchronous Job Queues Modern web users expect sub-200ms page responses. When HTTP requests synchronously perform heavy I/O operationsβ€”such as sending SMTP emails, querying external APIs, watermarking...

<?php

declare(strict_types=1);

namespace App\Jobs;

use App\Models\Invoice;
use App\Mail\InvoiceGeneratedMail;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQue...

Validating Input Cleanly with Form Requests: Security & Business Rules

Separating Validation Logic from Controllers in Laravel Writing validation logic inside controller actions violates the Single Responsibility Principle. Laravel Form Request classes offer a clean, reusable architecture to handle authorization,...

<?php

declare(strict_types=1);

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreHospitalQuoteRequest extends FormRequest
{
    public function authorize(): bool {
        return $this->user()?->can('create-quotes') ?? false;...

Shaping JSON Responses with Eloquent API Resources: Versioning & Security

Protecting Internal Schemas and Formatting Production JSON APIs Returning raw Eloquent models directly from controller endpoints is a security vulnerability. It exposes internal column names, timestamps, and sensitive fields. Eloquent...

<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class CourseDetailResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,...

Reusable Query Logic with Eloquent Scopes: Clean Query Architecture

DRY Database Querying with Local and Dynamic Scopes When multiple endpoints filter active subscriptions, hospital quotes, or pending payments, copying raw where() clauses causes bugs. Eloquent Scopes centralize complex filtering...

<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Subscription extends Model
{
    public function scopeActive(Builder $query): Builder {
        return $query->where('status', 'active')...

Thinner Views with Django Class-Based Views (Premium)

Django python

Most list and detail pages follow the same pattern: fetch a queryset, paginate, render a template. Django's generic class-based views hand you that for free, so a full listing page...

from django.views.generic import ListView, DetailView
from .models import Article

class ArticleList(ListView):
    model = Article
    paginate_by = 10
    context_object_name = "articles"

    def get_queryset(self):
        qs = super().get_queryset().filter(is_published=True)
        if q := sel...