[{"data":1,"prerenderedAt":219},["ShallowReactive",2],{"page-one-line-of-code":3,"navigation":129},{"id":4,"title":5,"body":6,"date":118,"description":119,"draft":120,"extension":121,"hideYear":120,"meta":122,"navigation":123,"path":124,"readingTime":125,"seo":126,"stem":127,"__hash__":128},"articles/articles/one-line-of-code.md","One line of code",{"type":7,"value":8,"toc":115},"minimark",[9,13,16,19,22,33,36,42,45,62,69,72,75,78,89,99,102,105],[10,11,12],"p",{},"In 2012, I built an app for the London Olympics. I'd seen the official app in the months leading up to the games and decided I could do better, so I set to work. I wasn't looking to profit from it, I just wanted to learn how to build an app.",[10,14,15],{},"In one section was news and in another was a global medal table. These had to be kept updated in real time. Back then I wasn't as proficient in cloud services as I am now, so I was looking for a simple solution. There was no official medal list API. I needed a way of obtaining, storing and serving this data for free. I was also worried about hosting costs - afterall, this is one of the biggest world events, what if my app became popular and struggled to deliver content.",[10,17,18],{},"I decided that the easiest thing to do was host a csv file. I would keep that updated and it would load into the app on every pull-to-refresh. But how could I keep it updated? And where could I host it? I thought about watching the games religiously and inputting all the data by hand, but decided to just steal a medal table from Wikipedia instead. Thanks Wikipedia moderators!",[10,20,21],{},"I loaded up Google Sheets and typed this into a cell:",[23,24,29],"pre",{"className":25,"code":27,"language":28},[26],"language-text","=IMPORTHTML(\"https://en.wikipedia.org/wiki/2012_Summer_Olympics_medal_table\", \"table\", 4)\n","text",[30,31,27],"code",{"__ignoreMap":32},"",[10,34,35],{},"And out popped the medal table…",[23,37,40],{"className":38,"code":39,"language":28},[26],"+───────+────────────────+───────+─────────+─────────+────────+\n| Rank  | NOC            | Gold  | Silver  | Bronze  | Total  |\n+───────+────────────────+───────+─────────+─────────+────────+\n| 1     | United States  | 47    | 27      | 30      | 104    |\n| 2     | China          | 38    | 31      | 22      | 91     |\n| 3     | Great Britain  | 29    | 18      | 18      | 65     |\n| 4     | Russia         | 19    | 21      | 27      | 67     |\n| 5     | South Korea    | 13    | 9       | 8       | 30     |\n| 6     | Germany        | 11    | 20      | 13      | 44     |\n| 7     | France         | 11    | 11      | 13      | 35     |\n| 8     | Australia      | 8     | 15      | 12      | 35     |\n| 9     | Italy          | 8     | 9       | 11      | 28     |\n| 10    | Hungary        | 8     | 4       | 6       | 18     |\n| ...   |                |       |         |         |        |\n+───────+────────────────+───────+─────────+─────────+────────+\n",[30,41,39],{"__ignoreMap":32},[10,43,44],{},"Bingo!",[10,46,47,48,52,53,61],{},"All I had to do was ",[49,50,51],"em",{},"Share > Publish to web > as .csv"," and hey presto, ",[54,55,60],"a",{"href":56,"rel":57,"target":59},"https://docs.google.com/spreadsheets/d/e/2PACX-1vT0O-PnTbbeI16F9M8HlQ8SaIgaguitVhQq40tZWtU9sx1Mpy42nHcPpD3pC1SpwwAxJxl7SmvVDtoo/pub?gid=0&single=true&output=csv",[58],"nofollow","_blank","here"," was my API.",[10,63,64,65,68],{},"And better still, there was an option to ",[49,66,67],{},"Automatically republish when changes are made"," which  would poll the website every 5 minutes and update the CSV accordingly.",[10,70,71],{},"I pointed it at a few websites - BBC Sport, The Guardian, Wikipedia etc… So if markup broke on one website, it would default to the next one in line.",[10,73,74],{},"I did the same for the news; pointing at Google's own news site for tagged olympic news and then I launched the app with a few weeks to go before the opening ceremony.",[10,76,77],{},"I had tickets to the first day of the olympics and as I queued to get in with my friends, I pulled my phone out of my pocket, opened the app and pulled to refresh. It worked like a charm - all the way through the olympics. No hosting fees, no worries.",[79,80,81],"blockquote",{},[10,82,83],{},[84,85,88],"span",{"className":86},[87],"text-2xl","Actually looks like it may be easier to use than the official app",[10,90,91],{},[84,92,98],{"className":93},[94,95,96,97],"text-sm","block","-mt-4","ml-6","- The Guardian",[10,100,101],{},"The app had a reasonable amount of downloads (~10k), the API never went down, and it gave me the confidence to start building more apps and services.",[10,103,104],{},"Building digital services these days can be incredibly complicated. But I often think about this one line of code that instantly provided an API. It taught me to look for the simplest, smartest route - the fewer moving parts, the fewer things can break.",[10,106,107],{},[108,109],"img",{":sizes":110,"alt":111,"format":112,"src":113,"style":114},"400px sm:800px","My humble app - Go2012","webp","https://raw.githubusercontent.com/mulhoon/Go2012/master/screenshots/go2012.png","border:1px solid #ccc",{"title":32,"searchDepth":116,"depth":116,"links":117},2,[],"2021-05-11","How I built an API for the London 2012 Olympics with one line of code.",false,"md",{},true,"/articles/one-line-of-code",5,{"title":5,"description":119},"articles/one-line-of-code","gVZRKLf75Log1SoEm_e4j99o_0RVKWxHAKi7sHpSV8k",[130],{"title":131,"path":132,"stem":133,"children":134,"page":120},"Articles","/articles","articles",[135,141,147,153,159,165,171,177,183,189,195,201,207,208,213],{"title":136,"path":137,"stem":138,"description":139,"date":140},"Still haven't found what you're looking for?","/articles/ai-search","articles/ai-search","AI-powered search is transforming web search.","2024-10-31",{"title":142,"path":143,"stem":144,"description":145,"date":146},"Big Emoji","/articles/big-emoji","articles/big-emoji","Building an app for my kids.","2024-06-23",{"title":148,"path":149,"stem":150,"description":151,"date":152},"It probably won’t be you","/articles/it-probably-wont-be-you","articles/it-probably-wont-be-you","An interactive exploration of our lottery instincts.","2024-06-11",{"title":154,"path":155,"stem":156,"description":157,"date":158},"My memory is shot","/articles/my-memory-is-shot","articles/my-memory-is-shot","Discovering the link between writing and memory.","2024-04-28",{"title":160,"path":161,"stem":162,"description":163,"date":164},"Quotes","/articles/quotes","articles/quotes","A collection of quotes I've heard and written down at some point in my life.","2024-03-29",{"title":166,"path":167,"stem":168,"description":169,"date":170},"TikTok goes your clock","/articles/tiktok-goes-your-clock","articles/tiktok-goes-your-clock","What I learned from quitting TikTok","2024-03-26",{"title":172,"path":173,"stem":174,"description":175,"date":176},"User testing fail","/articles/user-testing-fail","articles/user-testing-fail","Attempting to think like a kid when designing a kids app.","2024-03-20",{"title":178,"path":179,"stem":180,"description":181,"date":182},"George Harrison's hands","/articles/george-harrisons-hands","articles/george-harrisons-hands","You can replicate the setup, but not the experience.","2023-01-17",{"title":184,"path":185,"stem":186,"description":187,"date":188},"Things I learned in 2022","/articles/things-i-learned-in-2022","articles/things-i-learned-in-2022","Aside from all the emergence of AI.","2022-12-20",{"title":190,"path":191,"stem":192,"description":193,"date":194},"Counting unique visitors without using cookies, UIDs or fingerprinting.","/articles/cookieless-unique-visitor-counts","articles/cookieless-unique-visitor-counts","on withcabin.com","2022-11-30",{"title":196,"path":197,"stem":198,"description":199,"date":200},"Hang up.","/articles/hang-up","articles/hang-up","Steps for for avoiding scam calls.","2022-05-06",{"title":202,"path":203,"stem":204,"description":205,"date":206},"The “yes” transaction","/articles/yes","articles/yes","Why my contact lens service is my favourite transaction.","2022-01-04",{"title":5,"path":124,"stem":127,"description":119,"date":118},{"title":209,"path":210,"stem":211,"description":212,"date":118},"The potential energy savings of deprecating Cloudflare's cfduid cookie.","/articles/the-deprecated-cookie","articles/the-deprecated-cookie","How removing a tiny cookie can have a big impact on carbon emissions.",{"title":214,"path":215,"stem":216,"description":217,"date":218},"Never launching","/articles/never-launching-products","articles/never-launching-products","It's not just about the launch, it's about the process.","2021-04-09",1772188377447]