Cheat sheets

One-page references to keep beside you while you build. Print them, pin them up in a classroom, or copy one into your notes.

Prompting checklist

Role
Who should the AI be? 'Act as a patient tutor' or 'a skeptical customer'.
Goal
What you want, and why.
Context
Who it's for, what already exists; paste the text it needs.
Constraints
Length, tone, what not to change, what to avoid.
Format
Table, bullets, steps, a short email, JSON.
Examples
One or two samples of what good looks like.
Check
Ask it to list assumptions and what you should verify.
Iterate
Change one thing at a time; keep what works.

Learn it: Prompting that works

Terminal commands

pwd
Show the folder you're in
ls (dir on Windows Command Prompt)
List files and folders
cd my-app
Go into a folder
cd ..
Go up one folder
mkdir notes
Make a folder
npm install
Download the project's packages
npm run dev
Start the app on localhost
Ctrl+C
Stop the running program
Up arrow
Repeat a previous command

Learn it: Terminal basics: the command line without fear

Forms

<label for="email">Email</label>
Names the field; clicking it focuses the input
type="email" / "tel" / "number"
The right phone keyboard, plus basic checks
name="email"
The key the value is sent under
required, minlength, maxlength
Quick checks before sending (check on the server too)
autocomplete="email"
Lets browsers and password managers fill it in
autocomplete="new-password"
Sign-up: offer a strong new password
aria-describedby="email-error"
Links the hint or error text to the field
aria-invalid="true"
Tells screen readers the value needs fixing
event.preventDefault()
Stop the page reloading when JavaScript sends it
button.disabled = true
No double submits while it's sending

Learn it: Forms that work: labels, checks and safe sending

CSS layout

display: flex
Children side by side in a row
flex-direction: column
Stack them instead
justify-content: center
Centre along the line (space-between spreads them out)
align-items: center
Centre across the line
gap: 16px
Space between items (flex and grid)
flex-wrap: wrap
Let items move onto a new line
flex: 1
Take up the space that's left
display: grid
Rows and columns
grid-template-columns: repeat(3, 1fr)
Three equal columns
repeat(auto-fit, minmax(200px, 1fr))
As many columns as fit, each at least 200px
@media (min-width: 768px) { ... }
Styles for screens 768px and wider
max-width: 100%
Never wider than its container (images too)
min-height: 100dvh
Full height of what's visible, phones included

Learn it: CSS layout: flexbox, grid and fitting every screen

npm commands

npm install
Install everything in package.json (after a clone or pull)
npm install zod
Add a package to dependencies
npm install -D vitest
Add a devDependency (build and test tools)
npm uninstall zod
Remove a package
npm run
List the project's scripts
npm run dev
Run the dev script (start on localhost)
npm ci
Clean install, exactly as the lockfile says (CI and hosts)
npm outdated
Show packages with newer versions
npm audit
Check installed packages for known security problems
npx create-next-app@latest
Run a package's command without adding it
^4.2.1 / ~4.2.1 / 4.2.1
Any 4.x from 4.2.1 / only 4.2.x / exactly 4.2.1

Learn it: npm and packages: what npm install really does

Async JavaScript

const data = await getData()
Wait for a promise and get its value
async function load() { ... }
A function that can await; it always returns a promise
try { await save() } catch (error) { ... }
Catch a promise that fails
finally { hideSpinner() }
Runs whether it worked or failed
if (!response.ok) { ... }
fetch doesn't throw on 404 or 500: check ok
await Promise.all([a(), b()])
Side by side; fails as soon as one fails
await Promise.allSettled([a(), b()])
Wait for all, then see which worked
for (const id of ids) await save(id)
One at a time, in order
ids.forEach(async (id) => ...)
Doesn't wait! Use for...of or Promise.all
setTimeout(fn, 1000)
Run fn once, about a second later

Learn it: Async JavaScript: promises, async and await

Git and GitHub

git status
What changed since the last commit
git diff
The exact lines that changed
git add .
Stage all changes for the next commit
git commit -m "Add sign-up form"
Save a snapshot with a message
git push
Send your commits to GitHub
git pull
Get the latest commits from GitHub
git switch -c new-feature
Create a branch and move to it
git log --oneline
Short history of commits

Learn it: Git and GitHub: save points for your code

HTML and CSS

<h1> … <h6>, <p>
Headings and paragraphs
<a href="/menu">Menu</a>
A link
<img src="a.jpg" alt="What it shows">
An image with alt text
<label for="email">Email</label> <input id="email">
A labelled form field
<button>Book now</button>
A button
color: navy; background: white;
Text and background colour
padding: 16px; margin: 8px;
Space inside and outside the box
display: flex; gap: 12px;
Lay items out in a row with gaps
@media (max-width: 600px) { … }
Styles for small screens

Learn it: HTML and CSS basics: how a web page is built

Python

print("Hello")
Show text
name = "Sam"
Store a value in a variable
if score >= 80:
Run the indented lines below when it's true
elif score >= 50: else:
Other cases, checked in order
for score in scores:
Repeat the indented lines for each item
for i in range(5):
Count 0 to 4
def total(numbers):
Start a function; indent its body
return sum(numbers)
Send a value back
f"Hi {name}"
Put values into text
# a comment
A note Python ignores
python3 hello.py
Run a script from the terminal

Learn it: Python basics: your first scripts

React

function Greeting({ name }) { return <h1>Hi {name}</h1> }
A component that takes a prop
<Greeting name="Sam" />
Use a component and pass a prop
const [count, setCount] = useState(0)
State: a value and its setter
setItems([...items, newItem])
Update an array with a new copy
{items.map((item) => <li key={item.id}>{item.name}</li>)}
A list with stable keys
onClick={() => setOpen(true)}
Pass a function, don't call it
{isLoading ? <Spinner /> : <List />}
Show one thing or another
{error && <p>{error}</p>}
Show something only if it exists
useEffect(() => { … }, [userId])
Run code after render when userId changes

