<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eoin O&#39;Brien on Medium]]></title>
        <description><![CDATA[Stories by Eoin O&#39;Brien on Medium]]></description>
        <link>https://medium.com/@EoinOBrien?source=rss-cdb7045a0c3c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tbbgpen3Wz3O3my2PpHARw.jpeg</url>
            <title>Stories by Eoin O&amp;#39;Brien on Medium</title>
            <link>https://medium.com/@EoinOBrien?source=rss-cdb7045a0c3c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 22:27:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@EoinOBrien/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Grappling with Concurrency in Mongoose]]></title>
            <link>https://medium.com/cloudboost/grappling-with-concurrency-in-mongoose-46f48e1b42ba?source=rss-cdb7045a0c3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/46f48e1b42ba</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[mean-stack]]></category>
            <category><![CDATA[mongoose]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Eoin O'Brien]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 08:31:02 GMT</pubDate>
            <atom:updated>2020-06-15T13:05:28.271Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Y-73T2SSwCopNaROvAYdg.png" /></figure><p><em>Making optimistic concurrency control easy.</em></p><p>If you’ve used the MEAN stack, then chances are you’ve heard of <a href="http://mongoosejs.com/index.html">Mongoose</a>. It’s an ODM (object document mapper) that takes the pain out of writing validation, casting and business logic for MongoDB. It’s also massively popular, with well over a million downloads per month on <a href="https://www.npmjs.com/package/mongoose">npm</a>.</p><p>MongoDB and Mongoose together provide a flexible, scalable platform for dealing with your app’s data, though they’re not without limitations. One of these is a lack of support for concurrency control.</p><p>Imagine editing a data item on your shiny new web app’s front-end. You check a few boxes, edit a few fields, then click save. Unbeknownst to you, while you were working, another user edited and saved the same data item. The version in the database is now different to the version you started with, and your save operation winds up overwriting the other user’s changes. Unfortunate, no?</p><p>I’ve run into this problem with concurrent edits myself, and I decided to do something about it.</p><p>Mongoose might not provide concurrency control out of the box, but it does provide a fantastically extensible framework, letting the user <a href="http://mongoosejs.com/docs/middleware.html">hook into various events</a>, such as validation, saving and so forth, in order to adapt their functionality to suit their purposes. Once I’d done some research on possible solutions, including <a href="https://github.com/Automattic/mongoose/issues/4004">an excellent thread</a> on Mongoose’s GitHub Issues page, I set about writing my own optimistic concurrency control (OCC) plugin for Mongoose.</p><p>I wrote the plugin in TypeScript with Gulp as a build system, using Jest to run my tests. The GitHub repo is hooked up to Travis CI and CodeClimate for testing, coverage and code quality.</p><p>The plugin is quite straightforward; it simply enables the version key on the Mongoose model (__v by default), makes sure an error is thrown if the save operation fails, and adds a pre-save hook to add our concurrency control logic.</p><p>Every Mongoose document has a unique _id field — it is used, among other things, to query for the record to save over whenever document.save() is called. My plugin extends this functionality a little — not only does the document in the database need to have the same _id, it also must have the same version number (__v). If the save is successful, then the document’s version number is incremented atomically in the same operation.</p><p>This means that in the example I detailed earlier, you wouldn’t be able to save over the other user’s edits. Your version of the document would be 0 while theirs would be 1, so our custom save hook would fail and return an error. Your app can then use this error message to prompt the user that the item they’re working on has been updated elsewhere, and that they should refresh the page to see the updated version.</p><p>Thanks to the way Mongoose handles plugins, you can add optimistic concurrency control to all of your models or just a select few. It only takes two lines of code to add it to your project.</p><p>I’ve <a href="https://www.npmjs.com/package/mongoose-update-if-current">published my plugin on npm</a>; grab a copy with npm install mongoose-update-if-current or take a look at the source code on <a href="https://github.com/eoin-obrien/mongoose-update-if-current">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46f48e1b42ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/grappling-with-concurrency-in-mongoose-46f48e1b42ba">Grappling with Concurrency in Mongoose</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with NodeMCU for the ESP8266]]></title>
            <link>https://medium.com/@EoinOBrien/getting-started-with-nodemcu-for-the-esp8266-990bc8272f18?source=rss-cdb7045a0c3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/990bc8272f18</guid>
            <category><![CDATA[nodemcu]]></category>
            <category><![CDATA[esp8266]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[lua]]></category>
            <dc:creator><![CDATA[Eoin O'Brien]]></dc:creator>
            <pubDate>Thu, 05 Oct 2017 16:25:55 GMT</pubDate>
            <atom:updated>2018-01-08T11:00:06.826Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*olm_Y-Ggcjtk6spg." /></figure><p>The ESP8266 is a low-cost, low-power Wi-Fi chip manufactured by Espressif Systems, featuring a 32-bit microcontroller and a full TCP/IP stack. It’s ideally suited to mobile devices, wearables and IoT applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*itENkIVYkUOQ_6rW.jpg" /><figcaption>The WEMOS D1 Mini development board for the ESP8266. Image credit: <a href="http://www.cnx-software.com/">www.cnx-software.com</a></figcaption></figure><p>In this article, I’m going to show you how to set started programming your ESP8266 with NodeMCU, an open-source firmware based on eLua. You’d be forgiven for expecting it to be a JavaScript framework like Node.js, but the similarity in nomenclature in fact derives from the asynchronous, event-driven programming model used by both frameworks. NodeMCU allows you to rapidly prototype on your ESP8266 with a minimum of effort and hassle.</p><h3>Installing the NodeMCU firmware</h3><p>The first step is to get hold of some NodeMCU firmware for your device. While you could download and build it yourself, it’s much easier to use the free cloud build service at <a href="https://nodemcu-build.com/">https://nodemcu-build.com/</a>. Enter and confirm your email address, don’t change the branch or the selection of modules, and start the build. It should be delivered to your inbox in less than 10 minutes.</p><p>NodeMCU Build supplies two versions of the firmware, one with support for floating-point arithmetic (with float in the filename) and one without (with integer in the filename). Download the integer version of the firmware for now.</p><p>Now that you’ve got your hands on the firmware, your next task is to flash it to your ESP8266. First, install esptool.py:</p><pre>$ pip install esptool.py</pre><p>Connect your ESP8266 development board to your computer. You should see the onboard LED flash as it’s plugged in. Use esptool.py to flash the firmware to the device:</p><pre>$ sudo esptool.py -p &lt;port&gt; write_flash -fm &lt;mode&gt; 0x00000 &lt;firmware&gt;.bin</pre><p>&lt;port&gt; will be something like /dev/ttyUSB0 on Unix-like systems and COM1 on Windows. &lt;mode&gt; should be dio if your board has 4 MB flash memory or more, and qio otherwise.</p><p>Congratulations — you’ve now got a working ESP8266 running NodeMCU!</p><h3>Uploading and running Lua code</h3><p>Now let’s get some code running. Let’s create a script called blink.lua to flash the board’s LED:</p><pre>-- Configuration<br><strong>local</strong> LED_PIN = 4<br><strong>local</strong> BLINK_MS = 1000</pre><pre>-- Toggle LED state between HIGH and LOW<br><strong>function</strong> toggle_led_state()<br>    <strong>if</strong> led_state == gpio.LOW <strong>then</strong><br>        led_state = gpio.HIGH<br>    <strong>else</strong><br>        led_state = gpio.LOW<br>    <strong>end</strong><br>    gpio.write(LED_PIN, led_state)<br><strong>end</strong></pre><pre>-- Set initial state<br><strong>local</strong> led_state = gpio.LOW<br>gpio.mode(LED_PIN, gpio.OUTPUT)<br>gpio.write(LED_PIN, led_state)</pre><pre>-- Start timer loop<br><strong>local</strong> timer = tmr.create()<br>timer:register(BLINK_MS, tmr.ALARM_AUTO, toggle_led_state)<br>timer:start()</pre><p>Next, we have to upload this code to the device. I’m going to use nodemcu-uploader.py for this tutorial, but nodemcu-tool is also worth trying out if you prefer. It can be installed with pip:</p><pre>$ pip install nodemcu-uploader</pre><p>Now we can finally upload our Lua script to the ESP8266 and run it:</p><pre>$ sudo nodemcu-uploader upload blink.lua<br>$ sudo nodemcu-uploader file do blink.lua</pre><p>You should see the onboard LED flashing at regular intervals. Hit the reset button or manually cycle the power to the board to stop it.</p><p>That’s it! At this point, you’ve got NodeMCU fully working, and you’re ready to start building your own projects on the ESP8266.</p><h3>Links</h3><ul><li><a href="https://nodemcu.readthedocs.io/en/master/">NodeMCU documentation</a></li><li><a href="https://nodemcu-build.com/">NodeMCU Build</a></li><li><a href="https://www.lua.org/docs.html">Lua documentation</a></li><li><a href="http://espressif.com/en/products/hardware/esp8266ex/overview">Espressif’s overview of the ESP8266</a></li><li><a href="https://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html">WEMOS D1 Mini development board</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=990bc8272f18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>