<?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 Leandro Cesquini Pereira on Medium]]></title>
        <description><![CDATA[Stories by Leandro Cesquini Pereira on Medium]]></description>
        <link>https://medium.com/@leandrocesquini?source=rss-77fa428a9fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZlOHnsz06Qd7qmKa.</url>
            <title>Stories by Leandro Cesquini Pereira on Medium</title>
            <link>https://medium.com/@leandrocesquini?source=rss-77fa428a9fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:19:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leandrocesquini/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[Enforcing code quality in Elixir]]></title>
            <link>https://itnext.io/enforcing-code-quality-in-elixir-20f87efc7e66?source=rss-77fa428a9fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/20f87efc7e66</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Leandro Cesquini Pereira]]></dc:creator>
            <pubDate>Fri, 07 Jun 2019 12:19:38 GMT</pubDate>
            <atom:updated>2019-06-07T13:55:37.029Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EaXybdKQ8iNVaPH1" /><figcaption>Photo by <a href="https://unsplash.com/@jeremythomasphoto?utm_source=medium&amp;utm_medium=referral">Jeremy Thomas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Enforcing your Elixir code to be well formatted, with no warnings and hopefully free of bugs. I’m talking about a <em>mix alias</em> that will check the quality of the code, and that can be used during local development and also on CI/CD pipelines to enforce the team (or yourself) to keep a clean code. But keep in mind that there&#39;s no magic, you&#39;re still responsible for creating a code that&#39;s well organized, performant, without security issues, and pleasant for human reading.</p><h4>Table of Contents</h4><ul><li><a href="https://medium.com/p/20f87efc7e66#ef9e">Tools</a></li><li><a href="https://medium.com/p/20f87efc7e66#a4e5">Implementation</a></li><li><a href="https://medium.com/p/20f87efc7e66#ebb2">Executing</a></li><li><a href="https://medium.com/p/20f87efc7e66#48a2">Complete example files</a></li><li><a href="https://medium.com/p/20f87efc7e66#e9c1">References</a></li></ul><h3>TL;DR</h3><p>The complete example is <a href="https://medium.com/p/20f87efc7e66#48a2">at the end of the article</a>.</p><h3>Tools</h3><h4>Credo and Dialyzer</h4><p><a href="https://github.com/rrrene/credo">Credo</a> is responsible for checking if the code is adherent to common good code practices established by the community. And <a href="http://erlang.org/doc/man/dialyzer.html">dialyzer</a> is a static analysis tool that identifies software discrepancies, such as definite type errors, code that has become dead or unreachable because of a programming error (paraphrasing the official docs), but we&#39;ll use <a href="https://github.com/jeremyjh/dialyxir">dialyxir</a>, which is wrapper around dialyzer written in Elixir that simplify the use of dialyzer.</p><h4>Sobelow</h4><p><a href="https://github.com/nccgroup/sobelow">Sobelow</a> is a security-focused static analysis tool for the Phoenix framework. If you&#39;re not using Phoenix, just remove it from the deps, configs, and alias described on this article.</p><h4>mix format</h4><p>The <a href="https://hexdocs.pm/mix/Mix.Tasks.Format.html">mix format</a> task was <a href="https://elixir-lang.org/blog/2018/01/17/elixir-v1-6-0-released/">introduced in Elixir v1.6</a>, and it&#39;s used to format your code automatically. One of the main benefits of using it is to avoid boring and endless discussions like &quot;how we should format the code ?&quot;, &quot;what should be the line length ?&quot;, and so on. <a href="https://github.com/elixir-lang/elixir/blob/v1.8/Makefile#L215-L216">Elixir also uses it</a> to enforce a standard format.</p><h4>Warning as errors</h4><p>That’s not a tool, actually, it’s an <a href="https://hexdocs.pm/mix/Mix.Tasks.Compile.Elixir.html">Elixir compile attribute</a> that will treat warnings in the current project as errors and return a non-zero exit code, which means that your project won’t compile if it has any warning.</p><h4>A note before we continue</h4><p>Having all those tools and configs turned on <em>may be</em> annoying. A module without doc, a wrong spec or even an unused variable will stop you from compiling and shipping the code. The level of enforcement is up to you, so you should adapt the tools and configs as required for your project (and your stress level). But it&#39;s a good ideia to plan for the long term.</p><h3>Implementation</h3><p>Ok, let&#39;s change the files to implement the quality check. Let’s do that piece by piece, or better saying, function by function.</p><h4>mix.exs</h4><p>First, let&#39;s install the deps. Add the following in <em>deps list</em>:</p><pre>{:credo, &quot;~&gt; 1.0&quot;, only: [:dev, :test], runtime: false},<br>{:dialyxir, &quot;~&gt; 1.0.0-rc.6&quot;, only: [:dev, :test], runtime: false},<br>{:sobelow, &quot;~&gt; 0.7&quot;, only: [:dev, :test], runtime: false}</pre><p>And let’s change the project’s config. Add this to the <em>project function</em>:</p><pre>elixirc_options: [warnings_as_errors: true],<br>aliases: aliases(),<br>dialyzer: [<br>  plt_file: {:no_warn, &quot;priv/plts/dialyzer.plt&quot;},<br>  ignore_warnings: &quot;.dialyzer_ignore.exs&quot;<br>]</pre><p>Which will be like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bf48d95d4fbe4371ac8087116a91cc9/href">https://medium.com/media/2bf48d95d4fbe4371ac8087116a91cc9/href</a></iframe><p>I recommend reading <a href="https://hexdocs.pm/dialyxir/0.4.1/readme.html">dialyxir doc</a> to know more about its config, especially the <a href="https://github.com/jeremyjh/dialyxir#continuous-integration">Continuous Integration</a> if you want to enforce it on your CI/CD pipeline.</p><p>Continuing, let&#39;s create an alias function in your mix.exs file, <em>if you don&#39;t have this function already created</em>, and add two aliases:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbc599869d9eb498b8350caa53e4c856/href">https://medium.com/media/dbc599869d9eb498b8350caa53e4c856/href</a></iframe><p>I like using one alias specific for local development (quality) and one for CI/CD (quality.ci) because I have more freedom on the order of the tasks and its arguments. For example, on local development I don&#39;t want to check if the code is formatted, I just format the code directly; and I like to see test results at the end. Adapt as you want.</p><h4><em>.dialyzer_ignore.exs</em></h4><p>Create the file <em>.dialyzer_ignore.exs</em> in the root dir of the project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbc08ff54df44d624394ea11cbedb254/href">https://medium.com/media/bbc08ff54df44d624394ea11cbedb254/href</a></iframe><p>Remember I said those tools may be annoying ? Specially the dialyzer. Don&#39;t get me wrong, dialyzer is amazing and I believe you should use it, but sometimes you need to ignore a warning or two, and that&#39;s the file where you can do that.</p><p>About the content of this file: we&#39;ll run our aliases on the test environment (MIX_ENV=test) and dialyzer reclaim that those functions are errors, but that&#39;s not a big deal and let&#39;s just ignore it.</p><h4>Credo</h4><p>You don’t need to change anything in order to make credo work, but the default rules may not be suitable for your project. You can change that using a <a href="https://github.com/rrrene/credo#configuration-via-credoexs">.credo.exs</a> file or <a href="https://github.com/rrrene/credo#inline-configuration-via-config-comments">using special comments</a>.</p><h4>.gitignore</h4><p>Add to .gitignore:</p><pre># Dialyzer<br>/priv/plts/*.plt<br>/priv/plts/*.plt.hash</pre><pre># Sobelow<br>.sobelow</pre><p>Those files are environment-dependent.</p><h3>Executing</h3><p>Finally, you&#39;re ready to go! 😅</p><p>First, let&#39;s create the dir where dialyzer will store plt files:</p><p>mkdir -p priv/plts</p><p>And then just execute in your terminal:</p><p>MIX_ENV=test mix quality</p><p>Take some time off and grab a coffee, the first execution will take some time to build all dialyzer artefacts, but those files will be cached, don’t worry.</p><p>And change your CI/CD pipeline to execute:</p><p>MIX_ENV=test mix quality.ci</p><p>Whenever this command finds an issue in your code, the CI/CD pipeline will halt and return a failure.</p><h3>Complete example files</h3><p><em>mix.exs</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af38e8115a90596c172d967b0d23d0f1/href">https://medium.com/media/af38e8115a90596c172d967b0d23d0f1/href</a></iframe><p><em>.dialyzer_ignore.exs</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbc08ff54df44d624394ea11cbedb254/href">https://medium.com/media/bbc08ff54df44d624394ea11cbedb254/href</a></iframe><p>.gitignore</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5931a9d451d1cf236b9db0094f05f2f4/href">https://medium.com/media/5931a9d451d1cf236b9db0094f05f2f4/href</a></iframe><h3>References</h3><ul><li><a href="https://pragprog.com/book/tvmelixir/adopting-elixir">Adopting Elixir - From Concept to Production</a></li><li><a href="https://blog.dnsimple.com/2018/10/elixir-dialyzer-in-ci/">https://blog.dnsimple.com/2018/10/elixir-dialyzer-in-ci/</a></li></ul><p><em>Are you looking for a creative company to implement your next idea? Check out </em><a href="https://lnasystems.com.br/"><em>LNA Systems</em></a><em> and let’s talk.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20f87efc7e66" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/enforcing-code-quality-in-elixir-20f87efc7e66">Enforcing code quality in Elixir</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phoenix LiveView Collection]]></title>
            <link>https://medium.com/@leandrocesquini/phoenix-liveview-collection-8259f35ff2b0?source=rss-77fa428a9fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/8259f35ff2b0</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[demo]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[phoenix]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Leandro Cesquini Pereira]]></dc:creator>
            <pubDate>Mon, 06 May 2019 13:53:26 GMT</pubDate>
            <atom:updated>2019-08-28T01:20:12.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vN59PfaLcTd0DiYk" /><figcaption>Photo by <a href="https://unsplash.com/@loic?utm_source=medium&amp;utm_medium=referral">Djim Loic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Amazing demos and experiments that people are building with <a href="https://github.com/phoenixframework/phoenix_live_view">Phoenix LiveView</a>.</p><h3>Outdated</h3><p>Please checkout <a href="https://live-view-collection.herokuapp.com/">https://live-view-collection.herokuapp.com/</a> for a better experience.</p><h3>Intro</h3><p>I plan to keep this article updated as I find more examples and demos. But you can also contribute by commenting on this article or creating an issue at <a href="https://github.com/leandrocp/phoenix-liveview-collection">phoenix-liveview-collection repo</a>.</p><h4>Table of Contents</h4><ul><li><a href="https://medium.com/p/8259f35ff2b0#819b">Intro</a></li><li><a href="https://medium.com/p/8259f35ff2b0#3b54">Table of Contents</a></li><li><a href="https://medium.com/p/8259f35ff2b0#4619">Chris McCord examples</a></li><li><a href="https://medium.com/p/8259f35ff2b0#375f">Flappy Bird Clone</a></li><li><a href="https://medium.com/p/8259f35ff2b0#0b83">Form with multiple steps and progression indicator</a></li><li><a href="https://medium.com/p/8259f35ff2b0#fbd6">Table pagination, filtering, and sorting</a></li><li><a href="https://medium.com/p/8259f35ff2b0#4994">Synthetic load generator + ad-hoc scheduler observer</a></li><li><a href="https://medium.com/p/8259f35ff2b0#29ca">Hippo Game</a></li><li><a href="https://medium.com/p/8259f35ff2b0#b50c">WikiLiveView</a></li><li><a href="https://medium.com/p/8259f35ff2b0#afa3">Undo</a></li><li><a href="https://medium.com/p/8259f35ff2b0#206a">Logic Simulator viewer</a></li><li><a href="https://medium.com/p/8259f35ff2b0#b4ef">Doom’s fire</a></li><li><a href="https://medium.com/p/8259f35ff2b0#3133">SVG LiveView</a></li><li><a href="https://medium.com/p/8259f35ff2b0#c244">SVG LiveView 2</a></li><li><a href="https://medium.com/p/8259f35ff2b0#f1e0">Server-side calculator</a></li><li><a href="https://medium.com/p/8259f35ff2b0#eff1">Todos</a></li><li><a href="https://medium.com/p/8259f35ff2b0#d0df">Live Tinkering</a></li><li><a href="https://medium.com/p/8259f35ff2b0#66a7">Word Game</a></li><li><a href="https://medium.com/p/8259f35ff2b0#1a9a">Re-computing and re-rendering over 200 rows</a></li><li><a href="https://medium.com/p/8259f35ff2b0#732a">Table editor</a></li><li><a href="https://medium.com/p/8259f35ff2b0#cf50">Adventure Capitalist clone</a></li><li><a href="https://medium.com/p/8259f35ff2b0#32c0">Push live updates</a></li><li><a href="https://medium.com/p/8259f35ff2b0#3a19">ObserverLive</a></li><li><a href="https://medium.com/p/8259f35ff2b0#9b4c">Match game</a></li><li><a href="https://medium.com/p/8259f35ff2b0#cfe9">Side by side with Nodejs’ Socket IO</a></li><li><a href="https://medium.com/p/8259f35ff2b0#7f0d">BlackJack game</a></li><li><a href="https://medium.com/p/8259f35ff2b0#aa8a">SeaBattle game</a></li><li><a href="https://medium.com/p/8259f35ff2b0#6eb8">Rubular clone</a></li><li><a href="https://medium.com/p/8259f35ff2b0#fa56">Real-time chat</a></li><li><a href="https://medium.com/p/8259f35ff2b0#cd8e">Live HTML/CSS</a></li><li><a href="https://medium.com/p/8259f35ff2b0#cb9a">Live IMU sensor</a></li><li><a href="https://medium.com/p/8259f35ff2b0#68fe">Bluetooth Low Energy HeartRate demo</a></li><li><a href="https://medium.com/p/8259f35ff2b0#b3f8">Real-time communication with Zoom API</a></li><li><a href="https://medium.com/p/8259f35ff2b0#bfac">BreakoutEx (breakout clone)</a></li><li><a href="https://medium.com/p/8259f35ff2b0#e62f">Bike comparison</a></li><li><a href="https://medium.com/p/8259f35ff2b0#ada5">Calendar component</a></li><li><a href="https://medium.com/p/8259f35ff2b0#9a44">Kubernetes dashboard</a></li><li><a href="https://medium.com/p/8259f35ff2b0#dc5f">Markdown Live</a></li><li><a href="https://medium.com/p/8259f35ff2b0#4c5b">Ant Farm</a></li><li><a href="https://medium.com/p/8259f35ff2b0#7161">UX keypad</a></li><li><a href="https://medium.com/p/8259f35ff2b0#b8d0">Chat App</a></li><li><a href="https://medium.com/p/8259f35ff2b0#9e4d">Functional data structures</a></li><li><a href="https://medium.com/p/8259f35ff2b0#96fd">RFID Reader</a></li><li><a href="https://medium.com/p/8259f35ff2b0#a8f5">LetterSoup Game (Boggle clone)</a></li><li><a href="https://medium.com/p/8259f35ff2b0#3ad1">Keeping notes</a></li><li><a href="https://medium.com/p/8259f35ff2b0#ab84">Collaborative Painting</a></li><li><a href="https://medium.com/p/8259f35ff2b0#a0fd">Game of Life</a></li><li><a href="https://medium.com/p/8259f35ff2b0#d2c0">Falling Tiles game</a></li><li><a href="https://medium.com/p/8259f35ff2b0#1bdf">Kanban board</a></li><li><a href="https://medium.com/p/8259f35ff2b0#608d">Table Filter</a></li><li><a href="https://medium.com/p/8259f35ff2b0#79cf">Trivia Multiplayer</a></li><li><a href="https://medium.com/p/8259f35ff2b0#51dc">Monitoring dashboard</a></li><li><a href="https://medium.com/p/8259f35ff2b0#b909">Multi-step Form</a></li><li><a href="https://medium.com/p/8259f35ff2b0#fc8c">Piano roll</a></li><li><a href="https://medium.com/p/8259f35ff2b0#ccfe">Star Polygon demo</a></li></ul><h3>Chris McCord examples</h3><h3>Chris McCord on Twitter</h3><p>Phoenix LiveView is now public as we work towards our first release! I don&#39;t think my inbox could take any more messages asking for access :D https://t.co/EhV2hKlWrI</p><p><a href="https://github.com/chrismccord/phoenix_live_view_example">chrismccord/phoenix_live_view_example</a></p><h3>Flappy Bird Clone</h3><h3>Richard Taylor on Twitter</h3><p>Had fun making this Flappy Bird clone using @elixirphoenix LiveView. UI updates render in real time from the server. #myelixirstatus https://t.co/9H1jzPx4Zy</p><p><a href="https://github.com/moomerman/flappy-phoenix">moomerman/flappy-phoenix</a></p><h3>Form with multiple steps and progression indicator</h3><h3>Alex Garibay on Twitter</h3><p>I updated a form to have multiple steps with progression indicator, interactive user selection with filtering, and real-time validation on field blur all with #LiveView on @progressplum. Phoenix LiveView makes everything so much better! 🚀 #MyElixirStatus https://t.co/jlN7rGitKb</p><h3>Table pagination, filtering, and sorting</h3><h3>Jørgen O. Erichsen on Twitter</h3><p>Table pagination, filtering, and sorting with Phoenix LiveView and no JS :-) ~50 lines of Elixir https://t.co/usAbs4EicS #myelixirstatus https://t.co/08MbsYJHYE</p><p><a href="https://github.com/joerichsen/phoenix_live_view_example/blob/table_example/lib/demo_web/live/table_live.ex">joerichsen/phoenix_live_view_example</a></p><h3>Synthetic load generator + ad-hoc scheduler observer</h3><h3>Saša Jurić on Twitter</h3><p>Synthetic load generator + ad-hoc scheduler observer powered by #phoenix #LiveView #myelixirstatus https://t.co/yV3P3w7afY</p><p><a href="https://github.com/sasa1977/demo_system">sasa1977/demo_system</a></p><h3>Hippo Game</h3><h3>Milada on Twitter</h3><p>my first project in #PhoenixFramework and #LiveView: https://t.co/uy3zAMQG2v https://t.co/UsJGMA7k0s #MyElixirStatus @ElixirPhoenix https://t.co/tgSMyoAqG4</p><p><a href="https://github.com/miladamilli/hippo_game_live">miladamilli/hippo_game_live</a></p><h3>WikiLiveView</h3><h3>Felix Klement on Twitter</h3><p>Finally had time to play a bit around with #LiveView. Big kudos to @chris_mccord and everyone who worked/is working on it. Demo: https://t.co/JZvKNdbwmw Code: https://t.co/X8pW3UKl1N #myelixirstatus https://t.co/6YUw3QlyYa</p><p><a href="https://github.com/fklement/wikipedia_live_view">fklement/wikipedia_live_view</a></p><h3>Undo</h3><h3>Jørgen O. Erichsen on Twitter</h3><p>Want &quot;Undo&quot; in your web app? Use the amazing power of Phoenix LiveView and Elixir and implement it in ~45 lines of Elixir https://t.co/ZJFRO9S4KQ #myelixirstatus https://t.co/GHpNSHZOoO</p><p><a href="https://github.com/joerichsen/phoenix_live_view_example/blob/undo_example/lib/demo_web/live/undo_live.ex">joerichsen/phoenix_live_view_example</a></p><h3>Logic Simulator viewer</h3><h3>Mike Binns on Twitter</h3><p>Currently building a logic simulator library and a separate @elixirphoenix #LiveView display for the library. Each node is a GenServer, they communicate through message passing. #MyElixirStatus https://t.co/DyKIW2Sef3</p><h3>Doom’s fire</h3><h3>Allan on Twitter</h3><p>Trying out #LiveView and #PhoenixFramework to animate DOOM&#39;s fire: https://t.co/U9GSAsTqNr @elixirphoenix :) https://t.co/lnJiLTnNrN</p><p><a href="https://github.com/allmonty/elixir-live-doom-fire">allmonty/elixir-live-doom-fire</a></p><h3>SVG LiveView</h3><h3>Lucian Parvu on Twitter</h3><p>@elixirphoenix LiveView can redefine Full Stack Web development JS libs (like D3.js) can be ported to the server I can see solutions based on morphdom being adopted in @rails and @djangoproject I just did a quick SVG LiveView test. Incredible no JavaScript! #myelixirstatus https://t.co/6zPu7wAqCj</p><h3>SVG LiveView 2</h3><h3>Michael on Twitter</h3><p>Built an SVG tool with @elixirphoenix LiveView with renders as you type. Handling user updates and server-side updates in the same module makes the code really cohesive. https://t.co/IQkNK6Jfae #myelixirstatus https://t.co/hvZClPfUqD</p><p><a href="https://github.com/mmmries/showoff/blob/master/lib/showoff_web/live/scratchpad_live.ex">mmmries/showoff</a></p><h3>Server-side calculator</h3><h3>Scott Meade on Twitter</h3><p>It&#39;s a server-side calculator. You know, just in case you didn&#39;t have one on your phone, or desk, or watch :) 88 lines of live view: https://t.co/YQGnjZM976 ... 40 lines html: https://t.co/lzuMRzcxzD ... #myelixirstatus #liveview Phoenix LiveView https://t.co/DA33cXzGVt</p><p><a href="https://github.com/smeade/phoenix_live_view_example/blob/master/lib/demo_web/live/calc_live/index.ex">smeade/phoenix_live_view_example</a></p><h3>Todos</h3><h3>Scott Meade on Twitter</h3><p>I&#39;ve created a Phoenix LiveView todos app based on Chris McCord&#39;s examples in the LiveView demo repo. #myelixirstatus https://t.co/mKKzNFiziP https://t.co/v8zDqNgoXE</p><p><a href="https://github.com/smeade/phoenix_live_view_example_todos">smeade/phoenix_live_view_example_todos</a></p><h3>Live Tinkering</h3><h3>M. Shemayev on Twitter</h3><p>Seriously. I know I am posting a ton about this trivial clock but like. Look at that. Live-rendered from the server, no JS on my part. EVERY. 1. MS. I had to literally film my laptop screen to get video where it was clear enough. Phoenix LiveView is not. kidding.</p><p><a href="https://github.com/aleph-naught2tog/live_tinkering">aleph-naught2tog/live_tinkering</a></p><h3>Word Game</h3><h3>Marko Honkanen on Twitter</h3><p>I made a quick toy app to try out Phoenix LiveView. No APIs or JavaScript was written and no frameworks learned. #elixirlang #phoenixframework #LiveView https://t.co/z8EUjzAFQR https://t.co/Ih3ofyJ9tH</p><h3>Re-computing and re-rendering over 200 rows</h3><h3>Geoffrey Lessel on Twitter</h3><p>Have you played with @elixirphoenix #LiveView yet? It&#39;s *INSANE*. This is a quick test app re-computing and re-rendering over 200 rows of data every 1/10 of a second. I wrote no JS code. Bravo @chris_mccord and team! #MyElixirStatus https://t.co/E1oEkje8Ji</p><h3>Table editor</h3><h3>Pierre Hurtevent on Twitter</h3><p>Table editor demo with Phoenix LiveView. Zero javascript, ~80 LOC, table data already available serverside! thanks @chris_mccord ! https://t.co/9DgUkXKYOw https://t.co/ttmnYY2BAG</p><p><a href="https://github.com/hurty/phoenix_live_view_example/blob/master/lib/demo_web/live/tables_live.ex">hurty/phoenix_live_view_example</a></p><h3>Adventure Capitalist clone</h3><h3>Eric Teubert on Twitter</h3><p>Had some fun with Phoenix LiveView by @chris_mccord. Built a simple &quot;Adventure Capitalist&quot; clone. I wrote only server-side code, zero lines custom JS. Rendering animations in 60fps because why not. #myelixirstatus https://t.co/2vEtxBUb4E</p><p><a href="https://github.com/eteubert/open_adventure_capitalist/blob/master/lib/open_adventure_capitalist_web/live/game_live.ex">eteubert/open_adventure_capitalist</a></p><h3>Push live updates</h3><h3>Sophie DeBenedetto on Twitter</h3><p>@elixirphoenix LiveView is *so easy* to use! Push live updates from the server with so little code and NO Javascript 💥 Built a little demo and it took &amp;lt;30min #myelixirstatus https://t.co/djrU9LO9HN</p><h3>ObserverLive</h3><h3>Dimitris Zorbas on Twitter</h3><p>I made a port of observer_cli for the web using LIveView. Demo: https://t.co/cvFS7QWWiW Source: https://t.co/ArYuKvEUkz #phoenix #liveview #myelixirstatus https://t.co/GYkUwCnzJP</p><p><a href="https://github.com/zorbash/observer_live">zorbash/observer_live</a></p><h3>Match game</h3><h3>Toran Billups on Twitter</h3><p>I deployed my first Phoenix LiveView app this morning and couldn&#39;t be more excited about the programming model! Source w/ tests for anyone interested https://t.co/eQVCAUFg38 huge thanks to @chris_mccord and @josevalim #myelixirstatus https://t.co/dRsYXHifbJ</p><p><a href="https://github.com/toranb/elixir-match/commit/bac39b8da84f3e672021e9d168589204a3a7682d">add live view for match game · toranb/elixir-match@bac39b8</a></p><h3>Side by side with Nodejs’ Socket IO</h3><h3>Gabriel Giordano on Twitter</h3><p>Elixir&#39;s Phoenix LiveView Framework side by side with Nodejs&#39; Socket IO each one into a Heroku free Dyno server #Elixir #Erlang #BEAM #PhoenixFramework #PhoenixLiveView https://t.co/iGYgNjPKt0</p><h3>BlackJack game</h3><h3>Dan Carlo Maglasang on Twitter</h3><p>Built a BlackJack game without using javascript! My first stab at using @elixirphoenix #LiveView. Just a POC so there may bugs :P . #myelixirstatus https://t.co/B4myOnEUHA</p><p><a href="https://github.com/dorilla/live_view_black_jack">dorilla/live_view_black_jack</a></p><h3>SeaBattle game</h3><h3>Alexander Tuktarov on Twitter</h3><p>At last I made SeaBattle game...without js! Thx to @chris_mccord and all #LiveView contributors. Repo: https://t.co/QsWOCzs0J3, example: https://t.co/xgqEoHbnF8 #myelixirstatus</p><p><a href="https://github.com/Sanchos01/Phoenix-Sea-Battle">Sanchos01/Phoenix-Sea-Battle</a></p><h3>Rubular clone</h3><h3>Clark Kampfe on Twitter</h3><p>last night I accidentally rebuilt Rubular in 30 lines of code #elixir #phoenixliveview https://t.co/riuzWkUG67</p><p><a href="https://github.com/ckampfe/rere/blob/master/lib/rere_web/live/rere_live.ex">ckampfe/rere</a></p><h3>Real-time chat</h3><h3>Cassius Pacheco on Twitter</h3><p>Had a look at some @elixirphoenix #LiveView examples online and ended up porting a (non-optimised) real-time chat to live view. Phoenix LiveView allows us to create real-time apps with no custom JS, impressive! Video: https://t.co/ZQlLjltp0c Code: https://t.co/tJeha9D8WJ</p><p><a href="https://github.com/CassiusPacheco/live_chat">CassiusPacheco/live_chat</a></p><h3>Live HTML/CSS</h3><h3>no one can protect anyone :) on Twitter</h3><p>Here is my idea on @elixirphoenix #LiveView feat. @tailwindcss (which i misspell in the video 😅). Yes, zero javascript and 28 LOC elixir 😌 https://t.co/MeHaNg0Zgw</p><h3>no one can protect anyone :) on Twitter</h3><p>This is the whole liveview code, super simple.</p><h3>Live IMU sensor</h3><h3>Login on Twitter</h3><p>Welcome back to Twitter. Sign in now to check your notifications, join the conversation and catch up on Tweets from the people you follow.</p><p><a href="https://github.com/joshnuss/live_imu">joshnuss/live_imu</a></p><h3>Bluetooth Low Energy HeartRate demo</h3><h3>Kenichiro Hamada on Twitter</h3><p>This is Phoenix LiveView BLE demo. LiveView sends BluetoothLE sensor data to server. It was hard for bigginer.. https://t.co/lh0ZKisghW #myelixirstatus https://t.co/eYyrCkn9hd</p><p><a href="https://github.com/khamada611/ble_live_sample">khamada611/ble_live_sample</a></p><h3>Real-time communication with Zoom API</h3><h3>KMAN on Twitter</h3><p>Real-time communication with Zoom API as well as participant filtering! #phoenixframework #liveview #elixir https://t.co/6ljEYiltip</p><h3>BreakoutEx (breakout clone)</h3><h3>Elixir LibHunt on Twitter</h3><p>BreakoutEx - A breakout clone written in pure Elixir, using Phoenix LiveView https://t.co/ss8Kix3Ay1</p><p><a href="https://github.com/neslinesli93/breakoutex">neslinesli93/breakoutex</a></p><h3>Bike comparison</h3><h3>Andriel Nuernberg on Twitter</h3><p>Bike comparison built with Phoenix LiveView. So cool! This certainly will change the way we develop web apps. #Elixir #MyElixirStatus #PhoenixLiveView https://t.co/uUzWh1ul2E</p><pre><a href="https://gist.github.com/andrielfn/6bbf0bf7fa644bfad304752bfae081f9">https://gist.github.com/andrielfn/6bbf0bf7fa644bfad304752bfae081f9</a></pre><h3>Calendar component</h3><h3>Nicolas Blanco on Twitter</h3><p>Full calendar component with days selection persisted in database &amp;amp; real time broadcasting to all clients. 0 lines of JavaScript. Only clean Elixir server-side code (view component is 69 LOC! : https://t.co/dOtn1qArn6). This is LiveView. A small revolution. Thanks @chris_mccord! https://t.co/1xpGoglJUN</p><p><a href="https://github.com/nicolasblanco/booking_calendar/blob/master/lib/booking_calendar_web/live/calendar_live.ex">nicolasblanco/booking_calendar</a></p><h3>Kubernetes dashboard</h3><h3>Dmitrii on Twitter</h3><p>Started building a personal Kubernetes dashboard with @elixirphoenix LiveView. No client side JS. Running on a real system (with obfuscated names). For video, https://t.co/q6jiDVSZ7a If I don&#39;t get discouraged or lazy, I will detail what I&#39;m doing in a blog post. Some day :) 1/ https://t.co/WyMx71EFt9</p><p><a href="https://github.com/dmitriid/phreak">dmitriid/phreak</a></p><h3>Markdown Live</h3><h3>Phoenix Framework on Twitter</h3><p>Check out the latest LiveView demo making the rounds: Markdown Live - 25 LOC LiveView which does real-time markdown generation. https://t.co/SXelIykSiV</p><p><a href="https://github.com/nickdichev/markdown-live">nickdichev/markdown-live</a></p><h3>Ant Farm</h3><h3>Ricardo García Vega on Twitter</h3><p>Last night I wanted to try out @elixirphoenix LiveView, and I created this small experiment consisting of a bunch of old school ants running around 😍(tutorial coming soon). #elixirlang #myelixirstatus https://t.co/hm9BsaVuJo https://t.co/nXlpgijrtj</p><p><a href="https://github.com/bigardone/phoenix-liveview-ant-farm">bigardone/phoenix-liveview-ant-farm</a></p><h3>UX keypad</h3><h3>Jose Esteves on Twitter</h3><p>I could rewrite a ux keypad (selection panel) without a line of js, it works great and it&#39;s easily reusable. Thanks @chris_mccord and Phoenix LiveView team https://t.co/MMm3Tp1ftt #MyElixirStatus https://t.co/gE4i8GKyDG</p><pre><a href="https://gist.github.com/ponyesteves/372cf186665ab464413096fd3855f0ca">https://gist.github.com/ponyesteves/372cf186665ab464413096fd3855f0ca</a></pre><h3>Chat App</h3><h3>Sophie DeBenedetto on Twitter</h3><p>Spent yesterday building a chat app with @elixirphoenix, #liveview and #phoenixpresence. The live view clocks in at 91 LOC, incl. message broadcasting and user presence tracking! Still reached for *some* JS to handle chat window UI. Blog coming soon! https://t.co/W0zWb3Xsj8 https://t.co/j3CvUKYPDH</p><p><a href="https://github.com/SophieDeBenedetto/phat">SophieDeBenedetto/phat</a></p><h3>Functional data structures</h3><h3>Zack Kayser on Twitter</h3><p>@MarlusSaraiva It is all LiveView with SVGs for the tree stuff and just a bit of CSS sprinkled in. It&#39;s not the best code I&#39;ve ever written, but here is a link to the tree drawing stuff if you&#39;re interested. https://t.co/FADuvDVeLi</p><p><a href="https://github.com/zkayser/pfds_visualizations">zkayser/pfds_visualizations</a></p><h3>RFID Reader</h3><h3>Tim Viaene on Twitter</h3><p>RFID Reader on Raspberry Pi Zero with Elixir, Nerves and Phoenix LiveView #MyElixirStatus https://t.co/am6paQz242</p><h3>LetterSoup Game (Boggle clone)</h3><h3>Martin Stannard on Twitter</h3><p>Had fun presenting https://t.co/LvFmCvrUYI, a game built with Phoenix LiveView at @ElixirSydney last night. #myelixirstatus Repo at https://t.co/9ooik255v1, slides at https://t.co/f1ksdIryIP</p><p><a href="https://github.com/martinstannard/soup">martinstannard/soup</a></p><h3>Keeping notes</h3><h3>João M. D. Moura on Twitter</h3><p>Decided to give Phoenix LiveView a try. I&#39;m building this tool that kinda helps me keeping notes of my meetings, and seemed like a good opportunity to use LiveView and @clearbit&#39;s API. Kodus to the @elixirphoenix team, didn&#39;t write 1 single line of JS to make this works https://t.co/jpCF0t13KB</p><h3>Collaborative Painting</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*CRZDtg5b9erLwzrHnmQjZw.png" /></figure><p><a href="https://stormy-earth-96381.herokuapp.com/collaborative_canvas">Demo</a></p><p><a href="https://github.com/JohnB/phoenix_live_view_example">JohnB/phoenix_live_view_example</a></p><h3>Game of Life</h3><h3>Sebastian Schuth on Twitter</h3><p>@chris_mccord @miladamilli @joerichsen My learning Friday project at @BetterDoc_org : Game of Life using Phoenix LiveView - no JS needed and so much fun to build! https://t.co/hbAIfv8g7Y</p><h3>Falling Tiles game</h3><h3>Angelika Tyborska on Twitter</h3><p>Look ma, no JavaScript! 🤸‍♀️ https://t.co/HVJ2N6al0u #Elixir #MyElixirStatus #PhoenixLiveView</p><p><a href="https://github.com/angelikatyborska/falling_blocks">angelikatyborska/falling_blocks</a></p><h3>Kanban board</h3><h3>Hubert Łępicki on Twitter</h3><p>Been playing with @elixirphoenix LiveView, building a simple kanban board with html5 drag and drop. Whole thing re-renders on each drop event (mine or other users). Pretty cool &amp;amp; snappy! https://t.co/6UsgwQY2dy</p><p><a href="https://github.com/amberbit/board">amberbit/board</a></p><h3>Table Filter</h3><ul><li><a href="https://medium.com/@imartinat/table-filter-with-phoenix-liveview-cb30508e9fc0">Table Filter with Phoenix LiveView</a></li><li><a href="https://github.com/imartinat/phoenix_live_view_tablefilter">imartinat/phoenix_live_view_tablefilter</a></li></ul><h3>Trivia Multiplayer</h3><h3>Rubén Amórtegui on Twitter</h3><p>Yay! #myelixirstatus #JustAnotherLiveViewSample . Trivia Multiplayer. @elixirphoenix @gigalixir https://t.co/x5bJcLVeHq https://t.co/q2J9y3OJmI https://t.co/PrMCP0dlO0</p><p><a href="https://github.com/ramortegui/phoenix_trivia">ramortegui/phoenix_trivia</a></p><h3>Monitoring dashboard</h3><h3>Kerry Buckley on Twitter</h3><p>Converted a monitoring dashboard to Live View. Even the progress bar, collapsing panels and modals are server-rendered. #myElixirStatus https://t.co/9LrEseIH22</p><h3>Multi-step Form</h3><h3>Markus Bodner on Twitter</h3><p>Took some time yesterday to see if @elixirphoenix live view could be used for a multi-step from I have in mind for @newsletty. Its looking very promising. Check out the video. I didn&#39;t have to write any JavaScript myself for that result. https://t.co/VvGG9r3lET</p><p><a href="https://github.com/tuacker/phoenix_live_view_form_steps/">tuacker/phoenix_live_view_form_steps</a></p><h3>Piano roll</h3><h3>Thibaut Barrère on Twitter</h3><p>myelixirstatus a bit of LiveView training this morning. This one generates a SVG dynamically, and the server updates the current note. Part of a larger musical project. https://t.co/JLaguRirWF</p><h3>Star Polygon demo</h3><h3>Kyle Oba on Twitter</h3><p>Just cooked up this @elixirphoenix LiveView regular star polygon demo https://t.co/tH651safSc . Wanted to play with #LiveView and help out some math friends. #myelixirstatus</p><h3>HackerNews clone</h3><h3>Ashish Wadekar on Twitter</h3><p>Built a realtime smallish clone of HackerNews using #PhoenixFramework in about ~100 LoC Kudos to @chris_mccord @josevalim &amp;amp; Elixir community #Phoenix #Elixir #Erlang #BEAM #PhoenixLiveView #myelixirstatus https://t.co/bfpbhS6ueU</p><p><a href="https://github.com/ashishwadekar/live_hacker_news">ashishwadekar/live_hacker_news</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8259f35ff2b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to update objects inside JSONB arrays with PostgreSQL]]></title>
            <link>https://medium.com/free-code-camp/how-to-update-objects-inside-jsonb-arrays-with-postgresql-5c4e03be256a?source=rss-77fa428a9fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c4e03be256a</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Leandro Cesquini Pereira]]></dc:creator>
            <pubDate>Mon, 15 Apr 2019 15:48:55 GMT</pubDate>
            <atom:updated>2019-04-15T15:48:55.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TyYEPUBI96D1NDh4" /><figcaption>Photo by <a href="https://unsplash.com/@jankolar?utm_source=medium&amp;utm_medium=referral">Jan Antonin Kolar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>How to update a specific value on a JSONB array</h3><p>Let’s say you decided to store data in the database as json or jsonb and discovered that you just created new problems for yourself that you didn’t have before. You’re not alone.</p><p>JSONB is a powerful tool, but it comes at some cost because you need to adapt the way you query and handle the data.</p><p>And it’s not rare to load the entire jsonb object into memory, transform it using your preferred programming language, and then saving it back to the database. But, you just created another problem: performance bottlenecks and resource waste.</p><p>In this article let’s see how to update a specific value of an object inside an array with one query.</p><p><strong>TL;DR</strong>: the final query is at the end of the article, and you can check out a live example at <a href="https://www.db-fiddle.com/f/e8aeGk7cRNYnpjsqi1ncrs/1">DB Fiddle</a> to copy &amp; paste and play with.</p><p>Suppose you’re implementing a customer screen to store dynamic contacts for each customer. Then you come up with the idea of storing the contacts as a JSONB column because they’re dynamic, and thus using a not relational data structure makes sense.</p><p>Then you create a customers table with a JSONB contacts column and insert some data into it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*tEwADUkdxHOOr94sZlhOgA.png" /></figure><p>Pretty easy right? But how can you update a specific contact for a specific customer? How to change Jimi&#39;s email or Janis’ phone? 🤔</p><p>Fortunately, PostgreSQL is your friend and provides the <em>jsonb_set</em> function:</p><p><em>jsonb_set(target jsonb, path text[], new_value jsonb[, create_missing boolean])</em></p><p>Given a jsonb column, you can set a new value on the specified path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*hwvzDaimP64atkrANan0ZQ.png" /><figcaption>Reference: <a href="https://www.postgresql.org/docs/9.5/functions-json.html">PostgreSQL Json functions</a></figcaption></figure><p>The above selects will return:</p><pre>[{“type”: “phone”, “value”: “+1–202–555–0105”}, {“type”: “email”, “value”: “jimi.hendrix@gmail.com”}]</pre><pre>[{“type”: “email”, “value”: “janis.joplin@gmail.com”}]</pre><p>To change Jimi&#39;s email on the contacts list, you inform the path &quot;<strong>1, value&quot; </strong>which means the second object on the array (starting at 0) and the key <strong>value</strong>. That&#39;s the <em>path</em>. The same applies to change Janis’ email, but its email object is at index 0.</p><p>You may be thinking: I just have to use jsonb_set on an update statement and it’s all done? That’s the idea, but that’s not enough yet.</p><p>The problem with non-relational data is that they’re dynamic. Well, that’s one of the reasons for using JSONB but that brings a problem: see that Jimi’s email object is at index 1 and Janis’ email object is at index 0 on the array, and another customer could have a very different array with different indexes. So, how can you discover the index of each contact type? 🤔</p><p>The answer is ordering the elements of the array and getting its index:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*ksanX9kkOJjcU3_Nqr3aCA.png" /></figure><p>That query returns <strong>1</strong>, which is the <em>index</em> of the <em>email object (type email) </em>inside the contacts array of the customer Jimi.</p><p>Now we have all the pieces of the puzzle: we know how to update a jsonb value and how to discover the index of the object to be updated.</p><p>The only step left is the update itself. Putting it all together we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*6PLoy-DeP40P7Yg0WeqZhQ.png" /></figure><p>The most important part of this query is the <em>with</em> block. It&#39;s a powerful resource, but for this example, you can think of it as a &quot;way to store a variable&quot; that is the <em>path</em> of the contact you need to update, which will be dynamic depending on the record.</p><p>Let me explain a bit about this part:</p><pre>(‘{‘||index-1||’,value}’)::text[] as path</pre><p>It just builds the path as <em>&#39;{1, value}&#39;</em>, but we need to convert to <em>text[]</em> because that’s the type expected on the <em>jsonb_path</em> function.</p><h4>Wrapping up</h4><p>JSONB is a great and valuable tool to resolve a lot of problems. But keep in mind that you also need to query and update this kind of data. That brings a cost that you have to consider when deciding which tools you pick to use.</p><p><em>Side note: that solution came out of a pair programming session with </em><a href="https://medium.com/u/e9a6be9e7f4b"><em>Lucas Cegatti</em></a><em>.</em></p><p><em>Are you looking for a creative company to implement your next idea? Check out </em><a href="https://lnasystems.com.br/"><em>LNA Systems</em></a><em> and let’s talk.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c4e03be256a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-update-objects-inside-jsonb-arrays-with-postgresql-5c4e03be256a">How to update objects inside JSONB arrays with PostgreSQL</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Bounded Contexts in Elixir]]></title>
            <link>https://medium.com/@leandrocesquini/implementing-bounded-contexts-in-elixir-25bb8a80bbca?source=rss-77fa428a9fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/25bb8a80bbca</guid>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[bounded-context]]></category>
            <dc:creator><![CDATA[Leandro Cesquini Pereira]]></dc:creator>
            <pubDate>Thu, 25 Oct 2018 12:48:39 GMT</pubDate>
            <atom:updated>2019-03-29T14:33:01.917Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9ed1LDFyGhI6_hZf" /><figcaption>“three birds flying in the sky” by <a href="https://unsplash.com/@eryk9o9?utm_source=medium&amp;utm_medium=referral">Erik Kossakowski</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><em>What if we could write loose coupling services without the overhead of common microservices architecture? </em>In 2015 Valim wrote an article entitled <a href="http://blog.plataformatec.com.br/2015/06/elixir-in-times-of-microservices/">Elixir in times of microservices</a>, where he elaborated his idea on how Elixir fits in a microservice architecture. That’s the kind of mind-blowing post that challenges us to experiment different ways to write software, and that post is my practical approach on this matter.</p><p><strong>TL;DR</strong></p><ul><li>Create an umbrella project;</li><li>One app for each bounded context;</li><li>An app should never call internal code from another app;</li><li>Use a module on each app to act as a public API to exchange data between apps, and also to call functions to mutate data;</li><li>An app should never return its internal data structures on public apis, it should return only raw data like <em>maps</em> and <em>lists</em>;</li></ul><p><em>Edit: </em>Check out the comments section, which has great questions and more discussion about the details of the whole idea. And by the way, thanks for the comments :)</p><h3>First of all, what&#39;s a Bounded Context ?</h3><p><em>If you know nothing about it, I recommend to read </em><a href="https://martinfowler.com/bliki/BoundedContext.html"><em>this Martin Fowler article</em></a><em> before continuing.</em></p><p>According to the great book <a href="https://pragprog.com/book/swdddf/domain-modeling-made-functional">Domain Modeling Made Functional</a>:</p><blockquote>[…] domains and subdomains in the problem space are mapped to what DDD terminology calls bounded contexts — a kind of subsystem in our implementation. Each bounded context is a mini domain model in its own right. We use the phrase bounded context instead of something like subsystem because it helps us stay focused on what’s important when we design a solution: being aware of the context and being aware of the boundaries.</blockquote><blockquote>Why context? Because each context represents some specialized knowledge in the solution. Within the context, we share a common language and the design is coherent and unified. But, just as in the real world, information taken out of context can be confusing or unusable.</blockquote><blockquote>Why bounded? In the real world, domains have fuzzy boundaries, but in the world of software we want to reduce coupling between separate subsystems so that they can evolve independently. We can do this using standard software practices, such as having explicit APIs between subsystems and avoiding dependencies such as shared code.</blockquote><p>That give us some hints on how we should implement a bounded context:</p><ul><li>Should be independent</li><li>Should have an explict API to exchange data</li><li>Avoid shared code</li></ul><figure><a href="https://blog.usejournal.com/meet-journal-d222fce8db1d"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PMBwoU5bWkso8M2A1ocS9Q.png" /></a></figure><h3>Umbrella Projects</h3><p>If you know the concept of <a href="https://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-projects.html#umbrella-projects">umbrella projects,</a> you may be thinking that we can implement each bounded context as applications of an umbrella project. And you&#39;re right, but some rules are required in order to keep clean organization and avoid creating a mess that is hard to evolve.</p><p>But what&#39;s an umbrella project and apps ?</p><p>An app is just a package of code, it could be a tiny library, a component, a subsystem or a full application. An ERP system can be composed of apps like Customer, Billing, Delivery and so on.</p><p>And an umbrella project is a project composed of those apps, which lives in the same project and can be dependent on each other.</p><p>Want to read more about it ? Go to <a href="https://8thlight.com/blog/georgina-mcfadyen/2017/05/01/elixir-umbrella-projects.html">Using an Elixir Umbrella</a> post.</p><h3>Show me the code</h3><p>Enough talking, let&#39;s see how it works. And let&#39;s use the same example from Martin Fowler article to establish an example that we can use for our system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*mwP59Yo9SW_r2rybDTOvng.png" /><figcaption>Bounded Context example from Martin Fowler article</figcaption></figure><p>In this example we have 2 bounded contexts, <em>Sales</em> and <em>Support, </em>with their own rules and knowledge. Remember that each context should be independent, so let&#39;s start by creating a new Elixir umbrella project called &quot;SystemX&quot; with two apps:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33bd3882b80b7992a1b5f6409b6623bf/href">https://medium.com/media/33bd3882b80b7992a1b5f6409b6623bf/href</a></iframe><p>You’ll end up with the following directory structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c1c501ce1846fa18b9c5c2f14dbccae/href">https://medium.com/media/3c1c501ce1846fa18b9c5c2f14dbccae/href</a></iframe><h4>Entities</h4><p>As you can see in our domain, we have the entity Customer on both Sales and Support context. That&#39;s because each context may have specific rules or data and evolve independently, which give us leverage to modify each one of them without breaking the whole system, because it&#39;s limited to the inner context.</p><p>Let&#39;s define each Customer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7befb34c5d9c1d6afdace695c5fb9de/href">https://medium.com/media/e7befb34c5d9c1d6afdace695c5fb9de/href</a></iframe><h4>Public API</h4><p>And what happens if the Sales context needs to get some information from the Customer on the Support context ? That&#39;s when the explict API comes in handy. Let&#39;s say we need to know if a Customer has a support ticket, then we need to ask this information for the Support context. So, let&#39;s create the Support explicit API to return a Customer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79ba2a04a2047e828d982f383c58a8f0/href">https://medium.com/media/79ba2a04a2047e828d982f383c58a8f0/href</a></iframe><p>Returning a <em>map</em> instead of a <em>struct</em> is what give us loose coupling between apps. We will talk more about it in a moment.</p><h4>Putting into practice</h4><p>Now, let’s create a service in the Sales context that calculates the current customer’s score. The business rule is: It gives a higher score if the customer has no ticket support (<em>I know it’s not the best example in the world…</em>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fae0a627d0f575496426917683715f0/href">https://medium.com/media/7fae0a627d0f575496426917683715f0/href</a></iframe><p>Ok, there&#39;s more than just a simple service. Let me explain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*-vli0_gjVVuOyZtLjpqGGw.png" /><figcaption>Apps are allowed to comunicate with each other only by a public API. Boxes in gray are for internal use only.</figcaption></figure><p>A Customer entity in the Sales context knows nothing about support tickets, as expected because this information is of responsability of the Support context, however we need it to build our service <em>Sales.Service.Customer</em>.</p><p>To overcome this lack of information in the Sales context we can ask the Support context for this information, but remember that we can&#39;t share code between apps nor call internal code from another app. That&#39;s the objective of a public API and the reason it can only return raw data like <em>maps</em> and <em>lists </em>instead of returning an internal <em>struct</em> from Support app.</p><p>But we don&#39;t want a meaningless <em>map </em>being used internally in Sales app, we actually want that our domain reflect the real life by mapping it to a <em>struct</em>, which is done in <em>Sales.Client.Support —</em> receives a <em>map, </em>use the information it needs and fullfill <em>Sales.Domain.Customer</em>. Note that in <em>Sales.Domain.Customer</em> we don&#39;t keep the attribute <em>last_ticket_id </em>because we don&#39;t care about the actual ticket id in the Sales context, we just need to know if it&#39;s empty or not. Remember that the same entity from the real world may have different attributes according to the context.</p><p>Converting the data structure on the boundaries makes the <em>service layer</em> cleaner and easier to write and understand because in layers below the public API we deal with validated data structures prepared for the current context, which means you don&#39;t need to worry with dirty data, which frees us from writing conditional code.</p><h4>Maintenance</h4><p>And there&#39;s one more reason to do this kind of data convertion on the boundary: maintenance.</p><p>What would happen if you used the <em>struct</em> <em>Support.Domain.Customer</em> all over your Sales context in services, domain, tests and so on… and for some reason you had to rename the attribute <em>last_ticket_id</em> to any other name ? Yeah, that&#39;s right… you&#39;d have to change a lot of code. But using a client allows you to handle this scenario in the client while keeping the <em>struct</em> <em>Sales.Domain.Customer</em> exactly the same, avoiding a major refactor. Just the client layers changes. It&#39;s a simple example but I think it&#39;s enough to get the ideia.</p><p><em>How to organize the internal context code is not in the scope of this article.</em></p><h4>Contract</h4><p>You may be wondering: if the public API returns a <em>map</em>, how can I know the content (contract) of this <em>map</em> ? Which attribures are present or not, which data type I should expect and so on ? And how can I know if the call was successful ? The answer is: use <a href="https://hexdocs.pm/elixir/typespecs.html">Typespecs</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40e6ad3e903ad2789ea44da4b2883976/href">https://medium.com/media/40e6ad3e903ad2789ea44da4b2883976/href</a></iframe><p>Typespecs is about transparency. You know what to expect from calling the function and also what that function expects as parameter. And it also has the advantage to generate an useful documentation using <a href="https://github.com/elixir-lang/ex_doc">ex_doc</a> library or even a live documentation by using text editors that supports that.</p><p>However it does not enforce an &quot;automatic data validation&quot;, that means you can pass an <em>Integer</em> even if the typespec says that it&#39;s expecting an <em>String</em>. To assist you in the task of obeying the contract, I recommend using <a href="https://github.com/jeremyjh/dialyxir">Dialyxir,</a> that tool will do a static code analysis and warn you if anything is out of expected.</p><h3>When should I use an umbrella app ?</h3><p>Putting everything inside just one app or splitting each part into umbrella apps is a question of balance and following some rules. Creating many apps may be overkill, but it’s worth considering creating a new app in some cases:</p><ul><li>That part of the system is developed by another team, be it an internal or offshore team in the same company or an outsourced team.</li><li>That part of the system is shared between more than one app. That’s a more common scenario for shared libs.</li><li>That part of the system needs to be deployed separately in another server or in a different permission schema (some are public and some are private). — <a href="https://hexdocs.pm/distillery/introduction/understanding_releases.html">Distillery releases</a> can help you with that.</li><li>Need to use more than one framework in the same system.</li></ul><p>Everything else can live in the same app perfectly.</p><h3>A note about umbrella projects</h3><p>An umbrella project may get out of control if you don&#39;t follow some rules like we discussed here. Think in each app as being isolated, ie: you can remove it from umbrella without breaking too many things. That&#39;s the reason we can&#39;t call internal functions from another app and need to rely on a public API.</p><p>There&#39;s nothing in Elixir that forbids or prevents you from calling internal code from another app, instead of only using the public API. That&#39;s a convention you&#39;d have to adopt and always review the code to not break this rule.</p><p>Another commom issue with umbrella projects is circular dependencies that happens when app A depends on app B and for some reason you also try to make B depends on A. Then you get a circular dependency error. You have to carefully design the <a href="https://markhneedham.com/blog/2009/03/30/ddd-recognising-relationships-between-bounded-contexts/">relationship between your bounded contexts</a> to avoid this situation.</p><p>Another observation it that not everybody likes working with umbrella projects, and that&#39;s fine. The same ideia and rules applies if you work with separated apps.</p><p>Summing up, umbrella project sits between monolithic and microservices. And if done right, you gain the best of both worlds.</p><h3>Bonus: distributed apps</h3><p>Umbrella project is a good way to start a new project and get things running, but it has <a href="https://elixir-lang.org/getting-started/mix-otp/dependencies-and-umbrella-projects.html#dont-drink-the-kool-aid">known issues</a> that may cause problems in the future. But don&#39;t worry too much about it because the approach discussed here can evolve to break apart those apps into distributed apps by implementing each public API as a GenServer, which can be global registered using tools like <a href="https://github.com/bitwalker/swarm">Swarm</a> or <a href="https://github.com/derekkraan/horde">Horde</a>. But that&#39;s subject to another post, let me know if you want to hear more about it.</p><h3>What I didn&#39;t say</h3><p>Domain Types, Anti-Corruption Layers, CQRS, DTOs, Sagas, CRDT and some other techniques and patterns can be useful in this kind of architecture, but I can&#39;t talk about everything in just one article and you <a href="https://en.wikipedia.org/wiki/Fundamental_theorem_of_software_engineering">may not need all of it</a>. Keep in mind the first and most important step is to organize your project to enable it to evolve in a agile way.</p><p>Thanks <a href="https://medium.com/@eduardodeoh/">Eduardo Hernandes</a> for the hours discussing Elixir, DDD and some crazy stuff and also for reviewing this article.</p><p><em>Looking for a creative company to implement your next idea ? Check out </em><a href="http://lnasystems.com.br/"><em>LNA Systems</em></a><em> and let’s talk.</em></p><figure><a href="https://blog.usejournal.com/meet-journal-d222fce8db1d"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25bb8a80bbca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elixir — quick reference for debugging techniques]]></title>
            <link>https://medium.com/@leandrocesquini/elixir-quick-reference-for-debugging-techniques-8dad3920ab93?source=rss-77fa428a9fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dad3920ab93</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Leandro Cesquini Pereira]]></dc:creator>
            <pubDate>Thu, 17 May 2018 15:41:38 GMT</pubDate>
            <atom:updated>2019-03-29T14:34:32.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WDt7iNokH2BqSimb." /><figcaption>“Red and black beetle climbs on purple plants in the wild” by <a href="https://unsplash.com/@mahdishakhesi?utm_source=medium&amp;utm_medium=referral">Mahdi Shakhesi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://elixir-lang.org/getting-started/debugging.html">Much</a> <a href="http://blog.plataformatec.com.br/2016/04/debugging-techniques-in-elixir-lang/">has</a> <a href="https://speakerdeck.com/gcauchon/debugging-elixir-efficently">been</a> said about Elixir debugging techniques, but in this post, I’d like to give a quick overview of all possible options to serve as a go-to reference when you need to debug Elixir code. Enough talking, let’s check each of them:</p><h3><strong>IO.inspect</strong></h3><p>The simplest technique:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0456bbf42426e2f6b65763cf2046657/href">https://medium.com/media/b0456bbf42426e2f6b65763cf2046657/href</a></iframe><p><a href="https://hexdocs.pm/elixir/IO.html#inspect/2">IO.inspect/2</a>can also be used inside pipelines because <a href="https://github.com/elixir-lang/elixir/blob/v1.6.5/lib/elixir/lib/io.ex#L311">it returns the item passed to be inspected</a>. And the tip here is to use the option label:to output a string identifying each inspect:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3186dd0cfa44fa1906a4201b85683932/href">https://medium.com/media/3186dd0cfa44fa1906a4201b85683932/href</a></iframe><h3><strong>IO.inspect with binding</strong></h3><p><a href="https://hexdocs.pm/elixir/Kernel.html#binding/1">binding/1</a> is very useful when you want to see all variable names and values of the current function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd83f1d6f8e0b335aafeee2ece545542/href">https://medium.com/media/bd83f1d6f8e0b335aafeee2ece545542/href</a></iframe><h3><strong>apex</strong></h3><p>Similar to IO.inspect/2, <a href="https://github.com/BjRo/apex">apex</a> is a lib worth mentioning especially because of its <a href="https://github.com/BjRo/apex#awesome-def-aka-adef">adef</a> macro:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba3c52d93fbd8bdbcb3b2cbe440114ef/href">https://medium.com/media/ba3c52d93fbd8bdbcb3b2cbe440114ef/href</a></iframe><h3><strong>IEx.pry</strong></h3><p>But it can be very tedious and be limiting to debug with just data inspection likeIO.inspect or apex, that&#39;s when <a href="https://hexdocs.pm/iex/IEx.html#pry/0">IEx.pry/0</a> comes at hand because it allows you to pry into the current code. Put the following code at the line you want to pry:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86a79ca53d3516ae49e7fa727f28ccb7/href">https://medium.com/media/86a79ca53d3516ae49e7fa727f28ccb7/href</a></iframe><p>And now execute your code inside an IEx session: iex -S mix or iex -S mix phx.server if you are using Phoenix Framework. Tip: if you are running tasks like database seeds, you can pry into that code by running iex -S mix run priv/repo/seeds.exs or any other script.</p><p>Once the code execution gets to the point of IEx.pry , an interactive shell opens and allow you to interact with the current code.</p><p>Go to <a href="https://medium.com/@diamondgfx/debugging-phoenix-with-iex-pry-5417256e1d11">Debugging Phoenix with IEx.pry</a> if you want more tips about debugging Phoenix with IEx.pry.</p><h3><strong>:debugger</strong></h3><p>Pretty much the same as IEx.pry which stops the execution at the break point and allows you to inspect the current code, but <a href="http://erlang.org/doc/apps/debugger/debugger_chapter.html">:debugger</a> gives you a nice visual interface, like the ones in IDEs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*eeiDpGhDrSw9EiQTFlqzDw.gif" /><figcaption>gif from <a href="http://blog.plataformatec.com.br/2016/04/debugging-techniques-in-elixir-lang/">http://blog.plataformatec.com.br/2016/04/debugging-techniques-in-elixir-lang/</a></figcaption></figure><p>To open this debugger, you need to start it and set a break point:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4374ea4a53bed97d20d387f71fa8a1a/href">https://medium.com/media/c4374ea4a53bed97d20d387f71fa8a1a/href</a></iframe><h3><strong>:sys.get_state and :sys.get_status</strong></h3><p>This one works only for processes. As the name suggests, <a href="http://erlang.org/doc/man/sys.html#get_state-1">:sys.get_state/1</a>gets the current state of a process, and not only from a GenServer but also from any kind of process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0157cbda02a55466d753b02532de5a54/href">https://medium.com/media/0157cbda02a55466d753b02532de5a54/href</a></iframe><p>Snippet extracted from <a href="https://til.hashrocket.com/posts/urmxev1dh5-looking-at-the-state-of-processes-in-elixir">Looking at the state of processes in Elixir</a>.</p><p>If you need more data than just the current state, just call <a href="http://erlang.org/doc/man/sys.html#get_status-1">:sys.get_status/1</a> , which will return whole process information:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68c62aefa8e8361972b784a144381536/href">https://medium.com/media/68c62aefa8e8361972b784a144381536/href</a></iframe><p>Snnipet extracted from <a href="https://pragprog.com/book/elixir/programming-elixir">Programming Elixir book</a>.</p><p>Bonus: you can replace a process state at runtime using <a href="http://erlang.org/doc/man/sys.html#replace_state-2">:sys.replace_state/2</a> , which can be very handy to test some specific situation.</p><h3>Process.info</h3><p>You can also use <a href="https://hexdocs.pm/elixir/Process.html#info/1">Process.info/1</a> to get information about a specific process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fc798a9a23af8a1342d83d09eea1ce1/href">https://medium.com/media/5fc798a9a23af8a1342d83d09eea1ce1/href</a></iframe><h3><strong>:sys.trace</strong></h3><p>Still talking about process debug, another resource we have is <a href="http://erlang.org/doc/man/sys.html#trace-2">:sys.trace/2</a>to trace process calls, which will display each call and state change of the calling process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4146200b2cdc315c87a735184d2380f0/href">https://medium.com/media/4146200b2cdc315c87a735184d2380f0/href</a></iframe><h3><strong>Distillery commands</strong></h3><p>After you deploy your application as a package release, it may be very helpful to get information about it, specially if something is not working as expected. If you have deployed using <a href="https://github.com/bitwalker/distillery">Distillery</a>, you&#39;ll soon discover that mix does not work the same way as in your local machine, and that&#39;s expected. But you can execute some commands on that release by calling bin/&lt;app_name&gt; &lt;command&gt; , the two more useful commands are: remote_console to start an IEx session on the running release and help to give you a list of all <a href="https://github.com/bitwalker/distillery/tree/1.5.2/priv/libexec/commands">commands</a>.</p><h3><strong>:observer</strong></h3><p>Although it&#39;s not exactly a debug tool, it&#39;s worth mentioning that <a href="http://erlang.org/doc/man/observer.html">:observer</a> helps you get an overview of the running system. I&#39;ll not dig into details because there are a lot of articles that already do that, so I&#39;ll just leave here the function call to start the observer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82dceb9bc65e8abc62fafed6ef772e91/href">https://medium.com/media/82dceb9bc65e8abc62fafed6ef772e91/href</a></iframe><p><strong>Notes and sources</strong></p><p>If you have more tips and techniques, please leave a comment so I can update this post and help spread more Elixir knowledge. :)</p><p>Some code snippets were extracted from the great official documentation or from the <a href="https://elixir-lang.org/getting-started/introduction.html">official getting started tutorial</a>.</p><p>The book <a href="https://pragprog.com/book/elixir/programming-elixir">Programming Elixir</a> was also used as source.</p><p>The <a href="https://til.hashrocket.com/">Today I Learned</a> from Hashrocket is also a great source of tips.</p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more product &amp; design stories featured by the <a href="https://usejournal.com/?utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><p><em>Looking for a creative company to implement your next idea ? Check out </em><a href="http://lnasystems.com.br/"><em>LNA Systems</em></a><em> and let’s talk.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dad3920ab93" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>