<?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[digimondo - Medium]]></title>
        <description><![CDATA[The Digimondo Tech Blog. Find us at digimondo.de - Medium]]></description>
        <link>https://medium.com/digimondo?source=rss----dd64d3482ef8---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>digimondo - Medium</title>
            <link>https://medium.com/digimondo?source=rss----dd64d3482ef8---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 16:22:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/digimondo" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a JSON Tree View Component in Vue.js from Scratch in Six Steps]]></title>
            <link>https://medium.com/digimondo/building-a-json-tree-view-component-in-vue-js-from-scratch-in-six-steps-ce0c05c2fdd8?source=rss----dd64d3482ef8---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce0c05c2fdd8</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Arvid Kahl]]></dc:creator>
            <pubDate>Sat, 18 Feb 2017 11:53:05 GMT</pubDate>
            <atom:updated>2017-02-18T14:37:38.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*W6PAfSn9gDnBa36H9A0uJw.jpeg" /></figure><p>There are many ways to display JSON in Web Applications, but most of them are either <strong>boring</strong> or <strong>unreadable</strong>. There is a better way. I will show how I built a <a href="https://vuejs.org/v2/guide/installation.html">Vue.js</a> component that displays JSON beautifully.</p><p>If you just want to use the component, you can find a Vue.js module at <a href="https://github.com/arvidkahl/vue-json-tree-view">arvidkahl/vue-json-tree-view</a>. Otherwise, read on and see how I designed, developed and refined it from start to finish.</p><h3>Preparation: Looking at JSON</h3><p>In our User Interfaces we display plenty of JSON data, since we work heavily with REST APIs that yield <strong>variably sized responses</strong>. To be able to display those, we need a <strong>flexible UI component</strong>.</p><p>Usually, JSON is either worked into a table or displayed raw. Tables only work when you know what data to expect. Actually, they work really great when you know the structure of the data, since now you can apply semantics. But in our case, we needed something that would handle any piece of data.</p><p>That leaves the raw display option, which we also ruled out, since it might work fine on small objects, but infuriate the user when showing larger ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*3KyyggI3H6_dq7ehCglNmg.png" /><figcaption>At least they tried indenting it. And it could be worse, it could be XML.</figcaption></figure><p>Inspiration for JSON visualisation can be found with many REST API clients. Among those, <a href="https://paw.cloud/"><strong>Paw</strong></a> stood out the most to me. I use that application for developing REST endpoints for our <a href="https://www.digimondo.de/produkte/connectivity-und-firefly-network-stack/">IoT Cloud Platform Firefly</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*hnABHFDfhn_8MkcZtnTHSA.png" /><figcaption>Paw’s JSON Tree Visualisation. Yeah. I want that. That looks nice.</figcaption></figure><p>The JSON response data from the request is shown as a neatly arranged <strong>tree, with nodes and leaves. </strong>The nodes are<strong> </strong>individually <strong>expandable</strong> and clearly indicate the number of invisible items when collapsed.</p><p>The nodes and leaves also show the type of their values and descendants.</p><p>There is some nice eye-candy in there, animating the chevrons when collapsing or expanding the items.</p><p>The Tree View used in the Paw is a great model for building our own Vue.js component.</p><h3>First Step: Humble Beginnings</h3><p>Whenever I build isolated components, I take the <strong>data-first approach</strong>: what input needs to be transformed into what kind of output. For a JSON Tree View, that is pretty self-explanatory: the <strong>input will be a JSON Object</strong>, the <strong>output</strong> will be a <strong>HTML-based Tree View</strong>.</p><p>Since I’m building the component from scratch, I’ll start with laying out a basic HTML structure to develop from. Usually, I go with including<a href="http://getbootstrap.com/"> Bootstrap 3</a> (with <a href="https://jquery.com/">jQuery</a>) for a basic layout. Not strictly necessary, but useful for quick prototypes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45dfdaf36cd5b267fe32e2bb626154c3/href">https://medium.com/media/45dfdaf36cd5b267fe32e2bb626154c3/href</a></iframe><p>All it needs is a basic Vue.js instance and some <strong>sample data</strong>. I decided to start with some simple JSON that includes Integers, Strings, nested Arrays and Objects. That would, at least for the initial stages, be sufficient to build the logic I needed.</p><p>The result is not very interesting, but it does show the structure of the data we will need to transform into our Tree View:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*XUjR8kzU28dBw7DnQhM4Dw.png" /><figcaption>Baby steps.</figcaption></figure><p>You can find a <a href="https://jsfiddle.net/arvidkahl/kwo6vk9d/1/">JSFiddle for this step here</a>.</p><h3>Second Step: Preparing the Component, Tree View Edition</h3><p>Now that the source data is wired up, I wanted to prepare an <strong>empty component</strong> for the Tree View. I usually do that when building isolated components. Wire up all the bootstrapping parts, the logic will follow in a later step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f8a1d95c5857b959126826f281234be/href">https://medium.com/media/2f8a1d95c5857b959126826f281234be/href</a></iframe><p>We have now wired up our data to the component with a prop. That means that when the source JSON changes, we expect the component to react and re-draw the Tree View.</p><p>The structure already hints of the next step: we will need <strong>methods to transform the JSON</strong> into something that will be the <strong>data representation of our Tree View</strong>. It will live in a <a href="https://vuejs.org/v2/guide/computed.html">computed property</a>, as they will be re-computed only when the source data changes. The methods array will contain the logic to parse the JSON into the representation.</p><p>You can find a<a href="https://jsfiddle.net/arvidkahl/kwo6vk9d/2/"> JSFiddle for this step here</a>.</p><h3>Third Step: A Transformative Experience</h3><p>At <a href="https://www.digimondo.de/">DIGIMONDO</a>, we build most of our backend products in <a href="http://elixir-lang.org/">Elixir</a>, as it has proven to scale incredibly well for highly parallel products such as our network communication stack. Ever since I started working with Elixir professionally, my style of thinking about programming has changed significantly. Now, <strong>everything is a transformation of data.</strong> Variables and their mutability matter a lot less. We just take data, transform it, transform again and again until we reach the desired outcome. From JSON to Tree View, <strong>it’s just a bunch of transformations</strong>.</p><p>Then, how do we transform the JSON object into something useful? Let’s think about what we need here.<a href="https://en.wikipedia.org/wiki/Tree_(data_structure)"> In computer science</a>, a <strong>tree</strong> consists of a <strong>root node, child nodes and leaves</strong>. Every node can in turn be the root node of a sub-tree. That sounds fairly <strong>recursive</strong>, and that’s the exact way we will transform our JSON data.</p><p>What we expect to get from this is a <a href="https://en.wikipedia.org/wiki/Domain-specific_language">Domain-specific Language</a> for generating a tree, with all nodes and leaves properly described. Every node should have an array of child nodes and leaves, called children. Every node also has a type, either object, array or value (since objects are key/value-based, arrays are index-based and values are the termination points of our tree’s branches).</p><p>Using <a href="https://lodash.com/">Lodash</a> for most of our data transforms, the JSON can now be turned into a DSL for our Tree View like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e10ea1ff4206129f4aee86a1241b0f19/href">https://medium.com/media/e10ea1ff4206129f4aee86a1241b0f19/href</a></iframe><p>The transformed JSON will now be a bit bigger, since we enriched the whole data structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*zPLVcZn3eG-R_zbZ8yMPtQ.png" /></figure><p>But it also means we can <strong>finally build the visual component</strong>. You can find a <a href="https://jsfiddle.net/arvidkahl/kwo6vk9d/3/">JSFiddle for this step here</a>.</p><h3>Fourth Step: Painting a Tree</h3><p>At this point, we have a Tree View component that contains a representation of what the tree consists of. All we need now is to put it into the HTML. For this, we need a component to visualise it.<strong> Just like the data is a recursive description of a tree, so will the component have to recursively paint it</strong>. So it’s a essentially component that uses itself to paint its subcomponents. Yeah.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7df315c97eb9896c2507cbc0197301a/href">https://medium.com/media/b7df315c97eb9896c2507cbc0197301a/href</a></iframe><p>In the template, you’ll find <strong>three distinct paths. </strong>The component will choose the path depending on the type of the node that was passed into it. If it’s an object, it will iterate over it’s children, creating a new subtree with a string for a key for each child item. Same goes for arrays, just that they use an index as a key instead of a string. If it’s just a value with no children, the component outputs the key/value pair.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*n_ZwNjWM9F9hQt2Hy47AfA.png" /><figcaption>Now that looks like a tree. Almost.</figcaption></figure><p>Cool. At this point we have a Tree, in HTML, using a root component and a painting component. Now we can take care of the special effects. You can find a <a href="https://jsfiddle.net/arvidkahl/kwo6vk9d/4/">JSFiddle for this step here</a>.</p><h3>Fifth Step: Let me sugarcoat this</h3><p>Two things stand out in the JSON Tree View that the PAW API client provides: <strong>expandable items </strong>and <strong>hinting at item counts</strong> in collapsed items. To make that a reality for our Tree View, we need to allow each Tree View Item component to handle it’s own open/close state. Once that control is given to the directive, both features are easy to build:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6eb8329f0ba168a51183d67a7f1587d0/href">https://medium.com/media/6eb8329f0ba168a51183d67a7f1587d0/href</a></iframe><p>This allows each component to individually open and close. When closed, the component will show the amount of hidden first-level children. I even added a <strong>little CSS animation</strong> to the chevron, to show opening or closing of the sub-tree.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FSomberGoodnaturedKilldeer&amp;url=https%3A%2F%2Fgfycat.com%2FSomberGoodnaturedKilldeer&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FSomberGoodnaturedKilldeer-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="540" height="544" frameborder="0" scrolling="no"><a href="https://medium.com/media/b95e0fb15562b345f9557d59f28e6c6c/href">https://medium.com/media/b95e0fb15562b345f9557d59f28e6c6c/href</a></iframe><p>You can find a <a href="https://jsfiddle.net/arvidkahl/kwo6vk9d/6/">JSFiddle of this step here.</a></p><h3>Sixth Step: Make it Optional</h3><p>By now, we have a fully functional component to show a JSON object of any size. The single drawback right now is that when a<strong> large JSON </strong>object is passed into our Tree View component, it will <strong>automatically expand</strong> the whole thing. And it will be huge.</p><p>So what the component needs is a <em>max-depth </em>option. We need to be able to tell it to which <strong>maximum level it should be opened initially</strong>. Also, every Tree View Item component needs to know which level itself is nested at. Due to the recursion, we need to pass this information manually.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60bfec4aa4f2ab5dab62f7ac3fb31cc8/href">https://medium.com/media/60bfec4aa4f2ab5dab62f7ac3fb31cc8/href</a></iframe><p>And here we have it. After some more battling with the CSS to make the indentation only start at the first sub-tree, <strong>we now have a fully functional JSON Tree View Component</strong>. You can play around with it on <a href="https://jsfiddle.net/arvidkahl/kwo6vk9d/11/">JSFiddle</a>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2Farvidkahl%2Fkwo6vk9d%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2Farvidkahl%2Fkwo6vk9d%2F11%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2F8feb58c7dea14d362bea101bf3af765e%2F%3Fdefault%3D%26s%3D80&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc76cc1d0f39ad8fcdc7ee252e11b6fa/href">https://medium.com/media/fc76cc1d0f39ad8fcdc7ee252e11b6fa/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*drPdA9uu1YVuE8gh4QZO2w.jpeg" /></figure><p>I also chose to turn this from-scratch project into a <strong>fully-fledged single-file Vue.js component</strong> hosted on <a href="https://www.npmjs.com/package/vue-json-tree-view">npm</a>. You can find the source code on GitHub at <a href="https://github.com/arvidkahl/vue-json-tree-view">arvidkahl/vue-json-tree-component</a>. Feel free to inspect the <a href="https://github.com/arvidkahl/vue-json-tree-view/blob/master/src/TreeView.vue">Tree View</a> and <a href="https://github.com/arvidkahl/vue-json-tree-view/blob/master/src/TreeViewItem.vue">Tree View Item</a> components in their final form.</p><p><a href="https://github.com/arvidkahl/vue-json-tree-view">GitHub - arvidkahl/vue-json-tree-view: A JSON Tree View Component for Vue.js</a></p><p>If you’re interested in fabricating fancy functional frontends in JavaScript and Vue.js, building bafflingly beautiful backends in Elixir and Python, or transmuting totally transformative tooling needed in running, deploying and managing IoT networks, talk to me at <a href="/service/mailto:arvid.kahl@digimondo.de">arvid.kahl@digimondo.de</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce0c05c2fdd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digimondo/building-a-json-tree-view-component-in-vue-js-from-scratch-in-six-steps-ce0c05c2fdd8">Building a JSON Tree View Component in Vue.js from Scratch in Six Steps</a> was originally published in <a href="https://medium.com/digimondo">digimondo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple EventBus in Vue.js]]></title>
            <link>https://medium.com/digimondo/building-a-simple-eventbus-in-vue-js-64b70fb90834?source=rss----dd64d3482ef8---4</link>
            <guid isPermaLink="false">https://medium.com/p/64b70fb90834</guid>
            <category><![CDATA[components]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[eventbus]]></category>
            <dc:creator><![CDATA[Arvid Kahl]]></dc:creator>
            <pubDate>Sat, 11 Feb 2017 09:52:36 GMT</pubDate>
            <atom:updated>2017-02-12T08:20:49.365Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Simple Event Bus in Vue.js</h3><p>Whenever an <a href="https://vuejs.org/">Vue.js</a> application outgrows a certain simplicity, you isolate components to keep complexity under control. That makes them reusable, testable and maintainable. However, isolation makes it harder for components to communicate with each other. Where before there were parent and child components, the data flow is now interrupted. Another way has to be found for cross-component communication.</p><h3>Event-based Communication</h3><p>If passing <a href="https://vuejs.org/v2/guide/components.html#One-Way-Data-Flow">props</a> is not an option, the most commonly used way of exchanging information among components is to use Events. Vue.js already uses Events frequently, but mostly between components that are not isolated from each other.</p><h3>All aboard the Event Bus</h3><p>An Event Bus allows communication between components without requiring the components to explicitly register with one another. They don’t even need to be aware of their existence. The Event Bus is the central instance for all Events, and every component can publish or subscribe to it. This way, all components can talk to each other no matter what their relationship to each other is.</p><p>There are many JavaScript implementations of a central Event Bus system. Libraries like <a href="https://github.com/postaljs/postal.js/">Postal.js</a> or <a href="http://amplifyjs.com/api/pubsub/">AmplifyJS</a> are worth investigating if you expect to build very complex systems. Luckily, for simple use cases, you don’t need to use an external library at all.</p><h3>Events on the Vue Instance</h3><p>Vue.js already ships with everything you need to build your own Event Bus. Every Vue.js instance is able to <a href="https://vuejs.org/v2/api/#vm-emit">emit</a> and <a href="https://vuejs.org/v2/api/#vm-on">receive</a> Events, since these functions are used to communicate between linked components. They also work for isolated components, with a very small change.</p><p>For the Event Bus, just use an empty Vue.js instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43b44d4ca6b06c0569a7db1fbf1e56eb/href">https://medium.com/media/43b44d4ca6b06c0569a7db1fbf1e56eb/href</a></iframe><p>And that’s it. Every component can now use that Vue.js instance to send or listen to Events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f45d16572a9ecd85c0587e4cda6780c/href">https://medium.com/media/5f45d16572a9ecd85c0587e4cda6780c/href</a></iframe><p>Both components use the globally available Event Bus to communicate. With actual components being used, it looks like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2Farvidkahl%2Fgxdn6ycv%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2Farvidkahl%2Fgxdn6ycv%2F17%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2F8feb58c7dea14d362bea101bf3af765e%2F%3Fdefault%3D%26s%3D80&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a6e5248a7d1f225d9e4536ac78d09b1/href">https://medium.com/media/2a6e5248a7d1f225d9e4536ac78d09b1/href</a></iframe><h3>Tips and Tricks</h3><p>In a larger Vue.js project, you would likely abstract the Event Bus into a single file, importing it into every component file where it needs to be used. This way, it does not pollute the global namespace.</p><p>Alternatively, you can make it available to any Vue.js component by default by adding to the Vue.js prototype with <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty">Object.defineProperty</a> (thank you <a href="https://news.ycombinator.com/item?id=13623091">StreakyCobra</a> for the idea).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5118addf301528a67a2c03363b565ab4/href">https://medium.com/media/5118addf301528a67a2c03363b565ab4/href</a></iframe><p>This allows you to use the Event Bus from any Vue.js component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c4b7c4178dec59642432c3e437495b/href">https://medium.com/media/d3c4b7c4178dec59642432c3e437495b/href</a></iframe><p>The empty Event Bus instance does not need to stay empty. You can enrich the instance itself with logic to turn it into a service, maybe communicating with a real-time backend through websockets and passing new server-side events to the components via client-side events. Since your events are now handled at a central location, these things just got a lot easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64b70fb90834" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digimondo/building-a-simple-eventbus-in-vue-js-64b70fb90834">Building a Simple EventBus in Vue.js</a> was originally published in <a href="https://medium.com/digimondo">digimondo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sniffing a SPI-driven display using Arduino — and transmit values via LoRa]]></title>
            <link>https://medium.com/digimondo/sniffing-a-spi-driven-display-using-arduino-and-transmit-values-via-lora-86a39f912878?source=rss----dd64d3482ef8---4</link>
            <guid isPermaLink="false">https://medium.com/p/86a39f912878</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Stefan Reiser]]></dc:creator>
            <pubDate>Thu, 26 Jan 2017 14:00:22 GMT</pubDate>
            <atom:updated>2017-01-26T14:00:21.694Z</atom:updated>
            <content:encoded><![CDATA[<p>We have an interesting project going on, that involves to bring an usually offline machine online using <a href="https://www.digimondo.de/en/technology/">LoRa</a>. The customers interest to do this with the particular machine, is to get information when errors occur during normal operation. But there is no accessible interface to query the device’s hardware for potential errors. However, some components are easily accessible as they are attached using <a href="https://en.wikipedia.org/wiki/JST_connector">JST</a> jacks.</p><p>So is a 7-segment display , and google reveals how it is attached (LiteOn LTM-8328PKR-04) — SPI, gotcha !</p><p>From the machines datasheets and our customer we know that errors are indicated by a blinking number on this display, so finding out if there is any failure should be easy by grepping the displays reading.</p><p>But there is one problem, we need to put our arduino in slave mode and should not interfere the communication to the display. So we decided to use the arduino to simply act as an “read only” slave and just grab communication to the display in a “man-in-the-middle-like” manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FtEhty9hUlvRGcb854u5aw.jpeg" /><figcaption>First setup</figcaption></figure><p>Using only one device however was not possible in this case, so we decided to split up LoRa-communication and SPI-sniffing. For the LoRa part we decided to use a modded <a href="https://lowpowerlab.com/">moteino</a> and utilize the <a href="https://github.com/matthijskooijman/arduino-lmic">arduino-lmic</a> library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*qISCzRJeodL0Cll9Bv_KFg.png" /></figure><p>To become a slave we have to setup it as following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1ad8becd3b59efc2a14ffde50aaeec6/href">https://medium.com/media/a1ad8becd3b59efc2a14ffde50aaeec6/href</a></iframe><p>So all that is left to do, is to define some sort of global buffer to pump packets in and process them as soon as the buffer is full.</p><p>With this particular display, 36 bits are pushed over to change the value to be displayed. The first bit will always be 1, the following 4 bytes are representing the values of the four “slots”. As we can only “react” on fully transmitted bytes with this method we will loose information about a possible trailing decimal point and have to shift each “slot” by 1 left (first three decimal point bits could be used by “merging” the next bytes highest bit though). The rest is easy, read the datasheet, “translate” every single slot unit (calculate or just look up).</p><p>If there is a sequence of zero (empty display) and X we finally have identified our error code and can send it over to the moteino which will then wrap it into a LoRaWAN packet and send it away.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKguytWy4UqAY9bFQO5etQ.jpeg" /><figcaption>The finished prototype</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86a39f912878" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digimondo/sniffing-a-spi-driven-display-using-arduino-and-transmit-values-via-lora-86a39f912878">Sniffing a SPI-driven display using Arduino — and transmit values via LoRa</a> was originally published in <a href="https://medium.com/digimondo">digimondo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bulk remove OCR from PDFs with Swift]]></title>
            <link>https://medium.com/digimondo/bulk-remove-ocr-from-pdfs-with-swift-f4e2aedec3c0?source=rss----dd64d3482ef8---4</link>
            <guid isPermaLink="false">https://medium.com/p/f4e2aedec3c0</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[pdf]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Moritz Schmale]]></dc:creator>
            <pubDate>Tue, 24 Jan 2017 13:28:45 GMT</pubDate>
            <atom:updated>2017-01-27T10:38:46.341Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes you need to black out sensitive information from PDF documents. You could print everything, use a black pen and censor everything, only to scan all the documents again, because you need them in digital form. But that’s a waste of paper and ink, and also a lot of effort is required if you need to do that to a lot of documents.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FAngryFloweryHowlermonkey&amp;url=https%3A%2F%2Fgfycat.com%2FAngryFloweryHowlermonkey&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FAngryFloweryHowlermonkey-size_restricted.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=gfycat" width="736" height="1142" frameborder="0" scrolling="no"><a href="https://medium.com/media/da1c996b4efd9d8c1c01e9f557c5bfbc/href">https://medium.com/media/da1c996b4efd9d8c1c01e9f557c5bfbc/href</a></iframe><p>You can also use macOS’ builtin Preview.app to paint black boxes over sensitive content.</p><p>This is great, however, this won’t remove the underlying text at all. If you save this as PDF, you can still select the text behind the black box and copy it somewhere else to reveal it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*PsFIKyyZudb9B6h2J8wzww.png" /><figcaption>Automator Print Plugin</figcaption></figure><p>We’re in luck though, since Apple provides us with powerful PDF tools in Automator. For example, we can create a Print Plugin that receives a PDF file which we can process.</p><p>Here, we use the “Render PDF Pages as Images” action which flattens any rich PDF document to a bitmap version of it former self, without OCR and with just one layer.</p><p>For each page in the input document, it creates a TIFF image.</p><p>Then, we create a new PDF using the “New PDF from Images” action. This saves the output from the previous action to a file and we’re done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*VnTpUuwsMBGJ5948y-elOw.png" /><figcaption>Activate the print plugin from any macOS print dialog</figcaption></figure><p>Since this is a print plugin, we can use it from the macOS print dialog. Just click the PDF dropdown and find your fancy new print plugin at the bottom of the list.</p><p>After clicking the print plugin, automator will do its thing and then you have a new PDF file on your Desktop.</p><p>This approach is excellent for a few documents, but as your status as the “Remove OCR from PDF Guy” gets more known around your company, you might someday get a whole directory of PDFs to process.</p><p>That’s what happened to me, so I decided to create a little swift app that does the same to a whole directory structure.</p><h3>Moving to Swift</h3><p><a href="https://developer.apple.com/swift/">Swift</a> is Apple’s new language for their ecosystem. All the APIs you know from Objective-C are available for Swift as well, so you can do anything you could already do with Objective-C, but with a much nicer language (<a href="http://elixir-lang.org/">that reminds me of a certain other language</a>).</p><p>Just 3 hours of StackOverflow and chill later, I produced this script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4aaf83b10512ef97ad071fd0ae0194f/href">https://medium.com/media/a4aaf83b10512ef97ad071fd0ae0194f/href</a></iframe><p>It loops over all files in the input directory (defined in line 24) recursively, opens all PDF documents and loops over all the pages (31–39).</p><p>For every page in the document, it will calculate the resolution of the image (43–45) and then creates a bitmap (CGContext) that will hold the rendered page. To increase the output quality, we multiply the resolution by 2 (since page?.bounds() returns in a weird unit, 1/10 mm, this results in a resolution of 200 pixels per cm) and scale the context accordingly (line 49).</p><p>Finally, we can use page.draw() to render the page as a bitmap (line 50).</p><p>Some context-to-NSImage magic later, we can create a new PDFPage with the rendered image and replace the pages (55–57).</p><p>After all pages have been rendered, we can use document.save() to store the modified PDF document in a new file, while even preserving the old directory structure.</p><p>Legal will be so happy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*T3glF_y7QHyg1JKjPN7Cfg.png" /></figure><h3>To Clarify</h3><p>The term “removing OCR” is not 100% accurate, what we’re doing here is transforming all the things that make up a PDF (text, vectors, images) into just one image layer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4e2aedec3c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digimondo/bulk-remove-ocr-from-pdfs-with-swift-f4e2aedec3c0">Bulk remove OCR from PDFs with Swift</a> was originally published in <a href="https://medium.com/digimondo">digimondo</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>