<?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 Peter Ullrich on Medium]]></title>
        <description><![CDATA[Stories by Peter Ullrich on Medium]]></description>
        <link>https://medium.com/@peterullrich?source=rss-788c254a08a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*SxWUaiM6PBFbZR-UfM9lMg.jpeg</url>
            <title>Stories by Peter Ullrich on Medium</title>
            <link>https://medium.com/@peterullrich?source=rss-788c254a08a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:30:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peterullrich/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[Your product is not only your “product”]]></title>
            <link>https://peterullrich.medium.com/your-product-is-not-only-your-product-c0e1ecdbe1e7?source=rss-788c254a08a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e1ecdbe1e7</guid>
            <category><![CDATA[technical-debt]]></category>
            <category><![CDATA[planning]]></category>
            <category><![CDATA[scrum]]></category>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[refinement]]></category>
            <dc:creator><![CDATA[Peter Ullrich]]></dc:creator>
            <pubDate>Tue, 06 Apr 2021 13:15:57 GMT</pubDate>
            <atom:updated>2021-04-06T13:15:57.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*we5OGJGhRI_Mj0go" /><figcaption>Photo by <a href="https://unsplash.com/@kitera?utm_source=medium&amp;utm_medium=referral">Kitera Dent</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>What comes to mind when you describe “your product”? Do you think about features built for your customers? How it solves a problem your customers have? Maybe even a logo, a slogan, or its theme color?</p><p>These aspects describe your product’s business side and <a href="https://www.investopedia.com/terms/v/valueproposition.asp">value proposition</a>. However, they fail to mention the foundation of your product: <strong>its software</strong>.</p><p>The reason you might have forgotten about the software part lies in the fact that product development tends to revolve around the central question:</p><blockquote>Which feature should we build next?</blockquote><p>Answering this question is undoubtedly a critical step in product development. It justifies the need for a product and its development and is the bedrock of job security for everyone involved. Therefore, the most attention and perceived value lie on the business side of the product. Unfortunately, this causes the software and its maintenance to become nothing more than a by-product.</p><p>Think about the last time you worked on a purely technical ticket, the last time you spend most of a sprint cleaning up the codebase or restructuring your architecture. In short: Paying off your <a href="https://martinfowler.com/bliki/TechnicalDebt.html">technical debt</a>. If you did this just recently: Good for you. I mean it. If not: This is sadly more common than you might think, and it is a problem.</p><p>Ignoring the technical side of a product means neglecting its foundation, and the risk of an eventual collapse increases. The demise might start with a loss in agility or development speed. The pace with which you build new features will slow until it comes to a screeching halt. Bugs will occur more often and will become more severe until you spend most of your time fire fighting. Your stakeholders will become first concerned, then annoyed, and eventually: angry. Your once-happy customers will become less so and eventually will leave if they can.</p><p>If you want to avoid this scenario, you have to start including the technical side into the definition of “your product”. In other industries, this is already common practice. Think about what makes a car a <em>good</em> car. It probably will be its engine and other mechanical parts, which allow its low maintenance, low consumption, and that it doesn’t break down, ever. Carmakers know this and focus actively on maintaining and improving the technical side of their product as well. We need to adopt this perspective in software development too. The first step in this direction is to realise that:</p><blockquote>Your product is not only your “product”</blockquote><p>“Your product” is not only a set of features and the problem it solves. It also includes its codebase, its architecture, its dependencies, and its technical debt. Once you acknowledge this, you need to adapt your workflow to incorporate this shift of perspective. Here are a few tips:</p><p>1. Minimise piggybacking tasks to reduce your technical debt on feature tickets. Don’t make technical work like “<em>clean up the codebase”</em> part of developing new features.</p><p>2. Move technical work to purely technical tickets like “<em>tasks”</em> or “<em>chores”</em>. Estimate and prioritise these tickets in your backlog. Don’t make them inferior to feature tickets. Technical and feature tickets are equals from now on.</p><p>3. Plan your sprint with both technical and feature tickets. You decide about their ratio, but don’t hesitate to have purely technical sprints if you feel like the technical debt overwhelms you.</p><p>4. Consider adding a timebox to every sprint for technical tasks that are too small for their own ticket.</p><p>The depreciation of technical work has led to many battles between “business” and “technical” people. Typically, developers try to get a time or financial budget for reducing the technical debt, but the “business people” reject them since they don’t see the value in such work. I hope that this opinion piece convinced you to change your perspective on this issue.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e1ecdbe1e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up reoccurring jobs with GitHub Actions]]></title>
            <link>https://peterullrich.medium.com/how-to-set-up-reoccurring-jobs-with-github-actions-ce522358326b?source=rss-788c254a08a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce522358326b</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[background-jobs]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Peter Ullrich]]></dc:creator>
            <pubDate>Tue, 26 May 2020 15:01:57 GMT</pubDate>
            <atom:updated>2020-05-26T15:01:57.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oinhUQnjrOlksCeb" /><figcaption>Photo by <a href="https://unsplash.com/@bradneathery?utm_source=medium&amp;utm_medium=referral">Brad Neathery</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In a personal project of mine, I regularly fetched data collected by bicycle counting stations scattered around Cologne, Germany, and stored the data in a public <a href="https://github.com/PJUllrich/Dauerzaehlstellen-Koeln/">GitHub repository</a>. I ran the Python script which was fetching, appending, and uploading the data to GitHub manually for a while, but since I (am lazy and) wanted to always offer the latest data, I thought about how I could automate this process. Here’s how I accomplished running the reoccurring process with GitHub Actions.</p><p>At first, I thought about using the popular <a href="https://github.com/sorentwo/oban">Oban</a> library written in Elixir to run a reoccurring job, but every time the job would have been run, I would have to clone the repository, fetch the data, commit the changes and push everything to GitHub using a personal access token. Since I could not use git commands directly from Elixir, I would also have to use a wrapper library like <a href="https://github.com/elixir-git/xgit">Xgit</a>. This seemed way too complicated and the friendly Elixir community <a href="https://elixirforum.com/t/how-to-update-a-github-repo-daily/31798/3?u=pjullrich">pointed me</a> towards using scheduled GitHub Actions.</p><p>In short: GitHub Actions are jobs, scripts, or routines which GitHub runs for you whenever a predefined event occurs. Most people use GitHub Actions to automate their Continuous Integration (CI) pipeline using push or pull_request triggers. This means that whenever somebody pushes changes to a GitHub repository or opens a Pull Request, the GitHub Action is executed, mostly to run some tests or to upload the latest version to a package manager. What I was unaware of was the <a href="https://help.github.com/en/actions/reference/events-that-trigger-workflows">multitude of triggers</a> that can cause a GitHub Action to be run.</p><p>In my case, the <a href="https://help.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule">scheduled</a> trigger seemed most interesting. It can be set up using (relatively) simple cron syntax, which would let me trigger a GitHub Action once a day to fetch and update the data. Long story short, here’s my GitHub Action workflow, which I shortened a bit from the <a href="https://github.com/PJUllrich/Dauerzaehlstellen-Koeln/blob/master/.github/workflows/python.yml">original,</a> but it essentially achieves the same goal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0c4fd010b5e3c1b4e29c3d90a15d69/href">https://medium.com/media/6a0c4fd010b5e3c1b4e29c3d90a15d69/href</a></iframe><p>This workflow is executed every day roughly at 5 am, give or take 15min since GitHub Actions aren’t run <strong>exactly </strong>on time. It clones the repository to its machine and executes a python script that fetches and appends the latest counts to local files holding the historical data. It then uses the <a href="https://github.com/ad-m/github-push-action">GitHub Push Action</a> to automatically commit and push the latest counter data back to the master branch of my GitHub repository.</p><p>Using this GitHub Action, I could safely forget about running the Python script manually every day and it would automatically fetch and upload the latest data. So, if you also want to safely forget about things, use GitHub Actions.</p><h3>Caveats</h3><p>As mentioned before, the Action is <strong>not </strong>executed exactly on time, but with a delay of up to 15min in my experience. This means, that you shouldn’t use scheduled GitHub Actions for reoccurring jobs which are time-sensitive.</p><p>I was not able to reproduce this since, but the GitHub Action <em>could</em> execute twice, so make sure that your job is idempotent or no-op on the second run. This means that you should be able to run your job multiple times and always receive the expected result. I achieved this by storing the latest date for which I fetched the data. Now, whenever the job was run again for the same date, it would finish without changing any data.</p><h3>Conclusion</h3><p>It took me a day to research this possibility, but only around 1 hour to set up this GitHub Action, so GitHub Actions have convinced me once more of their ease-to-use and practicality. I hope this helped you further as well!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce522358326b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up a Reverse Proxy with CloudFront, Lambda@Edge and Phoenix]]></title>
            <link>https://medium.com/studitemps-tech/how-to-set-up-a-reverse-proxy-with-cloudfront-lambda-edge-and-phoenix-ece134ee16c7?source=rss-788c254a08a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ece134ee16c7</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Peter Ullrich]]></dc:creator>
            <pubDate>Wed, 20 May 2020 07:37:07 GMT</pubDate>
            <atom:updated>2020-05-20T07:40:08.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MUK2mSE3J64AJZA4" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=medium&amp;utm_medium=referral">Caspar Camille Rubin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>My team at Studitemps and I ran into the problem that we had multiple services, which needed to be served from the same URL. We had one service running the <a href="https://elixir-lang.org/">Elixir</a> + <a href="https://github.com/phoenixframework/phoenix">Phoenix</a> stack that we considered our “main service”. This service should be accessible under an URL like <a href="https://example.com/">https://example.com</a>. We also had another service serving our content, which we wanted to integrate into the navigation bar of our main service. We wanted the content service to be accessible under e.g. <a href="https://example.com/content">https://example.com/content</a>.</p><h3>Setting up CloudFront and Lambda@Edge</h3><p>We decided on using AWS CloudFront to route the requests to the appropriate services. In order to do that, we first needed to create 2 <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/DownloadDistS3AndCustomOrigins.html#concept_CustomOrigin">Origins</a>, one forwarding any request to our main service and one to the content service. These were our settings for the Origin of our main service. The settings for the content service where exactly the same except for the <strong>Origin Domain Name </strong>and <strong>Origin ID.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvLj2PPzEpKgIlDcR9J2zA.png" /><figcaption>Settings of the Main Service Origin</figcaption></figure><p>In order to route the requests to the appropriate services, we set up 2 <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html">Behaviors</a>. One behavior would forward any requests containing the /content path to the content service and the other requests would be forwarded to our main service by default. This were our settings for the /content behavior:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6A2iU014xcclhVcswh5Gwg.png" /><figcaption>Settings of the /content-Behavior</figcaption></figure><p>Next, we wanted to remove the /content-path from the request since the routes of our content service didn’t include the /contentpart of the path. For example, the post-route of our content service was available at /post/my-first-post and not /content/post/my-first-post. Therefore, we had to remove the /content part of the request URL. We decided on using a Lambda@Edge function for this.</p><p>First, we created a Node.js 12.x Lambda-Function “from scratch”. We needed to make sure that the function had all the right permissions in order to be triggered by the CloudFront-Behavior. Therefore, we used the Basic Lambda@Edge permissions (for CloudFront Trigger) Policy Template, which predefines all the necessary permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdryhMPDGbLxov2vfCjXuA.png" /><figcaption>Settings for new Lambda function</figcaption></figure><p>We based the code for the function on this informative <a href="https://stackoverflow.com/a/31574851/4138739">StackOverflow</a> post. It uses the JavaScript replace() function to remove the /content-path.</p><pre>&#39;use strict&#39;;<br><br>exports.handler = (event, context, callback) =&gt; {<br>    const request = event.Records[0].cf.request;        <br>    request.uri = request.uri.replace(/\/content/,&#39;/&#39;);<br>    return callback(null, request);<br>};</pre><p>This function retrieves the request object from the event, removes the /content part of the request uri and returns the updated request to CloudFront for further handling.</p><p>Once we saved the code, we deployed the function Lambda@Edge. Under the menu “Actions”, we chose “Deploy to Lambda@Edge” and entered the following information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Emvp6DT6rGkgUcOlbJPkg.png" /><figcaption>Settings for Deploy to Lambda@Edge</figcaption></figure><p>After deploying the Lambda-function, CloudFront would roll out the new distribution to all instances within 5–10min. Once the roll-out succeeded, our services were accessible under <a href="https://example.com/content">https://example.com</a> and <a href="https://example.com/content">https://example.com/content</a> respectively.</p><h3>Setting up Phoenix</h3><p>After we accessed our content service, we had the problem that our static content including the *.css and *.js files wasn’t loaded properly anymore. The problem was that the URLs generated by Phoenix did not include the /content path. So, the URLs to our static files were e.g. https://example.com/js/app.js instead of <a href="https://example.com/content/js/app.js/">https://example.com/content/js/app.js</a>.</p><p>Being the well-written framework that Phoenix is, changing how routes were generated took a single configuration in the <a href="https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#module-runtime-configuration">Plug.Endpoint</a>. We added the path: &quot;/content&quot; setting to our AppWeb.Endpoint configuration.</p><pre># config/prod.exs<br>config :app, AppWeb.Endpoint, <br>  url: [<br>    scheme: &quot;https&quot;, <br>    host: &quot;example.com&quot;, <br>    port: 443, <br>    path: &quot;/content&quot;<br>  ]</pre><p>Once deployed, Phoenix would generate routes prefixed with the /content-path. Since the static_url setting falls back to the url setting, our static files were now also accessible under e.g. https://example.com/content/js/app.js .</p><p>One caveat was though that we make sure to always use the conn instead of AppWeb.Endpoint when generating routes, e.g. Routes.index_path(@conn, :index) since otherwise the /content-prefix would not be included in the URL. Also, the Plug.Static setting in the endpoint.ex should not be changed since the static files must still be served under &quot;/&quot; and <strong>not </strong><strong>&quot;/</strong>content&quot; .</p><h3>Conclusion</h3><p>Setting up a reverse proxy with CloudFront, Lambda@Edge and a Elixir + Phoenix stack was not straight forward and a lot of trial-and-error if you do it for the first time (and don’t feel like reading 1000 pages of AWS documentation). But once you’ve managed, you can offer all your services through a single domain and specify to which service traffic should be forwarded based on a path. Since we plan on adding more services in the future, we are positive that this solution will help us integrate the new services seamlessly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ece134ee16c7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/studitemps-tech/how-to-set-up-a-reverse-proxy-with-cloudfront-lambda-edge-and-phoenix-ece134ee16c7">How to set up a Reverse Proxy with CloudFront, Lambda@Edge and Phoenix</a> was originally published in <a href="https://medium.com/studitemps-tech">Studitemps Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Business Requirements to Production Code]]></title>
            <link>https://medium.com/studitemps-tech/from-business-requirements-to-production-code-17e76e60ad49?source=rss-788c254a08a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/17e76e60ad49</guid>
            <category><![CDATA[enterprise-software]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[maintainability]]></category>
            <category><![CDATA[compliance]]></category>
            <dc:creator><![CDATA[Peter Ullrich]]></dc:creator>
            <pubDate>Fri, 24 Apr 2020 13:44:44 GMT</pubDate>
            <atom:updated>2020-04-24T13:46:15.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*y0alNt6JLaxzzH4hPEC9cA.jpeg" /></figure><p>Here at Studitemps, we have to comply with many rules and regulations that we have to be certain are followed by our software as well. These business requirements have to be poured into production code 1-to-1. Otherwise, we risk losing our students, customers, and at worst, our license.</p><p>Therefore, we have to make sure that our software behaves in certain ways. We have developed a process of extracting and implementing business requirements and to make sure that our software will always operate as needed, even when we develop our software further.</p><h3>The Interview</h3><p>Before we can implement business requirements, we have to understand exactly what they are. For that, we interview our stakeholders about their needs. Talks like this tend to start with a concrete solution idea with which the stakeholder comes into the meeting. The goal of the interview is however to first understand the problem that we need to solve and only then are we brainstorming about potential solution ideas.</p><p>We took this approach from Domain-driven Design in which one should first explore and understand the problem space, before moving on to the solution space, in which solutions to the problem are developed. This approach has the advantage to engage every team member in the problem-solving process. If every member understands the problem the team is likely to develop many more and better suited solutions to the problem since the team members can employ their unique experience and background to find good solutions.</p><p>While interviewing the stakeholders, we tend to use a mix of open-ended and closed-ended questions. Open-ended questions leave room for elaboration and mostly start with “Why”, “What”, or “How”. They are useful to gain an overview of the problem and to let the stakeholders explain in great detail what they need. If we believe that we have understood the problem, we use closed-ended questions, to verify our understanding. We use closed-ended questions only seldomly however since a simple “yes” or “no” from the stakeholders risks losing a lot of information about how much the stakeholders agree or disagree with a statement. We try to use estimations instead, like “From 1 to 10, how much do you agree with this statement?”.</p><p>Another principle of Domain-driven Design that we employ is Ubiquitous Language. It is hard enough to develop a shared understanding of a problem but it becomes much harder, if different words are used for the same thing. Therefore, we try to establish a common terminology that everybody adheres to. This language should also be specific rather than general. Whereas “personal data” can mean lots of things, “contact information” is already much more specific.</p><h3>Acceptance Criteria</h3><p>After we have established what the problem is and how we are going to solve it, we write a specific acceptance criterion that helps us verify or refute that our system behaves in a way that was agreed upon with the stakeholders. The criterion is written without code, but in the language shared with the stakeholders. In our case, this means writing the criteria, tests and even the code itself in German since all communication with stakeholders and within the team is in German. Therefore we opted to use the same terms and language on all levels of the development process.</p><p>An acceptance criterion can be rather trivial like “A user can create an account”, to very specific like “The wage bonus of hours worked on Sundays is exempt from taxation.” The purpose of acceptance criteria for us is to specify a behavior that the system has to show and to share that understanding with everybody involved. This approach is directly taken from Behavior-driven Development which focuses on “what” the system does instead of “how” it does it. Prioritizing the “what” over the “how” weakens the fallacy of letting personal interests influence what is built. If one is interested in the latest framework, which everybody talks about, user stories that might involve implementing this framework become magically much more interesting. However, the main goal is to fulfill the needs of the stakeholders and not one’s interest in technical advancements.</p><h3>Feature Specification</h3><p>Once the acceptance criteria are defined, we move to the technical realm and write our first high-level test. To make sure that the system’s behavior follows the business requirements closely, we write a feature specification first, typically using Gherkin syntax. For example:</p><pre>Scenario: Taxation of Wage Bonus<br>        Given an employee has worked on a Sunday<br>        And has received a wage bonus for that work<br>        When the taxation for that work is calculated<br>        Then the wage bonus is exempt from taxation</pre><p>We make sure that we don’t use technical terms in our specification. Steps like “The user clicks the ‘Register’ button” are dependent on the current state of the system. Once that state changes (e.g. the “Register” button is renamed to “Sign-Up”), we would need to adjust our specifications to reflect that change. A more change-resistant option would be: “The user creates a new account.” We like our high-level tests to be long-lived and independent of the implementation so that the behavior of the system is always checked in the same way.</p><h3>Acceptance Test</h3><p>Once the expected behavior is defined with a feature specification, we start writing acceptance tests. Whereas acceptance tests can be written on any testing level (i.e. e2e, integration or unit), we like them to be the most high-level automated tests we have in our system. Since acceptance criteria are checked against the system as a whole, it made sense to us to write automated tests that operate on the same level of abstraction.</p><p>We try to optimise the acceptance test for readability and to keep every test step as concise as possible. Most functionality is wrapped by helper functions whose function names give an explicit description of what the wrapped code is supposed to do. When the purpose of code is kept implicit, its purpose becomes an assumption, which varies with every developer who reads the code. By making the purpose explicit, the developer has a clear statement of purpose and can verify or refute whether the code is fulfilling its purpose against that statement. Let’s look at an example. The following code checks the last step of our feature specification. Please read it and be aware of how long it takes you to deduct the purpose of the code.</p><pre>defthen “the wage bonus is exempt from taxation”, %{session: session} do<br>    session<br>    |&gt; visit(“/pay”)<br>    |&gt; fill_in(fillable_field(“username”), text: “test-account”)<br>    |&gt; fill_in(fillable_field(“password”), text: “test-password”)<br>    |&gt; click(button(“Login”))<br>    |&gt; click(button(“Payslips”))<br>    |&gt; click(link(“01.11. - 30.11.2019”))<br>    |&gt; find(css(“#wage-bonus-taxation”))<br>    |&gt; assert_text(“0.00”)<br>end</pre><p>The test code exposes a lot of details of how it asserts that the taxation is equal to 0.00. To understand it, you have to have a mental model of how the UI looks like. For example, did you notice that the test navigated to the “Payslips” tab and opened the payslip of last month given that this article was written in December 2019? The only critical line in this test is the line assert_text(“0.00”) since right here we test the behavior of the system of how to calculate the wage tax. Let’s look at the same test again, this time written with helper functions, which encapsulate most of the logic.</p><pre>defthen “the wage bonus is exempt from taxation”, %{session: session} do<br>    session<br>    |&gt; open_payslip_of_last_month()<br>    |&gt; assert_that_wage_bonus_taxation_is_zero()<br>end</pre><p>This version of the test does exactly the same as the first version, but encapsulates any logic into helper functions, which define explicitly what they do. The test is much easier to read and to understand. If the developer cares about the underlying code, she can always dive into the helper functions which follow the single responsibility principle and do one thing only (e.g. login(), or open_payslip_from_november_2019()).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*he8zv7cY9gOGmhfs.png" /></figure><h3>Summary</h3><p>We started the process of bringing business requirements to our software in the business realm. We interviewed our stakeholders using open/closed conversation techniques starting in the problem space and slowly moving towards the solution space. We established a ubiquitous language to which everyone committed to adhere. Once a solution was agreed upon, we distilled the solution into an acceptance criterion, which gives our stakeholders explicit requirements against which they can verify the behavior of the system. The acceptance criterion focuses on the “what”, not the “how”.</p><p>Then, we left the business realm and moved to the technical realm. Here, we first wrote a feature specification, which is independent to technicalities and views the system as a black box. The specification was then tested in a concise acceptance test that moves the raw logic into helper functions, which explicitly describe the purpose of their implicit actions. This concludes the process of extracting business requirements and verifying them against our production code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17e76e60ad49" width="1" height="1" alt=""><hr><p><a href="https://medium.com/studitemps-tech/from-business-requirements-to-production-code-17e76e60ad49">From Business Requirements to Production Code</a> was originally published in <a href="https://medium.com/studitemps-tech">Studitemps Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bridge the Gap: Bring your Software to life with Elixir and Nerves]]></title>
            <link>https://peterullrich.medium.com/bridge-the-gap-bring-your-software-to-life-with-elixir-and-nerves-92866f2197d9?source=rss-788c254a08a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/92866f2197d9</guid>
            <category><![CDATA[raspberry]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[nerve]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Peter Ullrich]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 14:06:50 GMT</pubDate>
            <atom:updated>2019-07-31T14:06:50.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FCHldmjXJhRMkqDQw1aH_g.jpeg" /></figure><p>Writing code is fun, but nothing tops seeing your code moving things in the real world. That’s why I tested out the <a href="https://nerves-project.org/">Nerves library</a> and used $20 of Raspberry Pi utensils to let software wave a flag for me.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjterXt63tYM%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjterXt63tYM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjterXt63tYM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3fe8499f8c34b49928a4c952fc8dde8/href">https://medium.com/media/e3fe8499f8c34b49928a4c952fc8dde8/href</a></iframe><h3>The Hardware</h3><p>For this project, I used the following hardware:</p><ol><li>Raspberry Pi Zero W</li><li>28BYJ-48 5v Stepper Motor with ULN2003 Board</li><li>16GB microSD Card</li><li>A <a href="https://grandcentrix.net/">grandcentrix</a> flag</li><li>Some cables</li></ol><h3>The Wiring</h3><p>Here’s an overview of how to connect the ULN2003 to the Raspberry Pi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*ua3mQ6T7OQgZqiQ8sL80jQ.png" /><figcaption>Wiring schematic of Raspberry Pi and ULN2003 Board</figcaption></figure><p>After you connect the ULN2003 Board to the Pi, connect the Stepper Motor to the ULN2003 and the Pi to your Computer. <strong>IMPORTANT</strong>: Connect the Pi to your Computer using the USB port and <strong>not </strong>the PWR port. Otherwise, you will not be able to transfer or execute code from your Computer on the Pi.</p><p>Also, make sure to connect the wires properly. The LEDs on the ULN2003 Board should glow red once you start the stepper motor.</p><h3>Setting up the Project</h3><p>You can find the full code on <a href="https://github.com/PJUllrich/Nerves-Motor-Demo">GitHub</a>. Here’s how you set up the project from scratch.</p><p>If you haven’t already, first install the Nerves dependencies for your operating system</p><pre># On <strong>macOS</strong>, run:<br>brew update<br>brew install fwup squashfs coreutils xz</pre><pre># On <strong>Linux</strong>, run:<br>sudo apt install build-essential automake \<br>     autoconf git squashfs-tools ssh-askpass</pre><p>Then install the Nerves Bootstrap library</p><pre>mix archive.install hex nerves_bootstrap</pre><p>Next, create a new Nerves project and install its dependencies with</p><pre>mix nerves.new move_it<br>cd move_it</pre><p>Add the <a href="https://github.com/elixir-circuits/circuits_gpio">circuits_gpio</a> dependency to your mix.exs file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccc8b18b1cd234454c95a393fbad1d38/href">https://medium.com/media/ccc8b18b1cd234454c95a393fbad1d38/href</a></iframe><p>Install the dependencies with</p><pre>export MIX_TARGET=rpi0<br>mix deps.get</pre><p>You should now have a fully set up project. As a last step, enable the logger by changing the rootfs_overlay/etc/iex.exs like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dfd5ee8341d091db6bfbc24f87864d8/href">https://medium.com/media/9dfd5ee8341d091db6bfbc24f87864d8/href</a></iframe><h3>The Code</h3><p>Open the lib/move_it/move_it.ex file and fill it with the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c706095878f830277fb090b9fb4413be/href">https://medium.com/media/c706095878f830277fb090b9fb4413be/href</a></iframe><p>The code above first opens the GPIO pins with the GPIO.open/2 function and then starts the motor by sequentially enabling and disabling the Pins. This causes the stepper motor to move one step forward each time one of the pins is enabled. You can adjust how many steps the motor will make by defining the countparameter when starting the script with MoveIt.start(count)</p><h3>Setting up the Raspberry Pi</h3><p>First, insert the SD card into your computer.</p><p>Now, bundle the code into a <em>firmware</em> and copy it to the SD Card with the commands</p><pre>mix firmware<br>mix firmware.burn</pre><p>Nerves “should” be able to find your SD card and will ask you to confirm it. If it doesn’t find your SD card, you can supply the mount point with the -d option like so:</p><pre># For example<br>mix firmware.burn -d /dev/rdisk2</pre><p>After the copy process is completed, insert the SD Card into your Raspberry Pi and connect the Pi with the USB cable to your computer.</p><h3>Getting Things moving</h3><p>Now, the thrilling part comes. Connect your computer to the Raspberry Pi with</p><pre>ssh nerves.local</pre><p>This will start an iex terminal on the Raspberry Pi. Now, start the motor with</p><pre>MoveIt.start(1200)</pre><p>The motor should turn, you should be filled with awe, and in the distance you will hear the appreciative clapping of <a href="https://en.wikipedia.org/wiki/Richard_Stallman">Richard Stallman</a> for using open-source software :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92866f2197d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State Management with Phoenix LiveView and LiveEx]]></title>
            <link>https://medium.com/grandcentrix/state-management-with-phoenix-liveview-and-liveex-f53f8f1ec4d7?source=rss-788c254a08a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f53f8f1ec4d7</guid>
            <category><![CDATA[flux]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[liveview]]></category>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Peter Ullrich]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 09:51:50 GMT</pubDate>
            <atom:updated>2019-07-23T12:07:18.427Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://grandcentrix.net/">grandcentrix</a>, we use the Elixir + Phoenix stack to deliver scalable, fault-tolerant and high-availability IoT solutions to our customers. The web frontends, we build for managing these solutions, need to be developed rapidly and adjusted constantly to the needs of our customers. The Phoenix framework is a perfect choice for our needs, but unfortunately requires us to add interactivity using JavaScript. That changed when the Phoenix LiveView project came along.</p><p>With Phoenix LiveView, adding interactivity and displaying state changes without reloading the page becomes trivial. The complexity and loss of productivity due to context switching decreases significantly by eliminating the split between the backend and frontend code. But now that the normally stateless, since static, frontend becomes stateful, a new question arises: How can we manage the state?</p><h3>The Problem</h3><p>Once a stateful frontend grows in complexity, it becomes significantly more difficult to keep oversight of <em>how</em> the state is changed, <em>when</em>, by <em>whom, </em>and in <em>what</em> order<em>. </em>Think about state changes caused by asynchronous calls that fetch data from the backend, a websocket connection that pushes new updates to the data, and on top of all of this, have the user edit the state as well. All these actors change the state and since they usually do this directly, it quickly becomes unclear what is happening.</p><h3>The Solution</h3><p>Facebook ran into these issues as their website grew in complexity and proposed an architectural pattern they called <strong>flux</strong>. If you want to understand this pattern in-depth, we recommend Facebook’s <a href="https://www.youtube.com/watch?v=nYkdrAPrdcw">introduction</a> to the topic. In high level terms, the flux pattern wraps every state change into an <strong>action</strong> with a <strong>type</strong> and a <strong>payload</strong>. Every action has to go through a <strong>dispatcher</strong>, which is similar to a funnel, through which every action has to go sequentially. The dispatcher applies the change to the state using callbacks (sometimes called <strong>mutations</strong>) which were previously registered by a<strong> store </strong>to handle certain actions. The stores emit a <em>change</em> event if their state has changed. Special views called <em>controller-views</em> receive that event, fetch the latest state, and apply the updates to their views.</p><p>The advantage of the flux pattern is that state changes become observable and replicable. It helps tremendously in debugging breaking state changes and monitoring the information flows of larger frontend applications. It has proven itself to be so useful in sanitizing state changes that every larger single-page application (SPA) framework has an implementation of the flux pattern like <a href="https://vuex.vuejs.org/">Vuex</a>, <a href="https://redux.js.org/">Redux</a>, and <a href="https://ngrx.io/">NgRx</a>. In our experiences with LiveView, we ran into the exact issues that these libraries solve and therefore we decided to build a flux implementation for Phoenix LiveView, called <a href="https://github.com/pjullrich/live_ex"><strong>LiveEx</strong></a>.</p><h3>LiveView meets Flux</h3><p>In order to facilitate the use of the flux pattern in LiveView, we created the <strong>LiveEx</strong> library, which helps set up the flux architecture. LiveEx is inspired by the Vuex library, thus it adheres to the following flux flow:</p><figure><img alt="Vuex flux flow. LiveView dispatches Actions, which commit Mutations that mutate the Store which updates the LiveViews" src="https://cdn-images-1.medium.com/max/261/0*rVCu0N-VVHuzWYZX.png" /><figcaption>Flux Flow of the Vuex library</figcaption></figure><p>The Vuex flow deviates a bit from the original flux flow since it allows side-effects (e.g. asynchronous or database calls) in its actions. However, everything after the actions must be side-effect free and synchronous. In short, a view dispatches an action, which does its logic and eventually commits a mutation. The mutation actually changes/mutates the state and stores the updated state back in a store. The store notifies the views about its state change, which pull the latest version of the state and update themselves.</p><p>LiveEx gives you all the tools to write your own store with actions and mutations and lets you dispatch actions easily from within any LiveView that is connected to a particular store. Subsequently, we show how to get started with the LiveEx library.</p><h3>Setup LiveEx</h3><p>We created an example project that implements LiveEx and open-sourced it on <a href="https://github.com/PJUllrich/live_ex_example">GitHub</a>. Below, we explain how to set up your own project.</p><p>Add the LiveEx library to your Phoenix project:</p><pre>def deps do<br>  [<br>    {:live_ex, github: &quot;pjullrich/live_ex&quot; }<br>  ]<br>end</pre><p>Create a module for your store. A fully documented version of an example store can be found on <a href="https://github.com/PJUllrich/live_ex/blob/master/lib/example/example.ex">GitHub</a>. Here an example for how it could look like:</p><pre>defmodule MyAppWeb.Store do<br>  use LiveEx<br><br>  @initial_store %{<br>    a: 1,<br>    b: &quot;test&quot;,<br>    c: true,<br>    d: [nil, nil, nil]<br>  }<br><br>  def init(socket) do<br>    init(@initial_store, socket)<br>  end<br><br>  # Actions<br><br>  def handle_info(%{type: &quot;add&quot;} = action, socket) do<br>    # Perform any operation with the payload here. For example:<br>    new_state = socket.assigns.a + action.payload<br><br>    commit(&quot;set_a&quot;, new_state, socket)<br>  end<br><br>  # Mutations<br><br>  def set_a(payload, socket) do<br>    assign(socket, :a, payload)<br>  end<br>end</pre><p>Let’s discuss this. First, store variables can also be added dynamically, but it is a good idea to write out the entire structure of your store once. Thus, define every store variable that you will use in your application with a default value in the initial_store map. Pass this map to the init/2 function together with a LiveView.Socket. This will initialize your store.</p><p>Below your init/1 function, define your actions. Use pattern-matching to match the appropriate action with an action <strong>type</strong>. Perform any business logic in the action, potentially with side-effects or asynchronous calls. Eventually, commit a mutation that updates the state.</p><p>Mutations have to be free of side-effects and typically contain little to none business logic except for what is necessary to update the state. Please note that their function name needs to equal the name with which they should be committed (in this case set_a).</p><p>Next, connect your store with your “root” LiveView, which is the LiveView that encapsulates any LiveViews that should use the same state.</p><pre>defmodule MyAppWeb.RootLive do<br>  alias MyAppWeb.Store<br>  <br>  ...<br><br>  def mount(_session, socket) do<br>    # Init the store <br>    {:ok, Store.init(socket)} <br>  end<br><br>  ...</pre><pre>  # Delegate any action callbacks to the store<br>  # Add this line to the end of &quot;root&quot; LiveView<br>  defdelegate handle_info(msg, socket), to: Store<br>end</pre><p>Make sure to pass any state variables down to the nested LiveViews with</p><pre>&lt;%= Phoenix.LiveView.live_render(@socket, MyAppWeb.ChildLive, session: Map.take(assigns, [:a, :b, :c, :d])) %&gt;</pre><p>Within every nested LiveView, initialize the store as well in the mount/2 function with the passed-on state variables (here: [:a, :b, :c, :d])</p><pre>alias MyAppWeb.Store</pre><pre>...</pre><pre>def mount(session, socket) do<br>  {:ok, Store.init(session, socket)}<br>end</pre><h3>Use LiveEx</h3><p>Display your state in your .leex templates by using the common Phoenix Template syntax:</p><pre>&lt;h1&gt;Value of &quot;a&quot;: &lt;%= @a %&gt;&lt;/h1&gt;</pre><p>To change your state, simply call the dispatch/3 function with the <strong>type</strong>, (optional)<strong> payload, </strong>and LiveView.Socket and let LiveEx do its magic.</p><pre>def handle_event(&quot;add&quot;, value, socket) do<br>  to_add = String.to_integer(value)</pre><pre>  Store.dispatch(&quot;add&quot;, to_add, socket)<br>  {:noreply, socket}<br>end</pre><p>The dispatch/3 call will create and commit an action, change the state, and update the state of your LiveView.Socket automagically!</p><h3>Debugging</h3><p>Now that we send every state change through the dispatcher, it becomes trivial to log the state changes. Hence, if you set your Logger to debug, you will see how your actions are changing the state. Here is an example from the console:</p><pre>[debug] LiveEx<br>      - Action:  add<br>      - Payload: 3<br>      - Before:  %{a: 2, b: &quot;test&quot;, c: true, d: [nil, nil, nil]<br>      - After:   %{a: 5, b: &quot;test&quot;, c: true, d: [nil, nil, nil]</pre><h3>Conclusion</h3><p>LiveEx will hopefully help you to develop middle to larger frontends. It is not yet battle-tested, nor optimized. It will change dramatically once the LiveView team implements <a href="https://github.com/phoenixframework/phoenix_live_view/blob/master/lib/phoenix_live_view.ex#L89">support for prepending/appending</a> data since then each store state can be kept in a dedicated socket assignment. More on this <a href="https://github.com/PJUllrich/live_ex/issues/4">here</a>.</p><p>If you want to help to make state management with LiveView easier, your help and feedback are most welcome and best handed in on the <a href="https://github.com/PJUllrich/live_ex">LiveEx GitHub page</a>.</p><p>For further information, please check out the <a href="https://github.com/PJUllrich/live_ex_example">LiveEx Example Repository</a>.</p><p>Otherwise, if you’re interested in developing IoT solutions with Elixir, check out our <a href="https://grandcentrix.jobs/">jobs page</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f53f8f1ec4d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/grandcentrix/state-management-with-phoenix-liveview-and-liveex-f53f8f1ec4d7">State Management with Phoenix LiveView and LiveEx</a> was originally published in <a href="https://medium.com/grandcentrix">grandcentrix</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>