Learn it: React basics: components, props and state

TypeScript

let name: string; let age: number; let done: boolean
Basic types
string[]
A list of text
type User = { name: string; age?: number }
An object shape; ? means optional
type Status = "draft" | "sent" | "paid"
Only these values are allowed
function total(prices: number[]): number
What goes in and what comes out
user?.name
Read safely if user might be missing
user?.name ?? 'Guest'
Fall back when it's missing
Number(form.price)
Turn form text into a number
npx tsc --noEmit
Run the type check without building

Learn it: TypeScript basics: types and reading the errors

Browser DevTools

F12, or Ctrl+Shift+I (Cmd+Option+I on a Mac)
Open DevTools
Elements
See the HTML and CSS; try changes (gone on reload)
Console
Errors in red, plus your console.log output
Network, then reload
Every request with its status, size and time
Network, click a request
Headers, the payload sent and the response
Network, Fetch/XHR filter
Just your app's API calls
Network, throttling
Try a slow phone connection
Application, Local storage
What the site saved on this device
Lighthouse
Speed and accessibility audit with fixes

Learn it: Browser DevTools: see what your app is really doing

SQL

SELECT name, email FROM signups
Read columns from a table
WHERE interest = 'coding'
Only matching rows
ORDER BY created_at DESC LIMIT 10
Newest first, ten at most
SELECT interest, COUNT(*) FROM signups GROUP BY interest
Count per group
JOIN customers ON customers.id = orders.customer_id
Combine related tables
INSERT INTO signups (name) VALUES ('Sam')
Add a row
UPDATE users SET plan = 'pro' WHERE id = 42
Change rows (always use WHERE)
DELETE FROM signups WHERE id = 7
Remove rows (always use WHERE)

Learn it: SQL basics: ask your database questions

Table design

id bigint generated always as identity primary key
A unique id the database makes for each row
id uuid primary key default gen_random_uuid()
A random id that's hard to guess
workshop_id bigint not null references workshops (id)
A foreign key: it must match a real workshop
member_id uuid references auth.users (id) on delete cascade
The row's owner; their rows go when they do
created_at timestamptz not null default now()
When the row was made, filled in for you
price_cents integer not null check (price_cents >= 0)
Money in whole cents, never negative
unique (workshop_id, member_id)
No duplicate pairs, so no double booking
create index on signups (workshop_id)
Faster lookups by a foreign key
alter table signups enable row level security
Turn RLS on before anyone can reach it

Learn it: Design your database: tables, keys and relationships

Debugging checklist

Reproduce
Find the exact steps that make it happen every time.
Find the error
Browser Console, terminal output or your host's logs. Copy all of it.
What changed?
The last thing you or the AI changed is the usual suspect.
Brief the AI
What you did, what you expected, what happened, the error, what changed.
One fix at a time
Small changes, then test again.
Keep an exit
Commit when it works; revert if things get worse.

Learn it: Debugging with AI: when it breaks

Review checklist for AI-written code

Read the diff
Every file and line that changed.
Only what you asked
Unexpected files or features? Ask why or ask for a smaller change.
Explain it
Ask the AI to explain each change; if you can't, don't ship it yet.
Secrets
No keys in code; environment variables only.
Permissions
Sign-in and access checks run on the server; RLS still on.
Data
Migrations, deletes and bulk updates get a second look and a backup.
Test
Run the tests and click through it on a preview link.
Ship small
Small merges with clear messages; revert first if something breaks.

Learn it: Review AI-written code before you ship

Build safely checklist

Secrets
Keys in environment variables, never in code, chats or screenshots.
Data rules
Row level security on; people only see their own data.
Least access
Give tools, teammates and automations only what they need.
Accounts
Multifactor sign-in on email, GitHub, hosting and database.
Check AI's work
Read what it changed, test it, and question confident claims.
Personal data
Collect less; use fake data when testing or asking AI.
Backups
Know how to restore, and roll back a bad release.
Commands
Read every command before you run or approve it.

Learn it: Build safely: secrets, data and honest AI use

Regular expressions

/cat/i
'cat' in any case
\d \w \s
A digit · a letter, digit or _ · a space
. \.
Any one character · a real full stop
[aeiou] [^0-9] [a-z]
One of these · anything but · a range
? * +
Zero or one · zero or more · one or more
{3} {2,4}
Exactly three · two to four
^ ... $
The whole text must match, start to end
(cat|dog)
A group, and either-or
/-/g
Every match, not just the first
re.test(text)
true or false
text.match(/\d+/g)
Every match, as an array
text.replace(/\s+/g, " ")
Squash runs of spaces into one

Learn it: Regular expressions without fear: read, test and trust them

Web security checklist

Every request
On the server: who is this, and may they do this to this row?
Showing text
{text} in React, or textContent. Avoid innerHTML with anything people typed.
Showing HTML people wrote
Clean it with a sanitiser such as DOMPurify first.
Links people paste
Allow http: and https: only, never javascript:.
Database queries
Parameters or supabase-js, never strings glued to user input.
Another site's API
Call it from your server route, with the key on the server.
CORS error
The browser wouldn't share the answer. It isn't a lock on your API.
Sign-in cookies
HttpOnly, Secure, SameSite=Lax.
Changing data
POST, PUT, PATCH or DELETE, never GET.
Errors for visitors
A friendly message; the details go to your logs.

Learn it: Web security basics: access checks, XSS, CORS and cookies