{"schemaVersion":1,"contentVersion":"3.4.0","id":"intermediate.15","languages":{"javascript":{"id":"intermediate.15","title":"Make replay robust","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Write a macro that works on lines of different lengths, and replay it only as often as you need.</p><p><strong>Before this lesson:</strong> Record, stop and replay.</p><p>A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.</p><h3>Example</h3><p>If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.</p><p>Use Start over to try again.</p>","teaches":["macro:replay"],"introduces":["q","@","I","A","j","0","count"],"constraints":[],"drills":[{"task":"The server runs as an ES module now. Turn the six <code>require</code> lines into <code>import</code> lines, like <code>import express from \"express\";</code>.","hint":"Record the change on the first line, ending on the next one. A count before @a replays it on the rest.","mode":"jsx","start":"const express = require(\"express\");\nconst helmet = require(\"helmet\");\nconst morgan = require(\"morgan\");\nconst { json } = require(\"body-parser\");\nconst ordersRouter = require(\"./routes/orders\");\nconst config = require(\"./config\");\n\nconst app = express();\napp.use(helmet());\napp.use(morgan(config.logFormat));\napp.use(json({ limit: \"1mb\" }));\napp.use(\"/orders\", ordersRouter);\n\napp.listen(config.port, () => console.log(`API on port ${config.port}`));","startCursor":{"line":0,"ch":0},"paths":[{"keys":["q","a","c","w","import","<Esc>","f","=","c","t","\"","from ","<Esc>","f",")","x","j","0","q","5","@","a"],"tier":"idiomatic","technique":"macro:replay","core":["macro:replay","count"],"note":"Recording changed the first line, so the count is the lines that are left."}],"target":"import express from \"express\";\nimport helmet from \"helmet\";\nimport morgan from \"morgan\";\nimport { json } from \"body-parser\";\nimport ordersRouter from \"./routes/orders\";\nimport config from \"./config\";\n\nconst app = express();\napp.use(helmet());\napp.use(morgan(config.logFormat));\napp.use(json({ limit: \"1mb\" }));\napp.use(\"/orders\", ordersRouter);\n\napp.listen(config.port, () => console.log(`API on port ${config.port}`));","language":"javascript","evidence":"guided","canonicalKey":"intermediate.15#0","canonicalFingerprint":"9ughd1"}]},"python":{"id":"intermediate.15","title":"Make replay robust","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Write a macro that works on lines of different lengths, and replay it only as often as you need.</p><p><strong>Before this lesson:</strong> Record, stop and replay.</p><p>A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.</p><h3>Example</h3><p>If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.</p><p>Use Start over to try again.</p>","teaches":["macro:replay"],"introduces":["q","@","I","A","j","0","count"],"constraints":[],"drills":[{"task":"These settings are optional now. Read the six of them with <code>os.environ.get(\"…\")</code> instead of <code>os.environ[\"…\"]</code>. <code>SECRET_KEY</code> is still required.","hint":"Record the change on the first line, ending on the next one. A count before @a replays it on the rest.","mode":"python","start":"\"\"\"Settings read from the environment. Every server sets these in its unit file.\"\"\"\nimport os\n\nSENTRY_DSN = os.environ[\"SENTRY_DSN\"]\nREDIS_URL = os.environ[\"REDIS_URL\"]\nSTRIPE_WEBHOOK_SECRET = os.environ[\"STRIPE_WEBHOOK_SECRET\"]\nMAILGUN_API_KEY = os.environ[\"MAILGUN_API_KEY\"]\nCDN_URL = os.environ[\"CDN_URL\"]\nFEATURE_FLAGS = os.environ[\"FEATURE_FLAGS\"]\nSECRET_KEY = os.environ[\"DJANGO_SECRET_KEY\"]\n\nLANGUAGE_CODE = \"nl\"\nSHOP_COUNTRY = \"NL\"","startCursor":{"line":1,"ch":0},"paths":[{"keys":["2","j","q","a","f","[","c","l",".get(","<Esc>","f","]","r",")","j","0","q","5","@","a"],"tier":"idiomatic","technique":"macro:replay","core":["macro:replay","count"],"note":"Recording changed the first line, so the count is the lines that are left."}],"target":"\"\"\"Settings read from the environment. Every server sets these in its unit file.\"\"\"\nimport os\n\nSENTRY_DSN = os.environ.get(\"SENTRY_DSN\")\nREDIS_URL = os.environ.get(\"REDIS_URL\")\nSTRIPE_WEBHOOK_SECRET = os.environ.get(\"STRIPE_WEBHOOK_SECRET\")\nMAILGUN_API_KEY = os.environ.get(\"MAILGUN_API_KEY\")\nCDN_URL = os.environ.get(\"CDN_URL\")\nFEATURE_FLAGS = os.environ.get(\"FEATURE_FLAGS\")\nSECRET_KEY = os.environ[\"DJANGO_SECRET_KEY\"]\n\nLANGUAGE_CODE = \"nl\"\nSHOP_COUNTRY = \"NL\"","language":"python","evidence":"guided","canonicalKey":"intermediate.15#0","canonicalFingerprint":"9ughd1"}]},"text":{"id":"intermediate.15","title":"Make replay robust","moduleName":"Repeat, select and compose","tips":"","concept":"<p class=\"lead\">Write a macro that works on lines of different lengths, and replay it only as often as you need.</p><p><strong>Before this lesson:</strong> Record, stop and replay.</p><p>A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.</p><h3>Example</h3><p>If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.</p><p>Use Start over to try again.</p>","teaches":["macro:replay"],"introduces":["q","@","I","A","j","0","count"],"constraints":[],"drills":[{"task":"Turn the six help pages into Markdown links, like <code>[Delivery](/help/delivery)</code>. The contact line stays as it is.","hint":"Record the change on the first line, ending on the next one. A count before @a replays it on the rest.","mode":"text/plain","start":"# Help pages\n\nDelivery: /help/delivery\nReturns: /help/returns\nSizes: /help/sizes\nGift cards: /help/gift-cards\nPaying in parts: /help/klarna\nYour account: /help/account\nContact: help@northwind.shop, Monday to Friday","startCursor":{"line":0,"ch":0},"paths":[{"keys":["2","j","q","a","I","[","<Esc>","f",":","c","t","/","](","<Esc>","A",")","<Esc>","j","0","q","5","@","a"],"tier":"idiomatic","technique":"macro:replay","core":["macro:replay","count"],"note":"Recording changed the first line, so the count is the lines that are left."}],"target":"# Help pages\n\n[Delivery](/help/delivery)\n[Returns](/help/returns)\n[Sizes](/help/sizes)\n[Gift cards](/help/gift-cards)\n[Paying in parts](/help/klarna)\n[Your account](/help/account)\nContact: help@northwind.shop, Monday to Friday","language":"text","evidence":"guided","canonicalKey":"intermediate.15#0","canonicalFingerprint":"9ughd1"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Record, stop and replay.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Write a macro that works on lines of different lengths, and replay it only as often as you need.</p><p>A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.</p><h2 class=\"prose-subhead\">Example</h2><p>If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Record, stop and replay.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Write a macro that works on lines of different lengths, and replay it only as often as you need.</p><p>A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.</p><h2 class=\"prose-subhead\">Example</h2><p>If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Record, stop and replay.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Write a macro that works on lines of different lengths, and replay it only as often as you need.</p><p>A good macro moves to a fixed starting point, makes its edits and ends on the next line, ready for the next replay. I, A, f and ^ cope with lines of different lengths better than moving a set number of columns. A count before @a runs it that many times, so count only the lines that are left, and stop before any line that has to stay.</p><h2 class=\"prose-subhead\">Example</h2><p>If recording handled one of four items, 3@a does the other three. One replay too many would edit the footer. If the next item looks different, undo and adjust the macro.</p><p>Use Start over to try again.</p></div></details>"}}}