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
41 nuggets found
Streaming Large Files with Python Generators (Premium)
Loading a multi-gigabyte file into memory will crash your process. A generator yields one chunk (or line) at a time, so memory stays flat no matter how big the file...
def read_in_chunks(path, size=1024 * 1024):
"""Yield a file one megabyte at a time."""
with open(path, "rb") as f:
while chunk := f.read(size):
yield chunk
def count_lines(path):
total = 0
for chunk in read_in_chunks(path):
total += chunk.count(b"\n")...
A Minimal Image Classifier with Keras (Premium)
You do not need a research lab to train a working classifier. This compact Keras model learns to tell classes apart from a folder of labelled images and reports its...
import tensorflow as tf
from tensorflow.keras import layers, models
model = models.Sequential([
layers.Rescaling(1./255, input_shape=(128, 128, 3)),
layers.Conv2D(32, 3, activation="relu"),
layers.MaxPooling2D(),
layers.Conv2D(64, 3, activation="relu"),
layers.MaxPooling2D(),...
Building an Image Preprocessing Pipeline with tf.data (Premium)
Clean, well-batched input is half the battle in machine learning. tf.data loads images from disk, resizes and augments them, then prefetches batches so your GPU never sits idle.
import tensorflow as tf
AUTOTUNE = tf.data.AUTOTUNE
train_ds = tf.keras.utils.image_dataset_from_directory(
"data/train", image_size=(128, 128), batch_size=32, label_mode="int")
augment = tf.keras.Sequential([
tf.keras.layers.RandomFlip("horizontal"),
tf.keras.layers.RandomRotation(0....
Serving a Trained Model Behind a REST Endpoint (Premium)
A model is only useful once other apps can call it. FastAPI wraps your saved model in a tiny JSON API: load once at startup, then return predictions on every...
from fastapi import FastAPI, UploadFile
import tensorflow as tf
import numpy as np
from PIL import Image
import io
app = FastAPI()
model = tf.keras.models.load_model("model.keras") # loaded once
CLASSES = ["normal", "review", "urgent"]
@app.post("/predict")
async def predict(file: UploadFile):...
Fetching Server Data with TanStack Query (Premium)
Manual loading flags, caching and refetching are a lot of boilerplate. TanStack Query handles all of it: you describe how to fetch, and it gives you cached data plus loading...
import { useQuery } from "@tanstack/react-query";
function fetchPatients() {
return fetch("/api/patients").then((r) => {
if (!r.ok) throw new Error("Request failed");
return r.json();
});
}
export function PatientList() {
const { data, isLoading, isError, error } = useQuery({
que...
Powerful, Headless Data Grids with TanStack Table (Premium)
TanStack Table is headless — it gives you sorting, filtering and pagination logic while you keep full control of the markup and styling. Define columns, hand it rows, and render.
import {
useReactTable, getCoreRowModel, getSortedRowModel, flexRender,
} from "@tanstack/react-table";
import { useState } from "react";
const columns = [
{ accessorKey: "name", header: "Name" },
{ accessorKey: "role", header: "Role" },
{ accessorKey: "createdAt", header: "Joined" },
];
e...
Type-safe Routes and Loaders with TanStack Router (Premium)
TanStack Router gives you fully typed routes and data loaders that run before a component renders, so your screen already has its data on first paint — no flash of...
import { createRootRoute, createRoute, Outlet } from "@tanstack/react-router";
const rootRoute = createRootRoute({ component: () => <Outlet /> });
const patientRoute = createRoute({
getParentRoute: () => rootRoute,
path: "/patients/$patientId",
// loader runs before the component mounts
lo...
Extending a Standard Table with a Table Extension (Premium)
In Business Central you never modify base tables — you extend them. A tableextension adds your own fields to a standard table so upgrades stay clean and your data lives...
tableextension 50100 "Customer Ext" extends Customer
{
fields
{
field(50100; "Loyalty Points"; Integer)
{
Caption = 'Loyalty Points';
MinValue = 0;
DataClassification = CustomerContent;
}
field(50101; "Preferred Channel"; Op...
Surfacing New Fields with a Page Extension (Premium)
Adding a field to a table does not show it to users. A pageextension places your new fields onto the standard card or list page, anchored next to existing controls.
pageextension 50100 "Customer Card Ext" extends "Customer Card"
{
layout
{
addlast(General)
{
field("Loyalty Points"; Rec."Loyalty Points")
{
ApplicationArea = All;
ToolTip = 'Points earned by this customer.';...