<?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 Julian Rubisch on Medium]]></title>
        <description><![CDATA[Stories by Julian Rubisch on Medium]]></description>
        <link>https://medium.com/@minthesize?source=rss-472d3f7a0fed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ejSZb514KaYFO_quPgQrRw.jpeg</url>
            <title>Stories by Julian Rubisch on Medium</title>
            <link>https://medium.com/@minthesize?source=rss-472d3f7a0fed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 14:56:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@minthesize/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[The Post-Modern Web: StimulusReflex, or the Renaissance of Simplicity]]></title>
            <link>https://medium.com/@minthesize/the-post-modern-web-stimulusreflex-or-the-renaissance-of-simplicity-9b0357738814?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b0357738814</guid>
            <category><![CDATA[stimulusreflex]]></category>
            <category><![CDATA[stimulusjs]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Wed, 30 Sep 2020 18:03:06 GMT</pubDate>
            <atom:updated>2020-09-30T18:03:06.460Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Post-Modern Web: StimulusReflex, or the Renaissance of Simplicity, Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CW3ZbS9b7O4d1qt2" /><figcaption>Photo by <a href="https://unsplash.com/@jesuskiteque?utm_source=medium&amp;utm_medium=referral">Jesus Kiteque</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The year 2020 will be remembered as the year when a pandemic struck the world, and sanity returned to web development. While these two observations bear no apparent connection, they actually have a causal relation. With the world in lockdown and many developers forced into remote work, technologies empowering small teams, and solo practitioners to deliver outsized results are in high demand.</p><p>This year also saw the impressively-marketed release of HEY, Basecamp’s ingenious take on an improved email workflow. With it came a promise of renewal of ”old-school” web technologies like HTML delivered “over-the-wire”. HEY also served as a preview for new versions of Turbolinks and StimulusJS, which focus on embellishing the server-rendered web page with smart behaviors instead of trying to boil the ocean.</p><p>To be clear, this approach isn’t new (it dates back to the original notion of AJAX in the early 2000s). More recently, it has attracted attention through proponents such as Phoenix LiveView, Laravel LiveWire — and in the context of Rails: StimulusReflex, which this article is about.</p><p>Since Single Page Applications (SPAs) claim the title of comprising the “modern” web in its entirety, let’s call this new movement the ”Post-Modern Web”, for lack of a better term. After all, in the tradition of postmodernism itself, we want to challenge the “total truth” that is professed to amount to SPAs and microservices as opposed to multi-page apps and monoliths.</p><blockquote>Disclaimer: This article reflects my personal opinion and is going to stir emotions. Keep in mind though, that I don’t claim to have the monopoly on truth. Rather the opposite, I embrace all kinds of different takes on this subject and encourage discussion and diversity. After all, we all want to make the web better! This is not a StimulusReflex tutorial either, rather a philosophical reckoning of the state of web development.</blockquote><p>With that said, let’s dissect this topic piece by piece and see what StimulusReflex has to offer.</p><h3>1. The Fallacy of Serverless Architecture</h3><p>Serverless became a buzzword in the late 2010s, with companies from Amazon and Google down to Cloudflare providing options for running stateless functions. The promise of modularity, payment prorated to the second, and — not to be forgotten — environmentally aware computing was compelling.</p><p>On top of that, the notion that frontend developers could “just” extrapolate their JavaScript knowledge and write a full-fledged web app using a couple of serverless functions and a few API calls (more generally known as the JAMStack) attracted legions of programmers.</p><p>However, a lot of complexity in these scenarios is hidden in the details of how your application is structured and the entailing fine web of dependencies:</p><ul><li>Business logic and application state both have to be integrated in frontend code.</li><li>Any CRUD operations have to be coded as API calls (presumably via GraphQL).</li><li>Those APIs will often be provided by disparate services with their own set of change, uptime, maintenance etc. policies.</li><li>Search Engine Optimization will be a source of problems, and can only be resolved by applying (you guessed it) server side rendering.</li></ul><p>Note that this often goes unnoticed or is accepted as having no alternative: headless CMS here, GraphQL store there, and webhooks to trigger notifications on top of it.</p><p>Here‘s how a typical application (one that I wrote!) might be structured:</p><figure><img alt="Serverless Architecture with multiple agents" src="https://cdn-images-1.medium.com/max/1024/1*UPn42gCqSZAXkTZOLme6nA.png" /></figure><p>Ruby on Rails (as a stand-in for others such as Django or Laravel), on the other hand, has proven to be a highly productive environment for generations of web developers over the past 16 years. It comes with a well-vetted set of tools to codify (and simplify) exactly the front-backend contract, such as Turbolinks, Rails-UJS, and most recently StimulusJS. Importantly, as a developer, <strong>you control all dependencies yourself</strong> — a fact that cannot be stressed enough, especially for solo devs. DHH dubbed this the Majestic Monolith and while — like any concept — it is debatable in its essence, it leaves you a lot more <strong>confident</strong> than a serverless approach where you have to monitor your dependencies all the time.</p><p>What does StimulusReflex put on the table? Nothing short of assuming responsibility of rendering and replacing your HTML responding to user actions, leaving you the freedom to focus on a tighter application architecture.</p><p>Here are the cornerstones of what it adds to your Rails application:</p><ul><li>Server-side management of application state with a mental model that is easy to grasp (and will feel like relief to people frustrated by rendering JSON payloads from GraphQL endpoints)</li><li>First class support for reactive UIs through <a href="https://github.com/patrick-steele-idem/morphdom">morphdom</a></li><li>Reusable server logic without enforcing a particular application structure</li></ul><p>Here’s an example of how you could use StimulusReflex to devise a robust, late-bound filtering logic that can be re-used for any resource (I’m assuming that you read at least the <a href="https://docs.stimulusreflex.com/quickstart">Quick Start Guide</a> of the StimulusReflex docs).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sCjfS5DDzOTZskIWBJjx-w.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cea6ab015fbaacc81a7c9ccbfb9453f2/href">https://medium.com/media/cea6ab015fbaacc81a7c9ccbfb9453f2/href</a></iframe><p>When the user selects a category from a drop-down, StimulusReflex calls the filter method of the Reflex class and makes use of the standard Rails session object to hold the chosen category. The controller action is now able to re-render the page, now showing only the filtered records. This new version of the DOM is sent to the browser where it is diffed against the active page, and changed to reflect the new state on the server. No state is stored on the client; indeed, you&#39;d see the same thing if you hit refresh.</p><h3>2. The Current State of Web Performance</h3><p>In recent time we have seen an evangelization of Single Page Applications (SPAs) that went by almost unquestioned. Now there are lots of perfect use cases for this, but there are also alternatives that can be considered from a software design, as well as a performance perspective. Software design and organizational questions include code duplication between front- and backend, dividing your team in siloed specialists rather than generalists, and so on. <a href="https://link.medium.com/rhULBcs159">This excellent article</a> by Jorge Manrubia offers interesting insights into this relatively recent perceived schism.</p><p>Let’s focus on the performance part here. SPAs are perceived as fast, and in fact they are, after they are done parsing and executing the downloaded JavaScript bundle. The crucial metric here is called</p><h4>Time to Interactive</h4><p>To become interactive after the initial request, an SPA has to</p><p>1. Download the HTML page and all resources (including the JavaScript bundle),</p><p>2. Parse and execute the bundle,</p><p>3. Fetch some initial data, presumably JSON via an API call,</p><p>4. Parse and render this data in the DOM</p><p>Leaving network latency out of the equation, phase 2 is the bottleneck here. The effort to parse and execute a JavaScript bundle depends largely on its size, which is why most libraries, or their respective build steps, <a href="https://web.dev/interactive/#how-to-improve-your-tti-score">go to great lengths to optimize this stage</a> (by tree shaking and chunking).</p><p>One of the more recent strategies to come around this is to render your HTML server-side (sic!) and deliver it together with the JavaScript bundle containing the SPA as an entry point. Now while I can see merits in the code sharing („isomorphic JavaScript“) that is possible in such a scenario, consider how a request is served now:</p><ol><li>On the server, query the database and/or API to fetch initial data</li><li>On the server, render HTML and send it over to the client</li><li>On the client, parse and display the HTML</li><li>On the client, parse and execute the JavaScript bundle and load the SPA</li><li>Now the SPA is ready to take over.</li></ol><p>Call me narrow-minded, but this seems like reinventing PHP with a code-sharing approach between server and client, but without the benefits of a clear architecture (like MVC, for example). Generating HTML on the server and sending it over including some additional JavaScript is what we’ve been doing for decades. Have we finally come full circle?</p><h4>Multi Page Applications</h4><p>Let’s look for alternatives, then. Or maybe: let’s not. Because everything can actually stay as it has been concocted by Tim Berners-Lee in the 1990s, albeit with a few drop-in replacements. Let’s look at what problems SPAs actually try to solve, and how a <a href="http://www.modernmpa.com/">Multi-Page Application</a> could address that.</p><h4>1. Page Transitions</h4><p>Every traditional navigation on a web site issues a new HTTP request along with all the CSS and JS parsing and execution shenanigans over and over again. Transitions from page to page feel jittery and slow. So what do we do about it?</p><p><a href="https://github.com/turbolinks/turbolinks">Turbolinks</a>, which you might have heard about if you’re working in a Rails context, improves on this situation. It intercepts navigation events exchanging normal HTTP for XHR requests and swapping out the HTML body. (There’s other things happening behind the scenes, like building up a cache that can be used when navigating back and forth, but I won’t discuss that further).</p><p>So the alert reader will notice: Swapping out the body means leaving the HTML &lt;head&gt; intact, thus not necessitating a re-parsing of CSS and JavaScript. A huge speed-up which still requires sending over HTML instead of JSON, but often the difference in byte size over the wire (especially when brotli-compressed) is negligible.</p><p>Of course, now some standard events like DOMContentLoaded won’t fire, which in the past lead to problems with your occasional JQuery plugin and left many developers puzzled, ditching Turbolinks from the Gemfile. Fortunately, as frameworks like StimulusJS become more and more widely used, these concerns are a thing of the past.</p><h4>2. Reactive, Component-Based UIs</h4><p>Turbolinks is great, but SPAs give us the capability to surgically exchange only small parts of the DOM, when the app state changes. Basically this necessitates the use of a client-side store for your state (think Redux, Vuex, React Contexts etc.) and all the complicated strategies involved for synchronizing it to your app’s data layer (Redux-Saga etc.).</p><p>So the generally accepted opinion to this date is that you cannot have reactive, component-based UIs using a server side rendered approach.</p><p>Wrong.</p><p>The recently released StimulusReflex v3.3 introduces different “morph modes”, one of which—the <strong>selector morph</strong>—is perfect for this use case. You can easily swap out page components by simply applying a morph to a CSS selector of your choice. So you can check a checkbox in one section of your page and update another section in a a few milliseconds. Use good old server-side sessions for state persistence.</p><p>Expanding on the example above, here’s how that could look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9022e0d1bcc4225ff37f496c86b4f4f1/href">https://medium.com/media/9022e0d1bcc4225ff37f496c86b4f4f1/href</a></iframe><p>How is that possible? Selector morphs bypass the entire Rails middleware+routing stack and let you directly render whatever string you want into a DOM element present on your page. Making use of ApplicationController.render gives you maximal reusability of your view templates, too.</p><h4>3. Isolated Frontend Codebase</h4><p>This is an almost political issue: The move towards SPAs that can be distributed as static websites and only need an arbitrary web space to live in, without any runtime requirements such as databases or app servers, not only convinced a lot of decision makers to migrate to JAMStack environments, but also attracted many aspiring developers.</p><p>Let me say clearly that building applications without the need to care about backend languages or keeping your page live in the hours after Reddit discovers you is an achievement of great merit. Today we have an army of talented people building great value on the web. But it is also a somewhat misleading simplification and source of confusion down the road.</p><p>Believe it or not, the passage of time attracts entropy, almost guaranteeing that APIs change, SaaS start-ups go bust, headless CMS’s suddenly adapt their pricing schemes etc. Deciding whether to pull in a dependency or roll your own implementation is one of the toughest calls there is in software engineering. With some years of experience, I tend to start with <strong>no</strong>, but your mileage may vary from project to project.</p><p>Building an <em>entire programming model</em> around dependencies you cannot control from my current perspective—been there, done that—seems ill-advised to say the least. If you don’t want to take my advice, maybe take it from Sandi Metz:</p><blockquote>Depend on things that change less often than you do.</blockquote><p>I developed a healthy habit of scrutinizing my dependencies against this policy once in a while.</p><h3>Intermission</h3><p>In Part 2 we’re going to look at how a Websocket-centric, Server-Side-Rendered approach translates to material and immaterial profits, such as value delivered, increase in productivity and developer happiness. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b0357738814" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hidden Overbookings — Freelancers’ Fast Lane to Burn Out]]></title>
            <link>https://medium.com/@minthesize/hidden-overbookings-freelancers-fast-lane-to-burn-out-467867bd4991?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/467867bd4991</guid>
            <category><![CDATA[freelancing]]></category>
            <category><![CDATA[freelancers]]></category>
            <category><![CDATA[scheduling-software]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Sun, 30 Aug 2020 08:08:46 GMT</pubDate>
            <atom:updated>2020-10-01T08:29:14.938Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hidden Overbookings — Freelancers’ Fast Lane to Burn Out</h3><p>I’ve been a freelance software engineer for 7 years now, and had the immense luck of being fully booked most of the time. My primary source of stress was too much work, not the lack thereof.</p><p>During the COVID lockdown, I couldn’t take on as much work, so I was left with some “spare” time to think about my work practice and started to see patterns. One of my epiphanies was related to workload distribution.</p><h3>Burn Rates Aren’t Linear</h3><p>Traditional planning software (or your homegrown Excel sheet, for that matter) lets you allocate time over a certain timespan, but that’s not how a typical project passes off.</p><p>There are several reasons why work doesn’t happen linearly, here are some usual suspects:</p><h4>Sprint-, or Cycle-Type Work</h4><p>This — at least for me — typically happens with retainers. Once a month I meet the client to demo what has been done and prioritize new work packages. While all is fresh in memory, I start executing tasks and implementing features. In the middle of the month, some other project needs my attention, and work grinds to a halt. Then, right before the next “sprint review” meeting, I work off all remaining tasks.</p><p>Here’s how that looks like in an hour-per-week bar chart. The pink arrows denote weeks with meetings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FiaQFF39qPiIAVER.png" /></figure><h4>Waiting for the Client to Hand Over Assets</h4><p>We’ve all been there. Prerequisites and requirements for a project are discussed at great length, you start to build wireframes, craft a first prototype. Because there are no production assets yet, you fill in the gaps with all sorts of fake data: Lorem text, unsplash images, dummy CSV data etc.</p><p>Weeks pass, and despite urging the client to send you some data, nothing happens. Further development is stalled. When the finalized and signed off assets finally arrive, they hold all sorts of surprises:</p><ul><li>CSVs don’t match agreed upon specifications</li><li>Images come in the wrong formats (a classic: JPGs without alpha instead of transparent PNGs)</li><li>Text arrives unformatted, etc.</li></ul><p>So, to deliver on time, you start hustling and adapting everything until it fits the your project’s criteria. Below are two typical examples of how workloads distribute over time when your bottleneck is waiting for client data to arrive:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WIKd2T30DhfD6Wky.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QwLTGrCAeXPXQr23.png" /></figure><p>Hidden overbookings happen when you unintentionally pile up work with incompatible burn rates.</p><p>So while your scheduling app or calendar is showing you this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BHlqT_Wq4oK6NpYW.jpeg" /></figure><p>What’s actually happening is only revealed if you take a closer look at the accumulated burn rates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0DantvAFd96GOEuM.jpeg" /></figure><p>Without noticing, you overbooked your schedule and unwittingly agreed to a massive, predictable amount of stress that could have easily been avoided.</p><p>Now you could argue that work can always be shifted back and forth in time, filling in the gaps in your calendar. Practice shows, that that’s not always possible. Some dates may be fixed (take trade fairs as an example), other times you simply depend on external processes. The heteronomous powers affecting your schedule far outnumber your personal preferences.</p><h3>Take Control Over Your Schedule</h3><p><a href="https://www.crowsnestapp.com/">Crow’s Nest</a> sets out to remedy this shortcoming by</p><ol><li>allowing different types of burn rates into the equation, and</li><li>taking advantage of your time tracking data.</li></ol><p>Let me explain how this works:</p><h4>Leverage Burn Rate Types</h4><p>In the simplest case, you know beforehand what kind of project, and thus workload distribution you’re dealing with. Choose between</p><ul><li>Constant</li><li>Valley</li><li>Hill</li><li>Decreasing</li><li>Increasing</li></ul><p>to model your bookings.</p><h4>Integrate Your Time Tracking Data</h4><p>There are two ways in which including your time tracking data can help you avoid overbookings:</p><ol><li><strong>Analyze past projects and use average workload distribution over time</strong> to predict new projects. Since patterns are often client-specific, this is very helpful for clients that book you <strong>repeatedly</strong>.</li><li><strong>Analyze the characteristic</strong> of running projects and <strong>predict their further development</strong>. Thus you can spot bottlenecks faster and make reliable assertions about your availability.</li></ol><p><em>Originally published at </em><a href="https://www.crowsnestapp.com/product/2020/08/30/hidden-overbookings-freelancers-fast-lane-to-burn-out/"><em>https://www.crowsnestapp.com</em></a><em> on August 30, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=467867bd4991" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cache Dynamic Assets Offline in Electron Apps]]></title>
            <link>https://medium.com/better-programming/caching-dynamic-assets-offline-in-electron-apps-797232f18ec8?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/797232f18ec8</guid>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[electronjs]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 15:31:36 GMT</pubDate>
            <atom:updated>2020-01-10T15:41:08.282Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Why I created a custom ExpressJS caching middleware</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pd5gMwFduldFJGmj" /><figcaption>Photo by <a href="https://unsplash.com/@milkovi?utm_source=medium&amp;utm_medium=referral">MILKOVÍ</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Get asset-file-cache-middleware </strong><a href="https://www.npmjs.com/package/express-asset-file-cache-middleware"><strong>via npmjs.com</strong></a><strong>.</strong></p><p>Developing custom <a href="https://electronjs.org/">Electron</a> apps for situations with unusual requirements sometimes leads to surprising learnings. When I was commissioned with a project that should be</p><ul><li>portable, to be used at trade exhibitions,</li><li>adaptable, to be distributed to a variety of clients, and</li><li>scalable, able to be rolled out to a yet unspecified number of devices,</li></ul><p>I knew it would take a large dose of creativity to accommodate all those needs.</p><p>Normally, you would bundle all assets and copy with the application and distribute it, but in this case, that was not an option because I knew in advance there would be many last-minute changes to both of them. Additionally, the concept needed to be transferable to other projects, so I decided to go with a headless CMS, in this case, <a href="https://www.contentful.com/">Contentful</a>.</p><p>This technology decision offered both</p><ul><li>adaptability, obviously, because clients could exchange content at their own will and pace, and</li><li>scalability, because since Electron apps simply package a Chromium browser, I would be serving just another web app that would download new content as it became available.</li></ul><p>What I was left with was the problem of portability because the software needed to provide true offline capabilities in case of a flaky internet connection or other weird circumstances.</p><p>In this piece, I’ll outline three consecutive approaches I took to tackle this situation.</p><h3>Act 1: Service Workers</h3><p>The first take was to employ service workers that precache content in the integrated Chromium browser. Since the application front end was simply a React app created with <a href="https://github.com/facebook/create-react-app">create-react-app</a>, and it packages <a href="https://developers.google.com/web/tools/workbox">Workbox</a> (in the form of <a href="https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin">workbox-webpack-plugin</a>), it seemed worthwhile to put it to the test.</p><p>In create-react-app, this behavior is opt-in, so you need to change the serviceWorker.unregister() to serviceWorker.register() in index.js:</p><pre><em>// If you want your app to work offline and load faster, you can change<br>// unregister() to register() below. Note this comes with some pitfalls.<br>// Learn more about service workers: </em><a href="https://bit.ly/CRA-PWA"><em>https://bit.ly/CRA-PWA</em></a></pre><pre>serviceWorker.unregister();</pre><p>When I did that, upon inspecting the DevTools, it quickly became clear that this was not working as intended. As it turns out, precaching in the service worker config create-react-app creates was limited to JavaScript files and stylesheets. Since I needed to cache assets, and remote ones at that, a different approach was required.</p><p>So I needed to dive deeper into the webpack config, which is only possible by ejecting from create-react-app. The way I approached this was by creating a git release branch and ejecting there, so everyone on the team could continue working on an un-ejected version while I was tweaking the config.</p><p>Media files are preferably cached at runtime rather than before application load (precached) since they would delay the initial application startup time substantially. Furthermore, as clients could update contents through the headless CMS, this would amount to writing a crawler that would precache all the media files, which was unfeasible to do.</p><p>That’s why I resorted to configuring the runtimeCaching section of the GenerateSW section of webpack.config.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/877396abbb5f37bb2be44e90cdeee3f8/href">https://medium.com/media/877396abbb5f37bb2be44e90cdeee3f8/href</a></iframe><p>This approach seemed to work until we tested it in a near-production environment, i.e. with a realistic number and size of assets. Adding more and more assets, it became obvious that items from the runtime cache were evicted and loaded from the CDN Server when they should have been fetched from the cache. Curious about what was happening, I came to the conclusion that there must be some disk quota in place for the size of the service worker cache. This made intuitive sense, but there is only scarce information available online for this otherwise rather undocumented limitation:</p><blockquote>“The amount available to service worker caching isn’t defined in the specification. The amount varies by browser depending on device and storage conditions.” (<a href="https://love2dev.com/blog/what-is-the-service-worker-cache-storage-limit/">https://love2dev.com/blog/what-is-the-service-worker-cache-storage-limit/</a>)</blockquote><p>See this image for a breakdown of how limits are calculated, based on the available (free) disk space: <a href="https://love2dev.com/img/consensus-storage-capacity-1697x666.png">https://love2dev.com/img/consensus-storage-capacity-1697x666.png</a></p><p>So with standard Intel NUCs, you often end up with &lt;30 GB (free disk space), which gives you only about 500 MB of storage space. Download a few HD video files, and you’re already over your quota.</p><h3>Act 2: Disk Cache Using Express Middleware, First Attempt</h3><p>Whether or not this was really the root cause for the evictions taking place, it was certainly an unsatisfying situation for our use case. Since a large amount of disk space remained unused, and there would not be a single other app running on the NUCs designated for this project, I decided to go ahead and try to solve that on Electron’s main process, more precisely in the supporting ExpressJS server.</p><p>So I started researching existing middlewares but didn’t find one matching our requirements. Most of them, like <a href="https://github.com/chimurai/http-proxy-middleware">http-proxy-middleware</a>, were tailored to caching or proxying textual assets like JavaScript files, SVG graphics, or stylesheets.</p><p>Before I go on describing the solution I implemented, let’s take a closer look at the components that the problem is made up of:</p><ul><li>The requests to Contentful’s asset CDN have to be proxied by the Express server to be cacheable.</li><li>Assets should be cached to a unique, idempotent path.</li><li>The cache directory as well as the cache key should be configurable but have a fallback.</li><li>Content type and size should be recoverable from the cache.</li></ul><p>The first requirement was easily fulfilled with a custom Express route:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa4aa43cdb469ad4afdf7f14a1e2cb72/href">https://medium.com/media/fa4aa43cdb469ad4afdf7f14a1e2cb72/href</a></iframe><p>A unique cache path can be constructed by hashing the cache key (which has to be unique to the asset, obviously). To provide faster file system access, the cached asset is stored two directory levels deep, whose names are also retrieved by dividing and modulo dividing the hash:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88354e9d17e0a3c4846104a215edb33d/href">https://medium.com/media/88354e9d17e0a3c4846104a215edb33d/href</a></iframe><p>The middleware then tries to find the cached asset at the specified path. If it succeeds, it passes it on in a res.local variable, else writes it to the path and then passes it on. There is one edge case we should be prepared for: If fs.writeFileSync fails in the middle of writing to disk, we should remove the file just to avoid having a cache entry with partial data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d898d91133939fbb589b78477644f21/href">https://medium.com/media/1d898d91133939fbb589b78477644f21/href</a></iframe><p>Attentive readers will notice that this version of the middleware isn’t a real offline solution because there is a HEAD request necessary, even in the cached execution path, to determine the asset’s content type and length. Certainly, that’s not really an ideal solution.</p><h3>Act 3: Encoding and Storing Metadata</h3><p>Therefore, we needed a way to store that metadata pertaining to each asset. One way would have been to introduce a database, be it SQLite or a flat file. That, however, would have interfered with the objective to implement a portable solution. So instead of doing that, we decided to store that information in the filename itself, in a base64 encoded format:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/391b04683a52de809eded2dd90efc8ac/href">https://medium.com/media/391b04683a52de809eded2dd90efc8ac/href</a></iframe><p>That worked remarkably well, and had it been for this project, we’d just have called it a wrap and finished it. Since I could already envision that this could be useful for other future projects (mine or even of interested others), I pondered whether it would be feasible to extract this to its own npm package (<a href="https://www.npmjs.com/package/express-asset-file-cache-middleware">which I eventually did</a>). To do that, however, there would eventually be the requirement of evicting elements before they would clutter up the device’s hard drive.</p><h3>Coda: Least Recently Used Eviction Strategy</h3><p>For the moment, this is achieved by setting a hard upper limit for the size of the cache directory. There are two separate recursive operations necessary to make this work:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c432890fd0f24fdc25d424b6b59d90b/href">https://medium.com/media/9c432890fd0f24fdc25d424b6b59d90b/href</a></iframe><p>First, whenever a new file is to be written to the cache, evictLeastRecentlyUsed is called with the cacheDir and with maxSize (in bytes). If the folder size (using <a href="https://www.npmjs.com/package/get-folder-size">get-folder-size</a>) is exceeding the maximum size, it will go and find the least recently used<em> </em>asset and remove it, recursively, until the folder size has shrunk far enough.</p><p>The findLeastRecentlyUsed function itself is also called recursively because we need to traverse all present directories and find the one with the oldest access time (atime).</p><p>Finally (not shown in the gist, but feel free to <a href="https://github.com/julianrubisch/express-asset-file-cache-middleware/blob/c5eb3f84f17249ab29b17b138c7123bf950d6f26/index.js#L147">browse the source</a>), whenever a file is read and returned by the middleware, we have to touch it, to update the atime.</p><h3>Conclusion</h3><p>This leaves a final question to be answered. Why did I choose to implement my own solution instead of plugging together a middleware from a bunch of off-the-shelf npm packages like <a href="https://www.npmjs.com/package/express-cache-middleware">express-cache-middleware</a> with <a href="https://www.npmjs.com/package/cache-manager">cache-manager</a> and an appropriate <a href="https://github.com/hotelde/node-cache-manager-fs">back end</a>?</p><p>Well, there will always be trade-offs involved in such a decision, so let me just briefly sum up my considerations:</p><p>First, the more dependencies you agglomerate in a project, the more you are likely to spend your future nights trying to work around an incompatibility that suddenly crept up in a dependency you possibly didn’t even know you had in your tree. Here’s a wise quote by <a href="https://www.goodreads.com/author/quotes/5763434.Sandi_Metz">Sandi Metz</a>:</p><blockquote>“Depend on things that change less often than you do.”</blockquote><p>With JavaScript packages, I dare say the probability that they change more often than your software isn’t all that low.</p><p>Second, much like variables in your code, every project has a scope and a lifetime. With this particular project, it was pretty clear that there will be iterations for other clients; even some kind of productized service was being discussed. Had it been a clear one-off, I’d probably have gone the painless way of mix and match of readymade modules, but all the customizations that were already there (like the LRU eviction) would probably have sent me down a configuration rabbit hole, possibly leading to the conclusion that I had to roll my own anyway.</p><p>Clearly, this is all a matter of your own preferences and/or experience. In many projects, you won’t have the time and money to do a custom implementation like this, or quite possibly a client who will not listen to your advice that agglomerating tech debt in the form of unmanaged dependencies will come back to you sooner or later. At the very least, I would take the time and do a thorough investigation of the candidate packages as for their open-source maintenance status.</p><h3>Links</h3><p><a href="https://www.npmjs.com/package/express-asset-file-cache-middleware">https://www.npmjs.com/package/express-asset-file-cache-middleware</a></p><p><a href="https://create-react-app.dev/docs/making-a-progressive-web-app/">https://create-react-app.dev/docs/making-a-progressive-web-app/</a></p><p><a href="https://developers.google.com/web/tools/workbox">https://developers.google.com/web/tools/workbox</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=797232f18ec8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/caching-dynamic-assets-offline-in-electron-apps-797232f18ec8">Cache Dynamic Assets Offline in Electron Apps</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Made My Own Code Quality Tool, Attractor]]></title>
            <link>https://medium.com/better-programming/why-i-made-my-own-code-quality-tool-c44b40ceaafd?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/c44b40ceaafd</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[code-quality-tools]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Mon, 25 Nov 2019 14:07:12 GMT</pubDate>
            <atom:updated>2019-11-28T02:21:08.232Z</atom:updated>
            <content:encoded><![CDATA[<h4>Sometimes, to get what you want, you have to build it yourself</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSApiv-Hc4Ckof1tTKC9Wg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@richardbrutyo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Richard Brutyo</a> on <a href="https://unsplash.com/s/photos/quality?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>I needed a language-agnostic tool, available as a CLI, to investigate refactoring candidates in full-stack codebases.</p><p>Get it here: <a href="https://rubygems.org/gems/attractor">https://rubygems.org/gems/attractor</a>.</p><h3>Introduction</h3><p>Before I start introducing the tool I crafted, and more importantly, <em>why</em> I did so, let me tell you a little bit about my context.</p><p>These days, I’m primarily a full-stack web developer (mostly <a href="https://rubyonrails.org/">Ruby on Rails</a> stuff), but I also do quite an amount of front-end work (mainly React). More often than not, I’m consulted for codebase reviews, refactorings, or pulled in on short notice to compensate short-term demand.</p><p>In all of these roles, I’ve come to realize that I need some tooling to get an overview of the codebase quickly, to address the pain points, and/or find out where the crucial logic of the software lies, to get to grips with it fast.</p><p>Now, let’s switch gears. Many authors (<a href="https://www.agileconnection.com/article/getting-empirical-about-refactoring">Michael Feathers</a>, <a href="https://www.sandimetz.com/blog/2017/9/13/breaking-up-the-behemoth">Sandi Metz</a>, among others) have shown that an evaluation of churn (how often changes occur) vs. complexity of files in software projects provide a valuable metric towards code quality.</p><p>Churn/complexity charts are at the heart of many code quality evaluation tools, including <a href="https://codeclimate.com/">CodeClimate</a>, <a href="https://github.com/whitesmith/rubycritic">RubyCritic</a>, <a href="https://github.com/the-simian/es6-plato/">es6-plato</a>, and others.</p><p>You can read up on the science at the links I provided — I just want to concur with these authors, that surveying the files/classes with the highest churn * complexity product <em>virtually always gives the best leads as to where to poke my nose in first.</em></p><p>So, when all these tools already exist, why build another one?</p><p>First, I don’t believe that just because an idea already has one materialization, no other variant of it should be built. By the same token — and that’s just speaking of the same domain — we’d only need one operating system, one programming language, one editor, one testing framework, etc. — you could continue this list endlessly.</p><p>No, open-source software as such has proven that a variety of tools to choose from is nearly always beneficial for the ecosystem. The community will have to decide whether I have built something valuable.</p><p>And second, as I already hinted at in the introduction, I’m not really satisfied with having to install — and learn — one tool for each of the languages I’m concerned with.</p><p>I’d rather have one single source of truth I can consult about code quality. So, I’ve set out to create a tool that serves mainly two purposes:</p><ol><li>Provide (roughly) the same code quality metrics (along with high-quality visualizations for easy skimming through the codebase) for a multitude of programming languages.</li><li>Make it easily extensible so that anybody who’s interested can provide a Calculator for &lt;fill_in_your_language_of_choice&gt;.</li></ol><h3>Feature Tour</h3><p>I’ll be referring to the live-served version of attractor here, that is, the one you get if you type:</p><pre>$ attractor serve</pre><p>In your console. Most commonly, you will like to give this command a path prefix option -p, to restrict the calculations to a certain directory, such as app/.</p><p>The first thing you’ll be presented with is a churn/complexity chart of the Ruby source in the specified folder, along with some UI filtering options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dY-xNbVchZHg7pI_5auumA.gif" /></figure><p>Initially, the plot is quite minimal, but you can opt-in to display file names and a regression line, if you like. If you’d like to drill further down into the source directory, you can add to the path in a text input box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*heSwZ7C2YnCz0rDzSH9j8Q.gif" /></figure><p>If you click on a dot, you’ll get additional information displayed in the sidebar:</p><ul><li>A method breakdown of the file in question.</li><li>The Git history of the last 10 commits.</li></ul><p>Scrolling down further, you’ll get a list of refactoring candidates, by default the top 95 percentile of the churn * complexity product, but you can also change that percentage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUSnulLOaQiFzq2OE2u-9w.gif" /></figure><p>In addition to the default scatterplot, attractor also features a treemap representation, which visualizes the file &quot;weight&quot; even more radically by dividing the total available area according to the specified metric.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSybkAXB8kVw5xZgrvp-xw.gif" /></figure><p>Which brings me to the final cherry on the cake — the ability to select the metric used — either churn * complexity or each of those separately.</p><p>Since a scatterplot for a single metric doesn’t make any sense, I’ve fallen back to a histogram in those cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q7UheBJLbdEbWl4xSuDdMw.gif" /></figure><p>Finally, as promised, you can expect the exact same features (as was my primary goal) in your JS(X) source files. Neat!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9LSx9iC8AAVHO0yinrTxXA.gif" /></figure><h3>Extensibility — Bring Your Own Calculator</h3><p>I’ve tried to keep the code as modular as possible. Since file churn is language agnostic, all you have to do is implement a calculator, as you can observe in the JS calculator on <a href="https://github.com/julianrubisch/attractor/blob/master/lib/attractor/calculators/js_calculator.rb">GitHub</a>.</p><p>At the moment, all you have to do is provide your file extension in the initializer:</p><pre>def initialize(file_prefix: &#39;&#39;, minimum_churn_count: 3)<br>  super(file_prefix: file_prefix, file_extension: &#39;(js|jsx)&#39;, minimum_churn_count: minimum_churn_count)<br>end</pre><p>And in the calculate method, a change hash is yielded, providing, among other things, access to the file_path of the file under scrutiny.</p><p>The block you supply here is expected to return an array containing two elements:</p><ol><li>The total computed complexity of the file.</li><li>(Optionally) a “details” hash containing method names as keys and their respective complexities as value.</li></ol><p>So, in the case of js_calculator, first, in the Ruby class I overwrote the calculate method like so:</p><pre>def calculate<br>  super do |change|<br>    complexity, details = JSON.parse(`node #{__dir__}/../../../dist/calculator.bundle.js #{Dir.pwd}/#{change[:file_path]}`)</pre><pre>    [complexity, details]<br>  end<br>end</pre><p>And wrote a <a href="https://github.com/julianrubisch/attractor/blob/master/src/javascript/calculator/index.js">node script</a> that provides these values:</p><pre>const report = escomplex.analyzeModule(fs.readFileSync(file).toString());</pre><pre>const details = {};</pre><pre>report.methods.forEach(m =&gt; {<br>  details[m.name] = m.cyclomatic;<br>});</pre><pre>console.log(JSON.stringify([report.aggregate.cyclomatic, details]));</pre><p>That’s probably one of the drawbacks here: You will have to use whatever tooling the target language provides to supply complexity (or other) metrics.</p><p>I’m currently thinking about the architecture to use for supporting different programming languages.</p><p>Probably, I will split it up into multiple modules/gems, but I’ll defer that decision until the demand for more languages arrives.</p><h3>Future Directions</h3><h4>More languages</h4><p>As outlined above, creating a Calculator is actually quite easy, you don&#39;t even need any detailed Ruby knowledge, just a notion of a code quality tool in your preferred language of choice.</p><p>If you have demand for &lt;your_language&gt;, open a <a href="https://github.com/julianrubisch/attractor/issues">Github issue</a> and/or give me a ping.</p><h4>More metrics</h4><p>Two I can think of are automated code smell detection and test coverage. If you have an idea, or would like to contribute, open a <a href="https://github.com/julianrubisch/attractor/issues">Github issue</a> and let’s talk.</p><h4>Alternate visualizations</h4><p>Scatterplots and treemaps are what came to my mind, but maybe there are even more feasible ones? Like <a href="https://www.d3-graph-gallery.com/network.html">network graphs</a>, <a href="https://www.d3-graph-gallery.com/chord.html">chord diagrams</a>, <a href="https://www.d3-graph-gallery.com/arc.html">arc diagrams</a> or what have you. Just ping me with your ideas or open a <a href="https://github.com/julianrubisch/attractor/issues">Github issue</a>.</p><h4>Auto-detection</h4><p>Based on what package files are present in the app’s root directory, it could be auto-detected which complexity calculators to use. There’s already a <a href="https://github.com/julianrubisch/attractor/issues/56">Github issue</a> for this, and will be implemented in a future version.</p><h4>GitHub app</h4><p>Installing Attractor and/or adding it to your project’s Gemfile may not be possible in your case. It is conceivable to create GitHub and/or GitLab integration for such cases, to have a running instance of attractor somewhere in the cloud.</p><p>I&#39;m not sure whether this is of any value at all, since <a href="https://codeclimate.com/">Code Climate</a> already offers a generous free plan. At any rate, if you have demand for something like this, let&#39;s get in contact!</p><h4>Export functionality</h4><p>This might be more realistic — you might have a need to export code quality data, e.g. to track it over time, compare it to other projects, etc. If you have any ideas concerning this, give me a ping!</p><h3>Concluding Thoughts</h3><p>My initial motivation was to scratch my own itch with this project, to get a quick overview of whatever codebase I’m in at the moment. That goal has been only partially reached, since I only implemented what I already knew from other tools.</p><p>But then, I seriously came to believe that this could become a community effort, because maybe interested code aesthetes such as myself could contribute ideas as to how to better parse, process, and visualize source code, let alone what machine learning, clustering algorithms, etc. could bring to light in such an environment.</p><p>So, if you have some high-flying visions of code discoverability in the back of your head, let’s get in touch!</p><h3>Links</h3><ul><li>Download the gem from <a href="https://rubygems.org/gems/attractor">RubyGems</a></li><li>Source code on <a href="https://github.com/julianrubisch/attractor/">github</a></li></ul><h3>Credits</h3><p>Thanks go to:</p><ul><li>Ernesto Tagwerker (<a href="http://twitter.com/etagwerker">@etagwerker</a>) of <a href="https://www.fastruby.io/">fastruby.io</a> for consistently giving feedback and pointers. I feel the two of us are very much on the same page!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c44b40ceaafd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/why-i-made-my-own-code-quality-tool-c44b40ceaafd">Why I Made My Own Code Quality Tool, Attractor</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hooking up Dropzone.js with ActiveStorage DirectUpload]]></title>
            <link>https://medium.com/boiling-plates/hooking-up-dropzone-js-with-activestorage-directupload-c012e3ae6a45?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/c012e3ae6a45</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Sat, 01 Sep 2018 06:55:44 GMT</pubDate>
            <atom:updated>2018-09-05T17:47:53.412Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hooking up Dropzone.js with ActiveStorage DirectUpload via Stimulus.js</h3><p>Recently I was trying to implement a drag‘n‘drop upload solution with Rails ActiveStorage (wired to Amazon S3 internally), but found the <a href="https://edgeguides.rubyonrails.org/active_storage_overview.html#integrating-with-libraries-or-frameworks">docs</a> rather sparse. One other helpful snippet was <a href="https://github.com/rails/rails/issues/32251">this</a>.</p><p>So when I managed to do it, I decided to write up this (my first) github gist. So here it is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff8f931d998f46692773a9b0b3bc4b74/href">https://medium.com/media/ff8f931d998f46692773a9b0b3bc4b74/href</a></iframe><p>Careful, this is only the beginning! As we overwrite Dropzone‘s drop event handler, we have to take care of everything (e.g. error handling) ourselves.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c012e3ae6a45" width="1" height="1" alt=""><hr><p><a href="https://medium.com/boiling-plates/hooking-up-dropzone-js-with-activestorage-directupload-c012e3ae6a45">Hooking up Dropzone.js with ActiveStorage DirectUpload</a> was originally published in <a href="https://medium.com/boiling-plates">Boiling Plates</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Cloud Firestore, Auth, Functions]]></title>
            <link>https://medium.com/@minthesize/firebase-cloud-firestore-auth-functions-ce5df0808eca?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce5df0808eca</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[contentful]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[zapier]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Tue, 22 May 2018 07:26:31 GMT</pubDate>
            <atom:updated>2018-05-22T07:26:31.149Z</atom:updated>
            <content:encoded><![CDATA[<h3>(Semi-)Automating a Video Tutorial Portal with YouTube, Github, Zapier, Contentful and Firebase Functions</h3><p>So I‘ve created this screencast series along with a little portal, called <a href="https://www.znibbl.es/">Znibbles</a>. It is centered around visual programming tools such as MaxMSP, PureData, TouchDesigner, vvvv and the like — my second pillar so to speak.</p><p>However, this post is about how I built a serverless platform using just a few APIs and some automation techniques. In the center of it all lie YouTube and Github as the <em>data model</em> in traditional MVC speak.</p><p>Before we go any further, this is the final product we‘re talking about, a finished episode with video, transcript and link to the source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*2tc5PcaJjvrwiJrHk6-6zg.png" /><figcaption>A Znibble~ video page</figcaption></figure><p>Obviously, I use YouTube to host the videos, along with some metadata such as description and tags. On Github I store the source files pertaining to the examples, as well as the transcripts in Markdown format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*breYiZpzM35Da_a33U8EEA.png" /><figcaption>Video on YouTube</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*thTa-JiLAAq28zp41PbG7g.png" /><figcaption>Transcript on Github</figcaption></figure><h4>Automating Contentful entries with Zapier</h4><p>Services like Zapier and IFTTT, along with webhooks are the epitome of how the Internet has evolved in the last 2 1/2 decades. The original client-server model has been replaced by, or perhaps more correctly <em>disguised</em> by a more decentralized approach.</p><p>Let’s put this into context: My goal was to minimize the effort I have to go through to produce a video as much as possible, since I do it entirely in my spare time. And I‘ve been quite successful: Once the video is ready, everything is triggered automatically with one little exception as we will see. And I like to view that exception as a little quality check on my side.</p><h4>There‘s a Zap for that.</h4><p>It starts with a Zapier hook that is launched once a video is published on my channel. It turns out that there is already a template zap for that case (there is one for almost every API-to-API connection), and it’s pretty simple to link it to Contentful to draft an entry:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*ghv34ZTLmVSnTu2UxhESNw.png" /><figcaption>Defining the Entry Template</figcaption></figure><p>So when I publish the above video, I get a Contentful entry that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*ScromqmRczNoj32GsIMKLA.png" /><figcaption>The unprocessed Contentful entry</figcaption></figure><p>Pretty neat, but something is still missing (the transcript), some data still needs transformation and the entry has to be connected to a playlist.</p><h4>Glueing everything together with webhooks and Firebase functions</h4><p>I use Firebase to store user data, downloads and perform authentication anyway, so using Firebase Cloud Functions to glue together transcripts and entries, and perform some transformations felt pretty natural.</p><p>We can expose a function to a public URL if we use the https module:</p><pre>exports.convertContentfulVideo = functions.https.onRequest((req, res) =&gt; {<br>    if (!req.headers.authorization || req.headers.authorization !== `Basic ${functions.config().basic_auth.password}`) {<br><br>    res.sendStatus(403);<br><br>  } else {<br>      // ...<br>  }<br>}</pre><p>We first check if it’s an authorized request. We do so by checking the Basic Auth header against a password stored in the firebase env variables.</p><p>Setting those is pretty easy:</p><pre>&gt; firebase functions:config:set basic_auth.password=&quot;&lt;base64-encoded-string&gt;&quot;</pre><p>Afterwards you can access it like shown above. In the else branch we then do our actual work:</p><p>First we need to manually parse the request, because Contentful sends a funny Content-Type (not application/json)</p><pre>const parsedEntry = JSON.parse(req.rawBody.toString(&#39;utf-8&#39;));</pre><p>After a guard clause to ensure we have a video entry in our hands which is yet unprocessed, we fetch a reference to the entry and use it to fetch the transcript from Github. I use a specially formatted title and split it into playlist and video titles to achieve this. True, I introduce a tight coupling here, but for a MVP, it seems alright to go with it for a while:</p><pre>let contentfulEntry;<br>if (parsedEntry.sys.contentType.sys.id === &#39;video&#39; &amp;&amp; parsedEntry.fields.transcript === undefined) {<br>  const id = parsedEntry.sys.id;<br><br>  client.getSpace(functions.config().contentful.space_id)<br>    .then((space) =&gt; space.getEntry(id))<br>    .then((entry) =&gt; {<br><br>      contentfulEntry = entry;<br><br>      const title = entry.fields.title[&#39;en-US&#39;];<br>      const transcriptURL = `https://raw.githubusercontent.com/znibbles/${parameterize(title.split(&#39;|&#39;)[0].trim().toLowerCase())}/master/transcripts/${parameterize(title.split(&#39;|&#39;)[1].trim().toLowerCase())}.md`;<br><br>      return fetch(transcriptURL);<br>    })</pre><p>After we have our transcript, we go on in our promise chain to format the duration, which originally comes in ISO-8601 format, into a human readable format, and shorten the title:</p><pre>.then(res =&gt; res.text())<br>    .then(transcript =&gt; {<br><br>      const durationISO8601 = contentfulEntry.fields.duration[&#39;en-US&#39;];<br><br>      contentfulEntry.fields.duration[&#39;en-US&#39;] = moment.utc(moment.duration(durationISO8601).asMilliseconds()).format(&#39;mm:ss&#39;);<br>      contentfulEntry.fields.transcript = {<br>        &#39;en-US&#39;: transcript<br>      };<br>      contentfulEntry.fields.title[&#39;en-US&#39;] = contentfulEntry.fields.title[&#39;en-US&#39;].split(&#39;|&#39;)[1].trim();<br><br>      return contentfulEntry.update();<br>    })</pre><p>Afterwards we re-publish the entry and call it a day:</p><pre>.then(entry =&gt; entry.publish())<br>    .then(entry =&gt; res.sendStatus(200))<br>    .catch(reason =&gt; {<br>      console.error(reason);<br>      return res.sendStatus(500);<br>    });<br><br>} else {<br>  console.log(&#39;no video or already processed&#39;);<br>  res.sendStatus(422);<br>}</pre><p>To trigger this function, we register a webhook on Contentful which launches it once an entry is published</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*s9Zlt05cooNWu83WQkyz4w.png" /><figcaption>Webhook definition</figcaption></figure><p>Afterwards, I get the transcript in place:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*eslO2LrFFaZchh6S30DNxA.png" /></figure><p>And the duration converted:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*6NZMPVOzBy7StH4BphcVog.png" /></figure><h4>Summing Up</h4><p>So the process of publishing as it stands consists of the following steps:</p><ol><li>Publish a video to YouTube using a specially formatted title</li><li>Edit the Contentful entry drafted by Zapier: Attach it to a playlist. This is the one step that has to be done manually, as mentioned above. Since I publish a video only once in a week or two, I find this acceptable and use it as a quality assurance on my side.</li><li>Click publish and see the magic happen.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce5df0808eca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Contentful Next JS]]></title>
            <link>https://medium.com/boiling-plates/contentful-next-js-d0a7f787b04?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0a7f787b04</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[contentful]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Fri, 11 May 2018 14:24:16 GMT</pubDate>
            <atom:updated>2018-05-11T15:58:38.661Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Portal with Contentful and Next.js on now.sh</h3><p>I admit, I have done websites. The WordPress way. Clients expecting a — decent, but nonetheless — blogging framework to behave like a customizable online publication, media storage/streaming service and/or fully-featured CRM. Over the time it became so frustrating to patch and twist WordPress with plugins to somehow enable that one desired functionality that I’ve avoided doing websites as much as I could. Plus, the always looming security flaws, backup and restore concerns, tedious migrations etc.</p><p>I was not aware of, or at least didn’t consider, the fact that there are <strong>headless, cloud-first CMS’s</strong> like <a href="https://www.contentful.com/">Contentful</a> out there. When I first learned about it, I hesitated because of the rather ambitious pricing model. <a href="https://www.contentful.com/pricing/">39$</a> for a rather small set-up, that sounded adventurous. But the more I read about the benefits, such as</p><ul><li>fully customizing your content model, from defining <strong>associations</strong> between types down to performing <strong>validations</strong> on single fields,</li><li>ready-to-go <strong>development kits</strong> for almost every relevant platform,</li><li>state-of-the-art <strong>caching</strong>,</li><li>easy to use <strong>webhooks</strong>,</li><li>etc…</li></ul><p>the platform intrigued me more and more. After all, you could incorporate your whole site into a static website, scaling down hosting costs to the very minimum possible. You could as well build multiple front-ends, manage entries and assets via a CLI, and so on.</p><h4>What about my WordPress templates?</h4><p>Scratch them. True, there are a ton of them to choose from out there. But very few of them actually work well on mobile devices, let alone allow customization in a way that will satisfy every need. There will always be a major trade-off in such an environment.</p><p>Now I’m not saying that this setup is for everyone. If your local grocery store comes asking for a website, you’d probably sell him a WordPress site (if you’re that type of person), or, more ethically correct, recommend him to just go with a Facebook page.</p><p>But the type of projects/web frontends I’m occupied with mostly at the moment have a content model that is so far away from the usual pages/categories/tags/posts approach that I embraced Contentful and have been very happy with it since then. And with modern HTML frontend frameworks like Bootstrap, it’s just as easy to create your own templates from scratch, and you got full flexibility instead of a few hooks the theme designer allows for you.</p><h4>Let’s get our hands dirty.</h4><p>Disclaimer: The rest of the article is even more opinionated than the start :)</p><p>So I’ve pondered what kind of set-up would make sense and in the end came up with an <strong>isomorphic javascript</strong> one. When I say that, I typically provoke one of two types of reaction:</p><ul><li>scoffing, or</li><li>cheering.</li></ul><p>To be honest, I most of the time am rather indifferent towards technology. I weigh the pros against the cons and choose what suits my business case best. True, that way I seldom reach true virtuosity, but the inverse is also dangerous: If all you know is a hammer, everything starts looking like a nail.</p><p>Since I had some prior React programming experience (and a <a href="https://zeit.co/now">now.sh</a> account), I chose <a href="https://github.com/zeit/next.js/">next.js</a> as a framework. What I generally like about Zeit’s projects is their minimalistic approach to everything, and it is the same with next.js. Compared to create-react-app the use case is pretty slim: Server-rendered React-powered <strong>sites</strong>. I wouldn&#39;t even go so far and say <strong>applications</strong> are their primary target. No need for routers, state containers out of the box, you build your site navigation with &lt;Link&gt; tags and have that magical /pages directory that will be mounted on the root of your app. Every React component you put in there will correspond to a route, so /pages/event.js will be accessible via /event/, etc.</p><p>There is also a /static folder that will hold your assets, but that&#39;s about it. Very opinionated, but you get</p><ul><li>automatic code splitting,</li><li>additional lifecycle methods for server-side data fetching</li><li>page prefetching</li><li>dynamic imports</li><li>and more…</li></ul><p>Again, the tight scaffold that next puts on your app will only fit a tiny percentage of use cases. But for this one, and for me, it was an almost perfect fit. And partially, I have to admit, that is due to the fact that with next, there is no need to separate client from server side code. Less possible breaking points, less boilerplate code, more development speed that means for me.</p><h4>Pulling in the Boiling Plate</h4><p>After a successful project launch like this, I sometimes take a step back and reduce everything to a <a href="https://github.com/julianrubisch/contentful-nextjs-now-boilerplate">boilerplate</a> (hence the publication title). I also write things up so I don’t forget them. And as a few colleagues have pointed out to me, others may find this useful, too. So yes, this is yet another TIL blog… please excuse my mediocrity :)</p><h4>Basic next.js</h4><p>So let’s dissect this one piece at a time. We start with our dependencies, and review our package.json. The relevant parts for the next.js setup are:</p><pre>{<br>    &quot;scripts&quot;: {<br>        &quot;dev&quot;: &quot;node server.js&quot;,<br>        &quot;build&quot;: &quot;next build&quot;,<br>        &quot;start&quot;: &quot;NODE_ENV=production node server.js&quot;<br>    },<br>    ...<br>    &quot;dependencies&quot;: {<br>        &quot;express&quot;: &quot;^4.16.3&quot;,<br>        ...<br>        &quot;next&quot;: &quot;^5.1.0&quot;,<br>        &quot;react&quot;: &quot;^16.3.1&quot;,<br>        &quot;react-dom&quot;: &quot;^16.3.1&quot;,<br>    }<br>}</pre><p>We’ll get to investigating why express is needed here later, but the main three packages are next, react, and react-dom, that&#39;s it. Let&#39;s just add an index page for now, and put it in /pages:</p><pre>const Index = () =&gt; (<br>  &lt;div style={{width: 640, maxWidth: &#39;100%&#39;, margin: &#39;auto&#39;}}&gt;<br>    &lt;h1&gt;Hello from Next&lt;/h1&gt;<br>    &lt;img src=&quot;static/boiling_plates.svg&quot; /&gt;<br>  &lt;/div&gt;<br>);<br><br>export default Index;</pre><p>Let’s install the packages, hit npm run dev and see what we get (note: I&#39;m using node v8.9.4 for this walkthrough). Navigate to <a href="http://localhost:3000/">http://localhost:3000</a> and you should get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3du_08VZMcBcYk77KV-A2w.png" /><figcaption>Initial index.js</figcaption></figure><p>Hey! Looks like we’re done. No, seriously. We want a cool, responsive look and feel, right? Let’s bootstrap it.</p><h4>Bootstrap 4</h4><p>This needs a little setup. First, some additional entries to our package.json:</p><pre>{   <br>    ...<br>    &quot;dependencies&quot;: {<br>        &quot;autoprefixer&quot;: &quot;^8.2.0&quot;,<br>        &quot;bootstrap&quot;: &quot;^4.0.0&quot;,<br>        &quot;jquery&quot;: &quot;^3.3.1&quot;,<br>        &quot;node-sass&quot;: &quot;^4.8.3&quot;,<br>        &quot;popper.js&quot;: &quot;^1.14.3&quot;,<br>        &quot;postcss-easy-import&quot;: &quot;^3.0.0&quot;,<br>        &quot;postcss-loader&quot;: &quot;^2.1.3&quot;,<br>        &quot;raw-loader&quot;: &quot;^0.5.1&quot;,<br>        &quot;sass-loader&quot;: &quot;^6.0.7&quot;<br>    }<br>}</pre><p>Let’s see. jQuery and popper.js are required by Bootstrap, so that’s that. In next.js.config, which is a sort of next-flavoured webpack.config.js, we configure the loading of SCSS files like so:</p><pre>...<br>{<br>    test: /\.s(a|c)ss$/,<br>    use: [&#39;raw-loader&#39;, &#39;postcss-loader&#39;,<br>      { loader: &#39;sass-loader&#39;,<br>        options: {<br>          includePaths: [&#39;styles&#39;, &#39;node_modules&#39;]<br>            .map((d) =&gt; path.join(__dirname, d))<br>            .map((g) =&gt; glob.sync(g))<br>            .reduce((a, c) =&gt; a.concat(c), [])<br>        }<br>      }<br>    ]<br>}<br>...</pre><p>So that explains the use of <a href="https://webpack.js.org/loaders/raw-loader/">raw-loader</a> and <a href="https://webpack.js.org/loaders/postcss-loader/">postcss-loader</a>: SCSS files are loaded and afterwards processed by postcss. So let&#39;s look at that config next:</p><pre>module.exports = {<br>    plugins: [<br>          require(&#39;postcss-easy-import&#39;)({prefix: &#39;_&#39;}),      <br>          require(&#39;autoprefixer&#39;)({ /* ...options */ })<br>    ]<br>  }</pre><p>(postcss.config.js)</p><p>We use it to autoprefix our stylesheets <em>and</em> the imports too (hence the ‘_’ prefix: load imports partial-style).</p><p>Afterwards <a href="https://webpack.js.org/loaders/sass-loader/">sass-loader</a> will do the the magic on our SCSS and concatenate it.</p><p>Now, for the Bootstrap part we also need to push in the ProvidePlugin as per the docs:</p><pre>config.plugins.push(<br>  new webpack.ProvidePlugin({<br>    $: &#39;jquery&#39;,<br>    jQuery: &#39;jquery&#39;,<br>    &#39;window.jQuery&#39;: &#39;jquery&#39;,<br>    Popper: [&#39;popper.js&#39;, &#39;default&#39;],<br>   }),<br>);</pre><p>So how do we get the stylesheet into our page? This is what it looks like (index.scss), pretty unexciting :)</p><pre>@import &quot;~bootstrap/scss/bootstrap&quot;;</pre><p>First, let’s create a folder called /components (can be called anything, really) and create a layout.js component.</p><p>It seems like the preferred way to load CSS in Next is to more or less copy-and-paste it into a &lt;Head&gt; section, css-in-js-style:</p><pre>import stylesheet from &#39;../styles/index.scss&#39;;<br>// ...<br>&lt;Head&gt;<br>  &lt;title&gt;Next / Contentful / Bootstrap 4 Boilerplate&lt;/title&gt;<br>  &lt;meta charSet=&quot;utf-8&quot; /&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot; /&gt;<br>  &lt;style dangerouslySetInnerHTML={{ __html: stylesheet }} /&gt;      <br>&lt;/Head&gt;</pre><p>No minifying here. I’m pretty sure there’s ways to optimize that, but I’ll leave it at that for now.</p><p>To complete the Bootstrap setup, we need the javascript as well, yes? This was the trickiest part to figure out. Because of the server-side-rendering, we need to put the initialization into the componentDidMount React lifecycle hook:</p><pre>componentDidMount() {<br>    window.$ = window.jQuery = require(&#39;jquery&#39;);<br>    require(&#39;bootstrap&#39;);<br>  }</pre><p>That part is only executed when the markup is ready, client side. So let’s add some text and bootstrap utility classes, wrap the Index page in our Layout, and refresh the dev server:</p><pre>&lt;Layout&gt;<br>    &lt;div className=&quot;text-center&quot;&gt;<br>      &lt;h1&gt;Hello from Next&lt;/h1&gt;<br>      &lt;p <em>className</em>=&quot;lead&quot;&gt;Lorem ipsum... yeah whatever...&lt;/p&gt;<br>      &lt;img className=&quot;img-fluid w-75 mt-4&quot; src=&quot;static/boiling_plates.svg&quot; /&gt;<br>    &lt;/div&gt;<br>  &lt;/Layout&gt;</pre><p>This is what we get, Bootstrap seems to work fine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5EtYKl-4I2rn_DE1hHYyw.png" /></figure><h4>Making it Contentful</h4><p>I’m not going to go through the whole Contentful UI and setup procedure here, please <a href="https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/">refer to the docs</a> :)</p><p>I’ll instead guide you into how to set up a Contentful client in this environment. First, npm i --save contentful and make a .env file with your credentials and Space ID:</p><pre>CTF_SPACE_ID=&lt;your space id&gt;<br>CTF_CDA_TOKEN=&lt;your CDA token&gt;<br>CTF_CPA_TOKEN=&lt;your CPA token&gt;</pre><p>We are going to need the dotenv npm module for that: npm i --save dotenv and load it in next.config.js:</p><pre>require(&#39;dotenv&#39;).config();</pre><p>That will make our environment variables accessible via process.env. Now also load in the EnvironmentPlugin in the same file:</p><pre>config.plugins.push(<br>  new webpack.EnvironmentPlugin(process.env),<br>    //...<br>    )</pre><p>That will make those variables available at compile time! Now we can reference them in our code, e.g. in the common/contentful.js file:</p><pre>const contentful = require(&#39;contentful&#39;);<br><br>const defaultConfig = {<br>  CTF_SPACE_ID: process.env.CTF_SPACE_ID,<br>  CTF_CDA_TOKEN: process.env.CTF_CDA_TOKEN,<br>  CTF_CPA_TOKEN: process.env.CTF_CPA_TOKEN<br>};<br><br>module.exports = {<br>  createClient (config = defaultConfig) {<br>    const options = {<br>      host: &#39;preview.contentful.com&#39;,<br>      space: config.CTF_SPACE_ID,<br>      accessToken: config.CTF_CPA_TOKEN<br>    };    <br><br>    if(process.env.NODE_ENV === &#39;production&#39; &amp;&amp; !process.env.STAGING) {<br>      options.host = &#39;cdn.contentful.com&#39;;<br>      options.accessToken = config.CTF_CDA_TOKEN;<br>    }<br><br>    return contentful.createClient(options);<br>  }<br>};</pre><p>The purpose of that file is to provide a factory method that will configure your Contentful client according to whether you are in the development or production environment, or, in our case, a custom STAGING environment, which I find useful. The switch we make here is as to whether we use the Delivery API (production) or Preview API (development, staging), which will also include unpublished entries.</p><p>Let’s now pretend that we are already going to load some Contentful data in our index page. We have to import the factory method we just made up:</p><pre>import { createClient } from &#39;../common/contentful&#39;;<br><br>//...<br><br>Index.getInitialProps = async () =&gt; {<br>  const client = createClient();<br><br>  const entries = await client.getEntries({<br>    // some query<br>  });<br>  <br>  return { someEntryAsProp: entries.items[0] };<br>};</pre><p>Later in that class, we call getInitialProps, thats a lifecycle method nextjs adds to our React class. We can use async code here, and simply fetch some entries from Contentful, and pass them via props. In our render method, that&#39;d be available as a prop then:</p><pre>//...<br><br>&lt;Layout&gt;<br>    &lt;div className=&quot;text-center&quot;&gt;    <br>      &lt;h1&gt;Hello from Next&lt;/h1&gt;<br>      &lt;p&gt;{someEntryAsProp.fields.text}&lt;/p&gt; // &lt;-- HERE<br>      &lt;img className=&quot;img-fluid w-75 mt-4&quot; src=&quot;static/boiling_plates.svg&quot; /&gt;<br>    &lt;/div&gt;<br>&lt;/Layout&gt;<br>  <br>//...</pre><p>And that’s about it. Now we can perform arbitrary queries on the Contentful backend and fetch our content, either on the server side via getInitialProps, or on the client side if we do so in componentDidMount.</p><h4>Server.js</h4><p>Now a side note on that Express server.js hiding in our root directory. A detailed explanation of nextjs is also beyond the scope of this article (it&#39;s already pretty lengthy :)) - if your interested, look <a href="https://learnnextjs.com/basics/getting-started">here</a>. It turns out that next is very smart, but not smart enough to guess your route masking. What do I mean by that?</p><p>In next, you could declare a link like that:</p><pre>&lt;Link as={`/a/${props.id}`} href={`/article?id=${props.id}`}&gt;<br>    &lt;a&gt;{props.title}&lt;/a&gt;<br>&lt;/Link&gt;</pre><p>And that would work (it’d give you clean URLs of type /a/my-awesome-article) as long as navigation takes place on the client side, because next does some magic with your browser history (pushState etc.).</p><p>However, if you <em>refresh</em> your browser window after navigating to that route, that would lead to a 404. So in the server.js there is this route, a translation of the shortened URL to the correct <strong>page</strong> in the /pages directory and append the id in a query string.</p><pre>server.get(&#39;/a/:id&#39;, (req, res) =&gt; {<br>  const actualPage = &#39;/article&#39;;<br>  const queryParams = { id: req.params.id };<br>  app.render(req, res, actualPage, queryParams);<br>});</pre><h4>Deploy it to Now</h4><p>That part is the easiest of all. Because both next and now are Zeit projects, it should be, no?</p><p>Turns out now will deploy anything that has a npm build and a npm start script, basically. The only thing we have to take care of, are our project secrets. In now, that&#39;s pretty easy to handle. We declare them in our console:</p><pre>&gt; now secrets add ctf_space_id &quot;my_value&quot;<br>&gt; now secrets add ctf_cda_token &quot;my_value&quot;<br>&gt; now secrets add ctf_cpa_token &quot;my_value&quot;</pre><p>And reference them in our now.json:</p><pre>{<br>  &quot;env&quot;: {<br>    &quot;CTF_SPACE_ID&quot;: &quot;@ctf_space_id&quot;,<br>    &quot;CTF_CDA_TOKEN&quot;: &quot;@ctf_cda_token&quot;,<br>    &quot;CTF_CPA_TOKEN&quot;: &quot;@ctf_cpa_token&quot;<br>  }<br>}</pre><p>That’s it. Deploy to our staging environment by additionally specifying the STAGING environment variable:</p><pre>&gt; now -e STAGING=1</pre><p>and finally to production:</p><pre>&gt; now</pre><p>Find the actual boilerplate <a href="https://github.com/julianrubisch/contentful-nextjs-now-boilerplate">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0a7f787b04" width="1" height="1" alt=""><hr><p><a href="https://medium.com/boiling-plates/contentful-next-js-d0a7f787b04">Contentful Next JS</a> was originally published in <a href="https://medium.com/boiling-plates">Boiling Plates</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Creative Musical Instruments — Part 1- Introduction]]></title>
            <link>https://medium.com/@minthesize/designing-creative-musical-instruments-part-1-introduction-7f755b722fb3?source=rss-472d3f7a0fed------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f755b722fb3</guid>
            <category><![CDATA[interaction-design]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[creativity]]></category>
            <dc:creator><![CDATA[Julian Rubisch]]></dc:creator>
            <pubDate>Fri, 23 Mar 2018 09:00:45 GMT</pubDate>
            <atom:updated>2018-03-26T07:26:03.075Z</atom:updated>
            <content:encoded><![CDATA[<h3>Designing Creative Musical Instruments — Part 1: Introduction</h3><p>A while ago I did a little research about the features and interaction patterns that make some musical instruments appear more creativity-boosting than others. In other words, why is, or was, a piano more often chosen to write a symphony on than, say, an oboe? (I‘m gracefully assuming this is true for the sake of argument, I admit I have no numbers backing this statement)</p><p>I‘m trying to condense my 2015 thesis „Designing Creative Electro-Acoustic Instruments“ into a few blog posts, in the hope that someone may find this useful.</p><h4>The premise</h4><p>So, what is the motivation for this research, what pain points does it try to address, what is the need it fulfills?</p><p>Following my musical composition and performance practice, I arrived at the conviction that the interaction patterns / interface an instrument displays directly shape how creative you are able to be with it. What do I mean by that? How is that quantifiable? To a degree, it is, as it turns out.</p><p>Creativity theory identifies (at least) 4 factors which can be taken into account for measuring what is called <em>divergent thinking</em> (cf <a href="https://en.m.wikipedia.org/wiki/Torrance_Tests_of_Creative_Thinking">TTOC</a>):</p><ul><li><strong>Fluency</strong>: the ability, given a certain problem, to produce a <em>large number</em> of ideas.</li><li><strong>Flexibility</strong>: the ability to produce ideas of <em>many different categories</em>.</li><li><strong>Originality</strong>: counts <em>novel</em> ideas, i.e. compared to a comparison group. (Note that M. Boden (2003) distinguishes between historically and personally original ideas)</li><li><strong>Elaboration</strong>: the amount of detail associated with each idea.</li></ul><p>To arrive at relevant conclusions we need to consider phenomenology, interaction design and user experience of musical instruments, as well as creativity theory.</p><h4>Phenomenology of Human-Technology Relations</h4><p>In his seminal work on a phenomenology of technology, Don Ihde (1990) distinguishes between a few distinct human-technology relations, three of which are relevant for this discussion:</p><h4>Embodied Relations</h4><p>characterised by a quasi-fusion of user and technology, postulating a perceptual transparency, or withdrawal of the tool from consciousness.</p><p>A simple example can be found in optics: Eyeglasses enhance the wearer’s bodily capabilities while staying almost literally <em>transparent</em> and unnoticed, enabling her to see the world <em>through</em> the instrument.</p><p>In many acoustic instruments, especially those amplifying the human vocal capacities, such as wind instruments, this relationship can also be found. The technology disappears, but the nature of the subject-technology relation remains opaque: If the tool breaks, the relationship (the <em>black box</em>) becomes apparent and forces the user to focus on the tool rather than on its use.</p><h4>Hermeneutic Relations</h4><p>require the user to take interpretive action, i.e. to read the technology in some way. The terminus of perception is the instrument or what it displays to the user.</p><p>Now the technology-world relation becomes transparent: Reading a written text, one effortlessly exchanges letters for words and words for concepts of the referred-to worldly objects.</p><p>Similarly, on a piano keyboard, technically speaking there is no perceptual isomorphism between the position of the keys and the produced frequency, as is the case with a guitar fretboard. The isomorphism has become <em>representational</em>: One has to be able to <em>read</em> the abstract convention of the piano’s keys in order to produce the correct frequencies.</p><p>Here, the location of the <em>black box</em> is the technology-world connection — without a deep knowledge of the instrument, the relationship of key to frequency remains opaque.</p><h4>Alterity Relations</h4><p>refer to how humans relate <em>to or with</em> a technology, rather than experience the world <em>through</em> it.</p><p>The focal attention lies on the quasi-other (e.g. an automobile), an entity which is attributed objectness, i.e. a foreground quality as compared to the other relations, where technology is but an artefact to mediate a part of the world.</p><p>The technology itself becomes the perceptual terminus — there may, but need not be a relation to the world. Certain toys or computer games serve as a fitting example here: They refer, if at all, to an imaginary world and can exhibit quasi-animated behaviour, turning them into objects of fascination.</p><p>Computers as meta-machines come to mind, more often than not becoming objects of emotional focus, embracing or condemning the idiosyncrasies they exhibit.</p><p>Developing this line of argument further, I will contend that the most creatively exciting musical technologies lie on the continuum between hermeneutic and alterity relations, and that embodiment plays a minor, if not counterproductive role here.</p><h4>The Role(s) of Electro-Acoustic and Computer Music Technology</h4><p>The majority of music is unconceivable without the use of tools or technology. Indeed, since ancient times instruments have been employed to produce music, and have undergone a continuous evolution since then.</p><p>Obviously, electro-acoustic music is one of the more recent developments in the long tradition of instrument use. With the advent of recording technologies, what Ihde calls <em>multistable development trajectories </em>(i.e., different branches of art and technology forming from a common root, cf Schaeffer and the empiristic school of Musique Concrete vs. Stockhausen and the abstract, deterministic school of Elektronische Musik vs. Cage and his stochastic experiments) were already predetermined, the path to sampling and sound synthesis technologies laid out.</p><p>Pierre Schaeffer (1977) was one of the first to extend the definition of musical instruments for modern electro-acoustic technology, first analysing the patterns of traditional ones. He identified two main components:</p><ul><li><strong>permanence</strong> of characteristics (e.g. timbre), and</li><li><strong>variations</strong> of values, such as abstract concepts (pitch, intensity, what he called „registers“) and concretization of personal playing potential (style, expressivity, imprecision)</li></ul><p>Decades before we had to deal with the technical perfection of digital instruments (read: computers) and the thereby caused detriment of artistic expression, he identified the confusion thus brought about by a lack of balance of timbre, registers and playing potential.</p><h4>Preparing the Research</h4><p>Technologies are never completely neutral. The ideas and concepts of the instrument designers are bound to affect the creative process and compositional ideas themselves.</p><p>Of course, in many ways can the designed way of using it be transformed and boycotted (think Sachiko M, Christian Marclay, …), but even then, one could say, this abuse results from negating deliberate (or accidental) design decisions. Thus, music technology always tends towards an expressive closure by design.</p><p>While this holds true for all technologies, computers are even more predestined to prescribe human thinking and streamline creativity by automating work processes and cognitive offloading. Moreover, the rule-based systems that digital instruments are, inevitably lead to a decrease in expressivity; the focus on the tool’s parameters and inner workings, and the reciprocal detachment from the action’s terminus — the produced sound — result in a certain disruption of flow.</p><p>Additionally, as will be elaborated on below, musical instruments should also encompass the negative dimension of expression, error and bad playing, which is also often neutralised by overly rule-structured machines.</p><p>Hence, we need to closely survey the conditions that challenge users of music technology to develop their creative goals within the boundaries predefined by the instrument creator, while simultaneously yielding an optimum of expressivity.</p><p>Originally posted on <a href="https://www.julianrubisch.at/stew/2018/03/24/designing-creative-musical-instruments-part-1-introduction.html">www.julianrubisch.at</a>.</p><h4>References</h4><p>Boden, M. A. (2003). The Creative Mind: Myths and Mechanisms London ; New York: Routledge Chapman &amp; Hall.</p><p>Ihde, D. (1990). Technology and the Lifeworld: From Garden to Earth. Bloomington: Indiana University Press.</p><p>Magnusson, T. (2009). Of Epistemic Tools: Musical Instruments as Cognitive Extensions. Organised Sound, 14(02), 168–176.</p><p>Magnusson, T. (2010b). Designing constraints: Composing and performing with digital musical systems. Computer Music Journal, 34(4), 62–73.</p><p>Schaeffer, P. (1977). Traité des objets musicaux: essai interdisciplines. Éditions du Seuil.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f755b722fb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>