<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Elixir on Justin B Kay's Blog</title><link>https://blog.jbkconsultingllc.com/tags/elixir/</link><description>Recent content in Elixir on Justin B Kay's Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Thu, 04 Jan 2024 14:42:55 -0700</lastBuildDate><atom:link href="https://blog.jbkconsultingllc.com/tags/elixir/index.xml" rel="self" type="application/rss+xml"/><item><title>Updating deeply nested elixir maps</title><link>https://blog.jbkconsultingllc.com/posts/updating-deeply-nested-elixir-maps/</link><pubDate>Thu, 04 Jan 2024 14:42:55 -0700</pubDate><guid>https://blog.jbkconsultingllc.com/posts/updating-deeply-nested-elixir-maps/</guid><description>&lt;p&gt;In some cases it is necessary to update a deeply nested attribute in a map. I went searching for a way to do this and came across several approaches, the one that worked for me was this, a combination of &lt;a href="https://hexdocs.pm/elixir/Kernel.html#put_in/2"&gt;Kernel.put_in&lt;/a&gt; and &lt;a href="https://hexdocs.pm/elixir/1.12.3/Access.html#key/2"&gt;Access.key&lt;/a&gt;, here I&amp;rsquo;m using it to update a socket struct nested assigns map.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-elixir" data-lang="elixir"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;put_in(socket, &lt;span style="color:#a6e22e"&gt;Enum&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;map([&lt;span style="color:#e6db74"&gt;:assigns&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;:beacon_live_data&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;:form_submitted&lt;/span&gt;], &lt;span style="color:#f92672"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;Access&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;key(&amp;amp;1, %{})), &lt;span style="color:#66d9ef"&gt;true&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The put_in function is pretty easy to understand, it &lt;code&gt;Puts a value in a nested structure via the given path&lt;/code&gt;. The tricky bit is the path.&lt;/p&gt;</description></item><item><title>Decoding TypeORM-Encrypted Data With Elixir</title><link>https://blog.jbkconsultingllc.com/posts/decoding-typeorm-encrypted-data-with-elixir/</link><pubDate>Sun, 21 Nov 2021 15:17:26 -0700</pubDate><guid>https://blog.jbkconsultingllc.com/posts/decoding-typeorm-encrypted-data-with-elixir/</guid><description>&lt;p&gt;Today&amp;rsquo;s challege was to figure out how to decrypt an encrypted field created by the TypeORM plugin &lt;a href="https://www.npmjs.com/package/typeorm-encrypted"&gt;typeorm-encrypted&lt;/a&gt;. Typeorm-encrypted allows you to automatically encrypt/decrypt a field on save/fetch when using TypeORM. This allows you to encrypt sensitive data while at rest in your database.&lt;/p&gt;
&lt;p&gt;The Typeorm-encrypted module saves the encrypted (aes-256-gcm) field as a Base64 encoded string in the database. Our challege is to be able to read that field from our database and decrypt the sensitive data for use in our Elixir application.&lt;/p&gt;</description></item></channel></rss>