{"schemaVersion":1,"contentVersion":"3.4.0","id":"foundation.10","languages":{"javascript":{"id":"foundation.10","title":"Search for a destination","moduleName":"Search and apply","tips":"","concept":"<p class=\"lead\">Search forward or backward, and see what happens when a search reaches the end of the file.</p><p><strong>Before this lesson:</strong> Reach a line or buffer boundary.</p><p>/ searches forward and ? searches backward. Type some text and press Enter. Esc cancels the search. A search looks past the current line, and when it reaches the end of the file it carries on from the other end. You don't have to type the whole word: a few letters are enough when they only match where you want to go. A search can also match text inside a longer word, so check where you land.</p><div class=\"pkeys\"><kbd>/</kbd> <kbd>?</kbd> <kbd>Enter</kbd> <kbd>Esc</kbd></div><h3>Example</h3><p>From the top of a note, /agenda then Enter reaches the next agenda. From below it, ?agenda then Enter searches backward. What you type after / goes into the search, not the file, and Enter jumps to the match.</p><h4>Worked text</h4><pre class=\"lesson-example\">// Read next\nconst message = \"agenda\";</pre><p>Use Start over to try again.</p>","teaches":["search:/","search"],"introduces":["search"],"constraints":[],"drills":[{"task":"Put the cursor on the <code>throw</code> that turns a failed response into an error.","hint":"Search for the start of the word. A few letters are enough when they only match there.","mode":"jsx","start":"// The HTTP client every page uses. Requests time out after 4000 ms.\nimport { getToken } from \"./auth.js\";\n\nconst BASE_URL = \"https://api.northwind.shop/v2\";\nconst TIMEOUT_MS = 4000;\n\nexport async function request(path, options = {}) {\n  const controller = new AbortController();\n  const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);\n  const headers = { Authorization: `Bearer ${getToken()}`, ...options.headers };\n  try {\n    const response = await fetch(BASE_URL + path, { ...options, headers, signal: controller.signal });\n    if (response.status >= 400) throw new Error(`Request failed: ${response.status}`);\n    return response.status === 204 ? null : await response.json();\n  } finally {\n    clearTimeout(timer);\n  }\n}","startCursor":{"line":1,"ch":0},"paths":[{"keys":["/","thr","<CR>"],"tier":"idiomatic","technique":"search:/","core":["search:/"],"note":"A search jumps straight there. Three letters are enough when they only match there."}],"kind":"navigate","land":{"line":12,"ch":32},"language":"javascript","evidence":"guided","canonicalKey":"foundation.10#0","canonicalFingerprint":"1i894rg"},{"task":"Put the cursor on <code>min</code>, where <code>addItem</code> caps the quantity.","hint":"The word is above you, so search backward with ?.","mode":"jsx","start":"// The cart lives in localStorage, so it survives a reload. Lines are limited to 10.\nconst STORAGE_KEY = \"northwind.cart.v2\";\nconst MAX_PER_LINE = 10;\nconst load = () => JSON.parse(localStorage.getItem(STORAGE_KEY) ?? \"[]\");\nconst save = (lines) => localStorage.setItem(STORAGE_KEY, JSON.stringify(lines));\n\nexport function addItem(sku, quantity = 1) {\n  const lines = load();\n  const line = lines.find((item) => item.sku === sku);\n  if (line) line.quantity = Math.min(line.quantity + quantity, MAX_PER_LINE);\n  else lines.push({ sku, quantity, addedAt: new Date().toISOString(), source: \"web\" });\n  save(lines);\n}\n\nexport function removeItem(sku) {\n  save(load().filter((item) => item.sku !== sku));\n}\n// Checkout calls this once the order is submitted.\nexport const clearCart = () => localStorage.removeItem(STORAGE_KEY);\nexport const itemCount = () => load().reduce((count, item) => count + item.quantity, 0);","startCursor":{"line":19,"ch":87},"paths":[{"keys":["?","min","<CR>"],"tier":"idiomatic","technique":"search","core":["search"],"note":"? searches up from the cursor."}],"kind":"navigate","land":{"line":9,"ch":33},"language":"javascript","evidence":"guided","canonicalKey":"foundation.10#1","canonicalFingerprint":"137xxh0"},{"task":"Point the proxy at the dev API, <code>api.dev.northwind.shop</code>, instead of staging.","hint":"You're at the end of the file. / carries on from the top, and cw changes the word you land on.","mode":"jsx","start":"// Builds the storefront. In development, API calls go through the proxy.\nimport { defineConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\n\nexport default defineConfig({\n  plugins: [react()],\n  server: {\n    port: 5173,\n    strictPort: true,\n    proxy: { \"/api\": { target: \"https://api.staging.northwind.shop\", changeOrigin: true, secure: true } },\n  },\n  preview: { port: 4173, strictPort: true },\n  build: {\n    outDir: \"dist\",\n    sourcemap: true,\n    target: \"es2020\",\n    assetsDir: \"static\",\n  },\n  envPrefix: [\"VITE_\", \"NORTHWIND_\"],\n});","startCursor":{"line":19,"ch":2},"paths":[{"keys":["/","sta","<CR>","c","w","dev","<Esc>"],"tier":"idiomatic","technique":"search","core":["search"],"note":"At the end of the file, / carries on from the top. cw changes the word from its start."}],"target":"// Builds the storefront. In development, API calls go through the proxy.\nimport { defineConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\n\nexport default defineConfig({\n  plugins: [react()],\n  server: {\n    port: 5173,\n    strictPort: true,\n    proxy: { \"/api\": { target: \"https://api.dev.northwind.shop\", changeOrigin: true, secure: true } },\n  },\n  preview: { port: 4173, strictPort: true },\n  build: {\n    outDir: \"dist\",\n    sourcemap: true,\n    target: \"es2020\",\n    assetsDir: \"static\",\n  },\n  envPrefix: [\"VITE_\", \"NORTHWIND_\"],\n});","language":"javascript","evidence":"guided","canonicalKey":"foundation.10#2","canonicalFingerprint":"ra7i5v"}]},"python":{"id":"foundation.10","title":"Search for a destination","moduleName":"Search and apply","tips":"","concept":"<p class=\"lead\">Search forward or backward, and see what happens when a search reaches the end of the file.</p><p><strong>Before this lesson:</strong> Reach a line or buffer boundary.</p><p>/ searches forward and ? searches backward. Type some text and press Enter. Esc cancels the search. A search looks past the current line, and when it reaches the end of the file it carries on from the other end. You don't have to type the whole word: a few letters are enough when they only match where you want to go. A search can also match text inside a longer word, so check where you land.</p><div class=\"pkeys\"><kbd>/</kbd> <kbd>?</kbd> <kbd>Enter</kbd> <kbd>Esc</kbd></div><h3>Example</h3><p>From the top of a note, /agenda then Enter reaches the next agenda. From below it, ?agenda then Enter searches backward. What you type after / goes into the search, not the file, and Enter jumps to the match.</p><h4>Worked text</h4><pre class=\"lesson-example\"># Read next\nmessage = \"agenda\"</pre><p>Use Start over to try again.</p>","teaches":["search:/","search"],"introduces":["search"],"constraints":[],"drills":[{"task":"Put the cursor on <code>status_code</code> in the check for failed requests.","hint":"Search for the start of the word. A few letters are enough when they only match there.","mode":"python","start":"\"\"\"The HTTP client every view uses. Requests time out after 4 seconds.\"\"\"\nfrom httpx import Client\n\nfrom shop.auth import get_token\n\nBASE_URL = \"https://api.northwind.shop/v2\"\n\n\ndef request(method: str, path: str, **kwargs) -> dict | None:\n    headers = {\"Authorization\": f\"Bearer {get_token()}\", **kwargs.pop(\"headers\", {})}\n    with Client(base_url=BASE_URL, timeout=4.0) as client:\n        response = client.request(method, path, headers=headers, **kwargs)\n    if response.status_code >= 400:\n        raise RuntimeError(f\"Request failed: {response.status_code} {response.text}\")\n    return None if response.status_code == 204 else response.json()\n\n\ndef get(path: str, **kwargs) -> dict | None:\n    return request(\"GET\", path, **kwargs)","startCursor":{"line":1,"ch":0},"paths":[{"keys":["/","sta","<CR>"],"tier":"idiomatic","technique":"search:/","core":["search:/"],"note":"A search jumps straight there. Three letters are enough when they only match there."}],"kind":"navigate","land":{"line":12,"ch":16},"language":"python","evidence":"guided","canonicalKey":"foundation.10#0","canonicalFingerprint":"1i894rg"},{"task":"Put the cursor on <code>get</code>, where <code>add_item</code> reads the quantity already in the cart.","hint":"The word is above you, so search backward with ?.","mode":"python","start":"\"\"\"The session cart behind the cart page. Each line is a SKU and a quantity.\"\"\"\nfrom shop.flags import cart_badge_shown\n\nCART_KEY = \"northwind.cart.v2\"\nMAX_PER_LINE = 10\n\n\ndef add_item(session, sku, quantity=1):\n    lines = session.setdefault(CART_KEY, {})\n    lines[sku] = min(lines.get(sku, 0) + quantity, MAX_PER_LINE)\n    session.modified = True\n\n\ndef remove_item(session, sku):\n    session.setdefault(CART_KEY, {}).pop(sku, None)\n    session.modified = True\n\n\ndef item_count(session):\n    return sum(session.setdefault(CART_KEY, {}).values()) if cart_badge_shown() else 0","startCursor":{"line":19,"ch":85},"paths":[{"keys":["?","get","<CR>"],"tier":"idiomatic","technique":"search","core":["search"],"note":"? searches up from the cursor."}],"kind":"navigate","land":{"line":9,"ch":27},"language":"python","evidence":"guided","canonicalKey":"foundation.10#1","canonicalFingerprint":"137xxh0"},{"task":"Point the shop at the dev API, <code>api.dev.northwind.shop</code>, instead of staging.","hint":"You're at the end of the file. / carries on from the top, and cw changes the word you land on.","mode":"python","start":"\"\"\"Settings for working on the shop on your own machine.\"\"\"\nfrom .base import *  # noqa: F401,F403\n\nDEBUG = True  # never on the live site\nALLOWED_HOSTS = [\"localhost\", \"127.0.0.1\", \".ngrok.app\"]\nINTERNAL_IPS = [\"127.0.0.1\"]\n\nCACHES = {\"default\": {\"BACKEND\": \"django.core.cache.backends.locmem.LocMemCache\"}}\nDATABASES[\"default\"][\"NAME\"] = \"northwind_dev\"\nAPI_BASE_URL = \"https://api.staging.northwind.shop/v2\"  # the shared test data lives here\nAPI_TIMEOUT = 10\n\nEMAIL_BACKEND = \"django.core.mail.backends.console.EmailBackend\"\nSTATICFILES_DIRS = [BASE_DIR / \"static\", BASE_DIR / \"frontend\" / \"dist\"]\nLOGGING[\"root\"][\"level\"] = \"DEBUG\"\nSESSION_COOKIE_SECURE = False\nCSRF_COOKIE_SECURE = False\nCSRF_TRUSTED_ORIGINS = [\"http://localhost:8000\", \"https://*.ngrok.app\"]\nSHOW_TOOLBAR = DEBUG and not os.environ.get(\"CI\")\nINSTALLED_APPS += [\"debug_toolbar\"]  # noqa: F405","startCursor":{"line":19,"ch":48},"paths":[{"keys":["/","sta","<CR>","c","w","dev","<Esc>"],"tier":"idiomatic","technique":"search","core":["search"],"note":"At the end of the file, / carries on from the top. cw changes the word from its start."}],"target":"\"\"\"Settings for working on the shop on your own machine.\"\"\"\nfrom .base import *  # noqa: F401,F403\n\nDEBUG = True  # never on the live site\nALLOWED_HOSTS = [\"localhost\", \"127.0.0.1\", \".ngrok.app\"]\nINTERNAL_IPS = [\"127.0.0.1\"]\n\nCACHES = {\"default\": {\"BACKEND\": \"django.core.cache.backends.locmem.LocMemCache\"}}\nDATABASES[\"default\"][\"NAME\"] = \"northwind_dev\"\nAPI_BASE_URL = \"https://api.dev.northwind.shop/v2\"  # the shared test data lives here\nAPI_TIMEOUT = 10\n\nEMAIL_BACKEND = \"django.core.mail.backends.console.EmailBackend\"\nSTATICFILES_DIRS = [BASE_DIR / \"static\", BASE_DIR / \"frontend\" / \"dist\"]\nLOGGING[\"root\"][\"level\"] = \"DEBUG\"\nSESSION_COOKIE_SECURE = False\nCSRF_COOKIE_SECURE = False\nCSRF_TRUSTED_ORIGINS = [\"http://localhost:8000\", \"https://*.ngrok.app\"]\nSHOW_TOOLBAR = DEBUG and not os.environ.get(\"CI\")\nINSTALLED_APPS += [\"debug_toolbar\"]  # noqa: F405","language":"python","evidence":"guided","canonicalKey":"foundation.10#2","canonicalFingerprint":"ra7i5v"}]},"text":{"id":"foundation.10","title":"Search for a destination","moduleName":"Search and apply","tips":"","concept":"<p class=\"lead\">Search forward or backward, and see what happens when a search reaches the end of the file.</p><p><strong>Before this lesson:</strong> Reach a line or buffer boundary.</p><p>/ searches forward and ? searches backward. Type some text and press Enter. Esc cancels the search. A search looks past the current line, and when it reaches the end of the file it carries on from the other end. You don't have to type the whole word: a few letters are enough when they only match where you want to go. A search can also match text inside a longer word, so check where you land.</p><div class=\"pkeys\"><kbd>/</kbd> <kbd>?</kbd> <kbd>Enter</kbd> <kbd>Esc</kbd></div><h3>Example</h3><p>From the top of a note, /agenda then Enter reaches the next agenda. From below it, ?agenda then Enter searches backward. What you type after / goes into the search, not the file, and Enter jumps to the match.</p><h4>Worked text</h4><pre class=\"lesson-example\">Read next\nMessage: agenda</pre><p>Use Start over to try again.</p>","teaches":["search:/","search"],"introduces":["search"],"constraints":[],"drills":[{"task":"Put the cursor on the <code>channel</code> to ask in about timeouts.","hint":"Search for the start of the word. A few letters are enough when they only match there.","mode":"text/plain","start":"# When checkout fails\n\nMost failures come from the payment provider, not from us. Work through these in order.\n\n1. Check the status pages for Stripe and for our own API.\n2. Search the logs for the order number. Every request writes one line.\n3. If the card was declined, there is nothing to fix. Tell the customer.\n4. If the API timed out, retry the order once from the admin.\n5. If it fails again, put the order on hold and page whoever is on call.\n\n## Who to ask\n\nPayments: Dana (Stripe account owner, has the dashboard login)\nAPI and timeouts: Kemal, or the #api channel in working hours\nAnything else: the on-call engineer, listed in the team calendar\n\n## After an incident\n\nWrite a short note in the incident log the same day, even if the fix was quick.\nLink the order numbers, and say what the customer was told.","startCursor":{"line":2,"ch":0},"paths":[{"keys":["/","cha","<CR>"],"tier":"idiomatic","technique":"search:/","core":["search:/"],"note":"A search jumps straight there. Three letters are enough when they only match there."}],"kind":"navigate","land":{"line":13,"ch":37},"language":"text","evidence":"guided","canonicalKey":"foundation.10#0","canonicalFingerprint":"1i894rg"},{"task":"Put the cursor on <code>collects</code>, in the costs for the United Kingdom.","hint":"The word is above you, so search backward with ?.","mode":"text/plain","start":"# Shipping\n\nWe ship from our warehouse in Rotterdam, Monday to Friday.\nOrders placed before 14:00 leave the same day.\n\n## Costs\n\n- Netherlands and Belgium: 4.95, free over 50\n- Rest of the EU: 9.95, free over 120\n- United Kingdom: 14.95, plus any import duty, which the courier collects on delivery\n- Everywhere else: we quote by email before we take payment\n\n## Tracking\n\nYou get a tracking link by email as soon as the parcel leaves us.\n\n## Returns\n\nYou have 30 days to send anything back, unused and in its box.\nPrint the label from your order page, and drop the parcel at any PostNL point near you.","startCursor":{"line":19,"ch":86},"paths":[{"keys":["?","col","<CR>"],"tier":"idiomatic","technique":"search","core":["search"],"note":"? searches up from the cursor."}],"kind":"navigate","land":{"line":9,"ch":65},"language":"text","evidence":"guided","canonicalKey":"foundation.10#1","canonicalFingerprint":"137xxh0"},{"task":"The test server is called <code>preview</code> now. Change <code>staging</code> to <code>preview</code> in step 3.","hint":"You're at the end of the file. / carries on from the top, and cw changes the word you land on.","mode":"text/plain","start":"# Releasing the shop\n\nWe release on Tuesdays and Thursdays, before noon, so there is time to fix things.\nAnyone on the team can release. You need access to GitHub and to the cloud console.\n\n## Steps\n\n1. Pull main and run the full test suite on your machine: npm run test:pr\n2. Bump the version in package.json and write the changelog entry.\n3. Deploy to staging with ./scripts/deploy.sh and click through checkout once.\n4. Tag the release, push the tag, and wait for the production build to go green.\n5. Post the changelog entry in #releases with a link to the tag.\n\n## If something breaks\n\nRoll back first and investigate after. Run ./scripts/rollback.sh with the previous tag.\nThen open an incident in the tracker and say what you saw, even if it was small.\nCustomers come first: if checkout is down, post on the status page within ten minutes.\n\nQuestions about this process go to Ines, who owns the release scripts and the CI setup.","startCursor":{"line":19,"ch":86},"paths":[{"keys":["/","sta","<CR>","c","w","preview","<Esc>"],"tier":"idiomatic","technique":"search","core":["search"],"note":"At the end of the file, / carries on from the top. cw changes the word from its start."}],"target":"# Releasing the shop\n\nWe release on Tuesdays and Thursdays, before noon, so there is time to fix things.\nAnyone on the team can release. You need access to GitHub and to the cloud console.\n\n## Steps\n\n1. Pull main and run the full test suite on your machine: npm run test:pr\n2. Bump the version in package.json and write the changelog entry.\n3. Deploy to preview with ./scripts/deploy.sh and click through checkout once.\n4. Tag the release, push the tag, and wait for the production build to go green.\n5. Post the changelog entry in #releases with a link to the tag.\n\n## If something breaks\n\nRoll back first and investigate after. Run ./scripts/rollback.sh with the previous tag.\nThen open an incident in the tracker and say what you saw, even if it was small.\nCustomers come first: if checkout is down, post on the status page within ten minutes.\n\nQuestions about this process go to Ines, who owns the release scripts and the CI setup.","language":"text","evidence":"guided","canonicalKey":"foundation.10#2","canonicalFingerprint":"ra7i5v"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Reach a line or buffer boundary.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Search forward or backward, and see what happens when a search reaches the end of the file.</p><p>/ searches forward and ? searches backward. Type some text and press Enter. Esc cancels the search. A search looks past the current line, and when it reaches the end of the file it carries on from the other end. You don't have to type the whole word: a few letters are enough when they only match where you want to go. A search can also match text inside a longer word, so check where you land.</p><h2 class=\"prose-subhead\">Example</h2><p>From the top of a note, /agenda then Enter reaches the next agenda. From below it, ?agenda then Enter searches backward. What you type after / goes into the search, not the file, and Enter jumps to the match.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Reach a line or buffer boundary.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Search forward or backward, and see what happens when a search reaches the end of the file.</p><p>/ searches forward and ? searches backward. Type some text and press Enter. Esc cancels the search. A search looks past the current line, and when it reaches the end of the file it carries on from the other end. You don't have to type the whole word: a few letters are enough when they only match where you want to go. A search can also match text inside a longer word, so check where you land.</p><h2 class=\"prose-subhead\">Example</h2><p>From the top of a note, /agenda then Enter reaches the next agenda. From below it, ?agenda then Enter searches backward. What you type after / goes into the search, not the file, and Enter jumps to the match.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Reach a line or buffer boundary.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Search forward or backward, and see what happens when a search reaches the end of the file.</p><p>/ searches forward and ? searches backward. Type some text and press Enter. Esc cancels the search. A search looks past the current line, and when it reaches the end of the file it carries on from the other end. You don't have to type the whole word: a few letters are enough when they only match where you want to go. A search can also match text inside a longer word, so check where you land.</p><h2 class=\"prose-subhead\">Example</h2><p>From the top of a note, /agenda then Enter reaches the next agenda. From below it, ?agenda then Enter searches backward. What you type after / goes into the search, not the file, and Enter jumps to the match.</p><p>Use Start over to try again.</p></div></details>"}}}