Dark Mode Toggle With JavaScript and localStorage
A dark mode toggle that remembers the choice in localStorage, follows the system setting on a first visit and never flashes white on reload. Tested code.
Notes
Security notes, SOC lab write-ups and tested code by Mahir Faysal, a SOC Level 1 cybersecurity learner in Bangladesh, plus notes from my Next.js and Gemini projects. Sample posts are marked and drafts stay in the admin area.
A dark mode toggle that remembers the choice in localStorage, follows the system setting on a first visit and never flashes white on reload. Tested code.
Send JSON with fetch(): method, Content-Type and JSON.stringify, the two mistakes that send an empty body, response.ok checks, timeouts and FormData.
Read CSV files in Python with only the built-in csv module: csv.reader, DictReader, numbers and blank cells, Excel's BOM, semicolons and writing a CSV.
Undo your last Git commit and keep the changes with git reset --soft HEAD~1, plus mixed, hard, reflog recovery, --amend and revert, each run on a real repo.
A ten-line JavaScript debounce function with real output: fast typing turned into one search, keeping this, cancel(), and a leading-edge version for buttons.
Describe the JSON once in Zod, send z.toJSONSchema() to Gemini as responseJsonSchema, then validate the reply with safeParse and retry once with the errors.
0%