<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://lanadz.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://lanadz.com/" rel="alternate" type="text/html" /><updated>2026-01-09T19:03:07+00:00</updated><id>https://lanadz.com/feed.xml</id><title type="html">TIL and Other Bugs</title><subtitle>Lana (Svitlana Dzyuban) - Software Engineer. &quot;TIL and Other Bugs&quot; is a place to collect and share gotchas, ideas, usuful bits, and have a little fun.</subtitle><entry><title type="html">Rust TIL</title><link href="https://lanadz.com/2026/01/05/rust.html" rel="alternate" type="text/html" title="Rust TIL" /><published>2026-01-05T00:00:00+00:00</published><updated>2026-01-05T00:00:00+00:00</updated><id>https://lanadz.com/2026/01/05/rust</id><content type="html" xml:base="https://lanadz.com/2026/01/05/rust.html"><![CDATA[<p>Today I had to deal with dependency vulnerability - <code class="language-plaintext highlighter-rouge">rkyv</code> for <a href="https://docs.rs/rust_decimal/latest/rust_decimal/">rust_decimal</a></p>

<p>TLDR;</p>

<blockquote>
  <p>rkyv vulnerability in transitive dependency via rust_decimal 1.39.0. rust_decimal is at latest version and hasn’t updated to rkyv 0.8.x yet. Will be fixed when rust_decimal updates.</p>
</blockquote>

<p>https://github.com/paupino/rust-decimal/issues/766</p>

<p>Cool, but now what? Do I need to wait for a fix (it’s a new year, people might still celebrating lol) Do I need to open pr just to add reason to <code class="language-plaintext highlighter-rouge">audit.toml</code>?</p>

<p>I ended up creating <code class="language-plaintext highlighter-rouge">audit.toml</code> with that ignore entry, since we are not even using <code class="language-plaintext highlighter-rouge">rkyv</code> and it is optional dependency. But as I am writing this I already see that patch to <code class="language-plaintext highlighter-rouge">rkyv</code> was <a href="https://github.com/rkyv/rkyv/pull/645">merged</a>, so I probably won’t need any <code class="language-plaintext highlighter-rouge">audit.toml</code>.</p>

<p>And T.I.L is:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">cargo audit</code>
<code class="language-plaintext highlighter-rouge">cargo install cargo-audit</code> is required for that. We have <code class="language-plaintext highlighter-rouge">cargo audit</code> step in CI to show vulnerabilities. Awesome tool</li>
  <li>there is such thing as <a href="https://github.com/paupino/rust-decimal/blob/master/Cargo.toml#L33">optional features</a> in dependecies</li>
</ul>

<div class="language-toml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">[dependencies]</span>
<span class="nn">rkyv</span> <span class="o">=</span> <span class="p">{</span> <span class="py">default-features</span> <span class="p">=</span> <span class="kc">false</span><span class="p">,</span> <span class="py">features</span> <span class="p">=</span> <span class="p">[</span><span class="s">"size_32"</span><span class="p">,</span> <span class="s">"std"</span><span class="p">],</span> <span class="py">optional</span> <span class="p">=</span> <span class="kc">true</span><span class="p">,</span> <span class="py">version</span> <span class="p">=</span> <span class="s">"0.7.42"</span> <span class="p">}</span>
</code></pre></div></div>

<ul>
  <li><code class="language-plaintext highlighter-rouge">cargo tree</code> Display a dependency graph
    <ul>
      <li>
        <p><code class="language-plaintext highlighter-rouge">cargo tree -p rust_decimal -e features</code>
This will show you all dependecies for the package, and that packach will be a root (<code class="language-plaintext highlighter-rouge">-p</code>) and <code class="language-plaintext highlighter-rouge">-e</code> what kind of dependencies to show: features, build, all, etc.</p>
      </li>
      <li>
        <p><code class="language-plaintext highlighter-rouge">cargo tree -i rust_decimal</code>. Inverts the tree and focuses on given package. It will show you if you have crate installed. In my case, I would have something like:</p>
      </li>
    </ul>
  </li>
</ul>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rust_decimal v1.39.0
├── my_proj v0.19.0 (path/path/path)
│   └── more path entries
└── more entries (/path/path)
</code></pre></div></div>

<p>and if I try <code class="language-plaintext highlighter-rouge">cargo tree -i rkyv</code> - since I don’t have it installed directly - no root to display 😊</p>

<ul>
  <li>and rust community is awesome and helpful, I spent only couple minutes to find the problem, and the issue was already created and people were addressing it only after couple hours since vulnerability was reported. Nice!!</li>
</ul>]]></content><author><name></name></author><category term="rust" /><summary type="html"><![CDATA[Today I had to deal with dependency vulnerability - rkyv for rust_decimal]]></summary></entry><entry><title type="html">AI</title><link href="https://lanadz.com/2025/11/30/ai.html" rel="alternate" type="text/html" title="AI" /><published>2025-11-30T00:00:00+00:00</published><updated>2025-11-30T00:00:00+00:00</updated><id>https://lanadz.com/2025/11/30/ai</id><content type="html" xml:base="https://lanadz.com/2025/11/30/ai.html"><![CDATA[<p>Everyone talks about AI. I am using AI, we are forced to use AI at work. AI is helpful <em>sometimes</em>. But I am strong believer that you barely can learn anything if you just rely on AI. AI can be confidently wrong. AI tries to please you all the time.
Use your critical thinking skills while you still have it. Talk to real people, they will give you honest opinion.</p>

<p>There, I said it.</p>

<!--more-->]]></content><author><name></name></author><category term="personal space" /><summary type="html"><![CDATA[Everyone talks about AI. I am using AI, we are forced to use AI at work. AI is helpful sometimes. But I am strong believer that you barely can learn anything if you just rely on AI. AI can be confidently wrong. AI tries to please you all the time. Use your critical thinking skills while you still have it. Talk to real people, they will give you honest opinion.]]></summary></entry><entry><title type="html">Patterns in ruby and rails</title><link href="https://lanadz.com/2021/02/27/ruby-patterns.html" rel="alternate" type="text/html" title="Patterns in ruby and rails" /><published>2021-02-27T00:00:00+00:00</published><updated>2021-02-27T00:00:00+00:00</updated><id>https://lanadz.com/2021/02/27/ruby-patterns</id><content type="html" xml:base="https://lanadz.com/2021/02/27/ruby-patterns.html"><![CDATA[<p>Some patterns here for reference:</p>

<h3 id="value-object">Value Object</h3>

<p>Probably the simplest pattern is Value Object - PORO(plain old ruby object) that provides methods that return values:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">User</span>
  <span class="k">def</span> <span class="nf">initialize</span> <span class="p">(</span><span class="n">full_name</span><span class="p">:,</span> <span class="n">email</span><span class="p">:)</span>
    <span class="vi">@full_name</span> <span class="o">=</span> <span class="n">full_name</span>
    <span class="vi">@email</span> <span class="o">=</span> <span class="n">email</span>
  <span class="k">end</span>

  <span class="nb">attr_reader</span> <span class="ss">:full_name</span><span class="p">,</span> <span class="ss">:email</span>

  <span class="k">def</span> <span class="nf">first_name</span>
    <span class="n">full_name</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="s2">" "</span><span class="p">).</span><span class="nf">first</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nf">last_name</span>
    <span class="n">full_name</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="s2">" "</span><span class="p">).</span><span class="nf">last</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<!--more-->

<h3 id="service">Service</h3>

<p>Service object is responsible for doing only one thing:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">Greeter</span>
  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">call</span><span class="p">(</span><span class="nb">name</span><span class="p">,</span> <span class="n">title</span><span class="p">)</span>
    <span class="s2">"Welcome back </span><span class="si">#{</span><span class="n">title</span><span class="si">}</span><span class="s2">. </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">!"</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>
<p>Of course, in reallity, you will have more complicated logic, but you want to make your service responsible for one thing only (single responsibility rule).</p>

<h3 id="decorator">Decorator</h3>
<p>Honestly, I am confusing <code class="language-plaintext highlighter-rouge">decorators</code> and <code class="language-plaintext highlighter-rouge">presenters</code>. I found this <a href="https://longliveruby.com/articles/rails-design-patterns-the-big-picture">explanation and example here</a>:</p>
<blockquote>
  <p>The decorator pattern is similar to the presenter, but instead of adding additional logic, it alters the original class’s behavior.</p>
</blockquote>

<blockquote>
  <p>We have the Post model that provides a content attribute that contains the post’s content. On the single post page, we would like to render the full content, but on the list, we would like to render just a few words of it:</p>
</blockquote>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">PostListDecorator</span> <span class="o">&lt;</span> <span class="no">SimpleDelegator</span>
  <span class="k">def</span> <span class="nf">content</span>
    <span class="n">model</span><span class="p">.</span><span class="nf">content</span><span class="p">.</span><span class="nf">truncate</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">decorate</span><span class="p">(</span><span class="n">posts</span><span class="p">)</span>
    <span class="n">posts</span><span class="p">.</span><span class="nf">map</span> <span class="p">{</span> <span class="o">|</span><span class="n">post</span><span class="o">|</span> <span class="n">new</span><span class="p">(</span><span class="n">post</span><span class="p">)</span> <span class="p">}</span>
  <span class="k">end</span>

  <span class="kp">private</span>

  <span class="k">def</span> <span class="nf">model</span>
    <span class="n">__getobj__</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="vi">@posts</span> <span class="o">=</span> <span class="no">Post</span><span class="p">.</span><span class="nf">all</span>
<span class="vi">@posts</span> <span class="o">=</span> <span class="no">PostListDecorator</span><span class="p">.</span><span class="nf">decorate</span><span class="p">(</span><span class="vi">@posts</span><span class="p">)</span>
</code></pre></div></div>

<h3 id="presenter">Presenter</h3>

<p>This pattern is used when you need to isolate some logic and is usually (not always) used in views.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">UserPresenter</span>
  <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
    <span class="vi">@user</span> <span class="o">=</span> <span class="n">user</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nf">role</span>
    <span class="k">if</span> <span class="vi">@user</span><span class="p">.</span><span class="nf">admin?</span>
      <span class="s1">'Administrator'</span>
    <span class="k">elsif</span> <span class="vi">@user</span><span class="p">.</span><span class="nf">signed_in</span>
      <span class="s1">'User'</span>
    <span class="k">else</span>
      <span class="s1">'Guest'</span>
    <span class="k">end</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<h1 id="policy-objects">Policy Objects</h1>

<p>These objects are responsible for permissions, policies etc. Examples of gems will be <code class="language-plaintext highlighter-rouge">cancan</code>, <code class="language-plaintext highlighter-rouge">pundit</code></p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">UserAccoutnPolicy</span>
  <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">account</span><span class="p">)</span>
    <span class="vi">@user</span> <span class="o">=</span> <span class="n">user</span>
    <span class="vi">@account</span> <span class="o">=</span> <span class="n">account</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nf">access?</span>
    <span class="n">admin?</span> <span class="o">&amp;&amp;</span> <span class="vi">@account</span><span class="p">.</span><span class="nf">user</span> <span class="o">==</span> <span class="vi">@user</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nf">close?</span>
    <span class="n">access?</span> <span class="o">&amp;&amp;</span> <span class="vi">@account</span><span class="p">.</span><span class="nf">active?</span> <span class="o">&amp;&amp;</span> <span class="vi">@user</span><span class="p">.</span><span class="nf">balance</span><span class="p">.</span><span class="nf">positive?</span>
  <span class="k">end</span>

  <span class="kp">private</span>

  <span class="k">def</span> <span class="nf">admin?</span>
    <span class="vi">@user</span><span class="p">.</span><span class="nf">role</span> <span class="o">==</span> <span class="s1">'admin'</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>or another example</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">BankTransferPolicy</span>
  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">allowed?</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">recipient</span><span class="p">,</span> <span class="n">amount</span><span class="p">)</span>
    <span class="n">user</span><span class="p">.</span><span class="nf">account_balance</span> <span class="o">&gt;=</span> <span class="n">amount</span> <span class="o">&amp;&amp;</span>
      <span class="n">user</span><span class="p">.</span><span class="nf">transfers_enabled</span> <span class="o">&amp;&amp;</span>
      <span class="n">user</span> <span class="o">!=</span> <span class="n">recipient</span> <span class="o">&amp;&amp;</span>
      <span class="n">amount</span><span class="p">.</span><span class="nf">positive?</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<h3 id="builder">Builder</h3>

<p>Again, nice example with file parsers from <a href="https://longliveruby.com/articles/rails-design-patterns-the-big-picture">long live ruby</a></p>
<blockquote>
  <p>The builder pattern is often also called an adapter. The pattern’s main purpose is to provide a simple way of returning a given class or instance depending on the case. If you are parsing files to get their contents you can create the following builder:</p>
</blockquote>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">FileParser</span>
  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">build</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
    <span class="k">case</span> <span class="no">File</span><span class="p">.</span><span class="nf">extname</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
      <span class="k">when</span> <span class="s1">'.csv'</span> <span class="k">then</span> <span class="no">CsvFileParser</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
      <span class="k">when</span> <span class="s1">'.xls'</span> <span class="k">then</span> <span class="no">XlsFileParser</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
      <span class="k">else</span>
        <span class="k">raise</span><span class="p">(</span><span class="no">UnknownFileFormat</span><span class="p">)</span>
      <span class="k">end</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">BaseParser</span>
  <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
    <span class="vi">@file_path</span> <span class="o">=</span> <span class="n">file_path</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">CsvFileParser</span> <span class="o">&lt;</span> <span class="no">BaseParser</span>
  <span class="k">def</span> <span class="nf">rows</span>
    <span class="c1"># parse rows</span>
  <span class="k">end</span>
<span class="k">end</span>

<span class="k">class</span> <span class="nc">XlsFileParser</span> <span class="o">&lt;</span> <span class="no">BaseParser</span>
  <span class="k">def</span> <span class="nf">rows</span>
    <span class="c1"># parse rows</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>
<p>And usage:
you can access the rows without worrying about selecting a good class that will be able to parse the given format:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">parser</span> <span class="o">=</span> <span class="no">FileParser</span><span class="p">.</span><span class="nf">build</span><span class="p">(</span><span class="n">file_path</span><span class="p">)</span>
<span class="n">rows</span> <span class="o">=</span> <span class="n">parser</span><span class="p">.</span><span class="nf">rows</span>
</code></pre></div></div>

<h3 id="null-object">Null object</h3>

<p>Nobody likes to deal with <code class="language-plaintext highlighter-rouge">nil</code>s and having those extra guards and defensive style.
If you expect a user in your code, and user is not created (for example guest), rather than check for <code class="language-plaintext highlighter-rouge">nil</code> create <code class="language-plaintext highlighter-rouge">GuestUser</code></p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">class</span> <span class="nc">GuestUser</span>
  <span class="k">def</span> <span class="nf">name</span>
    <span class="s1">'Guest'</span>
  <span class="k">end</span>

  <span class="k">def</span> <span class="nf">posts</span>
    <span class="p">[]</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>Now if you need to perform something with user you don’t need to check for <code class="language-plaintext highlighter-rouge">nil</code>s and can treat user as it always exists.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">user</span> <span class="o">=</span> <span class="n">current_user</span> <span class="o">||</span> <span class="no">GuestUser</span><span class="p">.</span><span class="nf">new</span>
<span class="nb">puts</span> <span class="s2">"Welcome </span><span class="si">#{</span><span class="n">user</span><span class="p">.</span><span class="nf">name</span><span class="si">}</span><span class="s2">"</span>
<span class="nb">puts</span> <span class="s2">"Number of posts created </span><span class="si">#{</span><span class="n">user</span><span class="p">.</span><span class="nf">posts</span><span class="p">.</span><span class="nf">size</span><span class="si">}</span><span class="s2">"</span>
</code></pre></div></div>

<h2 id="afterword">Afterword</h2>

<p>Patterns solve problems but when used incorrectly they bring unneeded complexity to your codebase.</p>]]></content><author><name></name></author><category term="ruby" /><summary type="html"><![CDATA[Some patterns here for reference:]]></summary></entry><entry><title type="html">Estimations at work</title><link href="https://lanadz.com/2021/01/06/estimations.html" rel="alternate" type="text/html" title="Estimations at work" /><published>2021-01-06T00:00:00+00:00</published><updated>2021-01-06T00:00:00+00:00</updated><id>https://lanadz.com/2021/01/06/estimations</id><content type="html" xml:base="https://lanadz.com/2021/01/06/estimations.html"><![CDATA[<p>I am not calling planning meetings useless - we actually do talk about <em>what</em> needs to be done, discuss estimates, ownership, and so on.</p>

<p>But have you ever noticed that in those plannings, towards the deadline, pressure builds, and when we discuss release plans, steps, etc, at some point eng manager asks if we will be ready to release it <em>next</em> week.</p>

<p>And somewhere in the middle of all the conversation noise, you hear your teammates essentially saying:
“Sure, it’ll be ready next week to release,assuming we address the issues, performance, and correctness.”</p>

<p>Politically - everyone’s happy.
Legally - as always there is fine print - no promises were made.</p>

<p>We’ll release when it’s <em>done</em>.</p>

<p>Everyone leaves the meeting happy.</p>

<p>Then we have followup later that week in the tight engineering circle, talking about unrealistic dates.</p>

<p>We don’t like cutting corners - but we are forced to. Deadlines are draining..</p>

<p>And here’s the thing:</p>

<p>We want to be proud of our work.
But things happen - on-calls, reviews, production issues, priority shifts - and all of that skews estimates.</p>

<p>Management hears the estimates, but they’re under pressure from above, so that pressure gets passed straight down to the team.</p>

<p>We don’t want to deliver and then roll back. We don’t want to ship something we are not confident in.</p>

<p>So the uncomfortable questions remain:</p>

<p>Is the deadline really necessary?
Can we allow ourselves to miss a cycle and actually deliver quality work?
And do we really need all those extra features that complicate the core project in the first place?</p>

<p>….
Side thought, I saw a <a href="https://www.linkedin.com/pulse/why-leaderships-favorite-holiday-message-reveals-broken-daron-yondem-wt4ac" target="_blan k">post about corporate “new year” letters</a>. You know the ones.</p>

<p>Those essensially say: “go recharge during <em>your</em> holiday, so <em>we</em> can drain your energy  efficiently for the rest of the year”</p>

<p>Lana, biocell.</p>]]></content><author><name></name></author><category term="work" /><category term="personal space" /><summary type="html"><![CDATA[I am not calling planning meetings useless - we actually do talk about what needs to be done, discuss estimates, ownership, and so on.]]></summary></entry><entry><title type="html">Tetris</title><link href="https://lanadz.com/2020/10/13/tetris.html" rel="alternate" type="text/html" title="Tetris" /><published>2020-10-13T00:00:00+00:00</published><updated>2020-10-13T00:00:00+00:00</updated><id>https://lanadz.com/2020/10/13/tetris</id><content type="html" xml:base="https://lanadz.com/2020/10/13/tetris.html"><![CDATA[<p>Take a break, play a game! <a href="https://lanadz.com/tetris/">Tetris</a></p>

<p>It was a fun project, never wrote games before. Ok not quite true, I wrote one game in Delphi in 2000 🤦‍♀️ That was loooooong time ago. Maybe I need to reimplement that game in javascript.</p>

<p>Game is written in JavaScript and Jest is used for tests.
It was funny how I struggle at the beginning to setup the environment. Missing those times when you had plain <code class="language-plaintext highlighter-rouge">javascript</code> and <code class="language-plaintext highlighter-rouge">index.html</code>. Double click on <code class="language-plaintext highlighter-rouge">index.html</code> and see the result.
<!--more-->
This time I wanted to use Jest and write tests. And write modules. And it didn’t work smoothly from the first try.</p>

<p>I used</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span><span class="p">.</span><span class="nx">Tetris</span> <span class="o">=</span> <span class="nx">Tetris</span><span class="p">;</span>
</code></pre></div></div>
<p>and</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  <span class="kd">const</span> <span class="p">{</span> <span class="nx">Tetris</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">./Tetris</span><span class="dl">'</span><span class="p">);</span>
</code></pre></div></div>

<p>The reason why I used <code class="language-plaintext highlighter-rouge">require</code> but not <code class="language-plaintext highlighter-rouge">exports</code> and <code class="language-plaintext highlighter-rouge">imports</code> - <code class="language-plaintext highlighter-rouge">jest</code> worked with <code class="language-plaintext highlighter-rouge">require</code> statements right out of the box. And I didn’t want to spend much time figuring out how to setup <code class="language-plaintext highlighter-rouge">webpack</code> and <code class="language-plaintext highlighter-rouge">babel</code> or whatever is needed to setup the project. Fast and simple please. And TDD ✅.</p>

<p>And of course, <code class="language-plaintext highlighter-rouge">require</code> statements don’t work in browser. <a href="http://browserify.org/">browserify</a> came to the rescue. In simple words it adds <code class="language-plaintext highlighter-rouge">require</code> and <code class="language-plaintext highlighter-rouge">module</code> functionality to bundled file.</p>

<p>The next issue was: if you simply double click <code class="language-plaintext highlighter-rouge">index.html</code> with bundled js files - you will receive the following error:</p>

<div class="errorDiv">
<div class="content">
Access to script at 'file:///Users/username/projects/tetris/bundle.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
</div>
</div>

<p>To fight that one you will need some server running. I used <a href="/tags/ruby-server-oneliner/">ruby oneliner</a></p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ruby <span class="nt">-rwebrick</span> <span class="nt">-e</span><span class="s1">'WEBrick::HTTPServer.new(:Port =&gt; 9090, :DocumentRoot =&gt; Dir.pwd).start'</span>
</code></pre></div></div>
<p>After that, you have a nice <code class="language-plaintext highlighter-rouge">localhost:9090</code> up and running.</p>

<p>That’s pretty much it for environment setup. Source code is available on <a href="https://github.com/lanadz/tetris">github</a>.</p>

<p>Fun with <del>Flags</del> 😄 <a href="https://lanadz.com/tetris/">Tetris</a></p>]]></content><author><name></name></author><category term="javascript" /><category term="personal space" /><summary type="html"><![CDATA[Take a break, play a game! Tetris]]></summary></entry><entry><title type="html">Note-taking</title><link href="https://lanadz.com/2020/07/31/note-taking.html" rel="alternate" type="text/html" title="Note-taking" /><published>2020-07-31T00:00:00+00:00</published><updated>2020-07-31T00:00:00+00:00</updated><id>https://lanadz.com/2020/07/31/note-taking</id><content type="html" xml:base="https://lanadz.com/2020/07/31/note-taking.html"><![CDATA[<p>Today I saw an interesting comment on <a href="https://news.ycombinator.com/item?id=13874026">Hacker News</a>, three years old thread made it to today’s digest.</p>

<p>Guys were discussing interviews and different processes that are used by companies.</p>

<p>I liked what user YCode wrote:</p>

<blockquote>
...
<p />
Keep a daily journal of what you work on. Nothing fancy, just stop by once a day religiously and add a few notes on what you did, what meetings you attended, who you spoke with, etc...
<p />
Save your evaluations and especially any award packages you or your team might get submitted for. At least where I work both are your supervisor's attempt to make you look as good as possible.
<p />

Then, when you're job hunting review your notes and bullets and collect the ones that sound the best and perhaps ones that have numbers assigned to them (size, savings, productivity, etc..)

<p />
...
</blockquote>

<p>But also it’s helpful as a reminder for what we are doing and what we have <strong>achieved</strong>.
Sprint notes are gone when you are changing company and will be too detailed to re-read, but a good old notebook (digital or real) is good to have. I will try to build a new habit.</p>]]></content><author><name></name></author><category term="personal space" /><summary type="html"><![CDATA[Today I saw an interesting comment on Hacker News, three years old thread made it to today’s digest.]]></summary></entry><entry><title type="html">Deep in ice</title><link href="https://lanadz.com/2020/07/30/vault.html" rel="alternate" type="text/html" title="Deep in ice" /><published>2020-07-30T00:00:00+00:00</published><updated>2020-07-30T00:00:00+00:00</updated><id>https://lanadz.com/2020/07/30/vault</id><content type="html" xml:base="https://lanadz.com/2020/07/30/vault.html"><![CDATA[<p>Do you know about <a href="https://archiveprogram.github.com/">The GitHub Arctic Code Vault</a>?</p>

<blockquote>
The GitHub Arctic Code Vault is a data repository preserved in the Arctic World Archive (AWA), a very-long-term archival facility 250 meters deep in the permafrost of an Arctic mountain. The archive is located in a decommissioned coal mine in the Svalbard archipelago, closer to the North Pole than the Arctic Circle. GitHub will capture a snapshot of every active public repository on 02/02/2020 and preserve that data in the Arctic Code Vault.
</blockquote>

<p>Because I didn’t.</p>

<p>I noticed a new badge on my github <a href="https://github.com/lanadz">profile</a> and was surprised to learn that this blog was stored in Arctic Code Vault. Something I leave for future generations 😅. That made me happy!</p>

<p><img src="/assets/fallout.png" style="width: 200px; height: 200px; display:block; margin: auto;" alt="fallout" /></p>]]></content><author><name></name></author><category term="personal space" /><summary type="html"><![CDATA[Do you know about The GitHub Arctic Code Vault?]]></summary></entry><entry><title type="html">Redesign</title><link href="https://lanadz.com/2020/07/16/redesign.html" rel="alternate" type="text/html" title="Redesign" /><published>2020-07-16T00:00:00+00:00</published><updated>2020-07-16T00:00:00+00:00</updated><id>https://lanadz.com/2020/07/16/redesign</id><content type="html" xml:base="https://lanadz.com/2020/07/16/redesign.html"><![CDATA[<p>When you are procrastinating, go and redesign your blog. Or watch some conference talks and learn something. Or pair-program with somebody. There will be the satisfaction of something achieved at the end of the day.</p>

<p>Today T.I.L. became dark. 🎨</p>]]></content><author><name></name></author><category term="personal space" /><summary type="html"><![CDATA[When you are procrastinating, go and redesign your blog. Or watch some conference talks and learn something. Or pair-program with somebody. There will be the satisfaction of something achieved at the end of the day.]]></summary></entry><entry><title type="html">Create new project with minitest and nice output. Run single test</title><link href="https://lanadz.com/2020/07/15/minitest.html" rel="alternate" type="text/html" title="Create new project with minitest and nice output. Run single test" /><published>2020-07-15T00:00:00+00:00</published><updated>2020-07-15T00:00:00+00:00</updated><id>https://lanadz.com/2020/07/15/minitest</id><content type="html" xml:base="https://lanadz.com/2020/07/15/minitest.html"><![CDATA[<p>Quick list how to create simple Ruby project with minitest:</p>

<!--more-->

<ul>
  <li>obiously you need to create new directory</li>
  <li>run <code class="language-plaintext highlighter-rouge">bundle init</code> to generate new Gemfile</li>
  <li>add minitest related gems:</li>
</ul>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">group</span> <span class="ss">:test</span> <span class="k">do</span>
  <span class="n">gem</span> <span class="s1">'minitest'</span>
  <span class="n">gem</span> <span class="s1">'minitest-reporters'</span>
  <span class="n">gem</span> <span class="s1">'minitest-focus'</span>
<span class="k">end</span>
</code></pre></div></div>

<ul>
  <li><code class="language-plaintext highlighter-rouge">bundle install</code></li>
  <li>create test file and add</li>
</ul>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'minitest/autorun'</span>
<span class="nb">require</span> <span class="s1">'minitest/reporters'</span>
<span class="nb">require</span> <span class="s1">'minitest/focus'</span>

<span class="no">Minitest</span><span class="o">::</span><span class="no">Reporters</span><span class="p">.</span><span class="nf">use!</span> <span class="p">[</span><span class="no">Minitest</span><span class="o">::</span><span class="no">Reporters</span><span class="o">::</span><span class="no">SpecReporter</span><span class="p">.</span><span class="nf">new</span><span class="p">]</span>
</code></pre></div></div>

<p>Reporters add nice formatting to your output. Personaly, I prefer spec-like output, so I used <code class="language-plaintext highlighter-rouge">Minitest::Reporters::SpecReporter</code>.</p>

<p>The <code class="language-plaintext highlighter-rouge">DefaultReporter</code> gives you the following output:</p>

<p>
<img src="/assets/defaultReporter.png" />
</p>

<p>The <code class="language-plaintext highlighter-rouge">SpecReporter</code> gives you the following output:</p>

<p><img src="/assets/specReporter.png" /></p>

<h1 id="run-single-test">Run single test</h1>

<p>Nice bonus: <code class="language-plaintext highlighter-rouge">focus</code>. You just need to add <code class="language-plaintext highlighter-rouge">focus</code> before method or <code class="language-plaintext highlighter-rouge">it</code>. <a href="https://github.com/seattlerb/minitest-focus">Source</a></p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'minitest/autorun'</span>
<span class="nb">require</span> <span class="s1">'minitest/focus'</span>

<span class="k">class</span> <span class="nc">MyTest</span> <span class="o">&lt;</span> <span class="no">MiniTest</span><span class="o">::</span><span class="no">Unit</span><span class="o">::</span><span class="no">TestCase</span>
  <span class="k">def</span> <span class="nf">test_unrelated</span><span class="p">;</span> <span class="o">...</span><span class="p">;</span> <span class="k">end</span>       <span class="c1"># will NOT run</span>

  <span class="n">focus</span> <span class="k">def</span> <span class="nf">test_method2</span><span class="p">;</span> <span class="o">...</span><span class="p">;</span>  <span class="k">end</span>  <span class="c1"># will run (direct--preferred)</span>

  <span class="n">focus</span>
  <span class="k">def</span> <span class="nf">test_method</span><span class="p">;</span> <span class="o">...</span><span class="p">;</span>  <span class="k">end</span>         <span class="c1"># will run (indirect)</span>

  <span class="k">def</span> <span class="nf">test_method_edgecase</span><span class="p">;</span> <span class="o">...</span><span class="p">;</span> <span class="k">end</span> <span class="c1"># will NOT run</span>
<span class="k">end</span>

<span class="c1"># or, with spec-style:</span>

<span class="n">describe</span> <span class="s1">'MyTest2'</span> <span class="k">do</span>
  <span class="n">focus</span><span class="p">;</span> <span class="n">it</span> <span class="s1">'does something'</span>       <span class="k">do</span> <span class="n">pass</span> <span class="k">end</span>
  <span class="n">focus</span>  <span class="n">it</span><span class="p">(</span><span class="s1">'does something else'</span><span class="p">)</span> <span class="p">{</span>  <span class="n">pass</span>   <span class="p">}</span> <span class="c1"># block precedence needs {}</span>
<span class="k">end</span>
</code></pre></div></div>]]></content><author><name></name></author><category term="ruby" /><summary type="html"><![CDATA[Quick list how to create simple Ruby project with minitest:]]></summary></entry><entry><title type="html">Create nested arrays in Ruby</title><link href="https://lanadz.com/2020/06/30/nested-array.html" rel="alternate" type="text/html" title="Create nested arrays in Ruby" /><published>2020-06-30T00:00:00+00:00</published><updated>2020-06-30T00:00:00+00:00</updated><id>https://lanadz.com/2020/06/30/nested-array</id><content type="html" xml:base="https://lanadz.com/2020/06/30/nested-array.html"><![CDATA[<p>I needed to create a nested array(2d array, matrix). Usually, I do:</p>

<!--more-->

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">array</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1">#or</span>
<span class="n">array</span> <span class="o">=</span> <span class="no">Array</span><span class="p">.</span><span class="nf">new</span>
</code></pre></div></div>

<p>More from official doc <a href="https://apidock.com/ruby/Array">here</a></p>

<p>And it usually works, because, often I don’t need nested arrays, I initiate array and I can start doing #push, #[], etc.</p>

<p>But the problem is when you need to create</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">array</span> <span class="o">=</span> <span class="p">[[]]</span>
</code></pre></div></div>

<p>I expected that this is enough for adding as many arrays to outer array as i want. To my surprise(again 🤦‍♀), when I wanted to add second element, I saw <code class="language-plaintext highlighter-rouge">NoMethodError</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2.7.0 :003 &gt; array=[]
2.7.0 :004 &gt; array[0]=1
2.7.0 :005 &gt; array[2]=3        &lt;- dynamically can add elements
2.7.0 :006 &gt; array
 =&gt; [1, nil, 3]
2.7.0 :007 &gt; array2d=[[]]
2.7.0 :008 &gt; array2d[0][0] = 0
2.7.0 :009 &gt; array2d[0][1] = 0
2.7.0 :010 &gt; array2d
 =&gt; [[0, 0]]
2.7.0 :011 &gt; array2d[1][0] = 0            &lt;- fail to add second array, obviously, because it doesnt exist
Traceback (most recent call last):
        4: from .rvm/rubies/ruby-2.7.0/bin/irb:23:in `&lt;main&gt;'
        3: from .rvm/rubies/ruby-2.7.0/bin/irb:23:in `load'
        2: from .rvm/rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `&lt;top (required)&gt;'
        1: from (irb):11
NoMethodError (undefined method `[]=' for nil:NilClass)
2.7.0 :012 &gt;
</code></pre></div></div>

<p>We failed to add second array, obviously, because it doesn’t exist. <code class="language-plaintext highlighter-rouge">array2d</code> is <code class="language-plaintext highlighter-rouge">[[]]</code>, which means when you call <code class="language-plaintext highlighter-rouge">array[1]</code> it will return nil, and on <code class="language-plaintext highlighter-rouge">nil</code> I was trying to call <code class="language-plaintext highlighter-rouge">[]</code>. And that’s why <code class="language-plaintext highlighter-rouge">NoMethodError</code></p>

<p>Ok, so we know the problem. I need to initiate array of arrays with right amount of arrays inside. <a href="https://apidock.com/ruby/Array">Official doc</a> shows how it can be done:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Array</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">{</span> <span class="no">Array</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="p">}</span>  <span class="c1"># please, see the block</span>
<span class="no">Array</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="no">Array</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span> <span class="c1"># no block was passed</span>
</code></pre></div></div>

<p>what happens here, let’s break down:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2.7.0 :012 &gt; a = Array.new(3) { Array.new(3) }              # block is given
2.7.0 :013 &gt; a
 =&gt; [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
2.7.0 :014 &gt; a[0][1]=2
2.7.0 :015 &gt; a
 =&gt; [[nil, 2, nil], [nil, nil, nil], [nil, nil, nil]]      # as expected

2.7.0 :016 &gt; b=Array.new(3, Array.new(3))                  # default parameter is given
2.7.0 :017 &gt; b
 =&gt; [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil]]
2.7.0 :018 &gt; b[0][1]=2
2.7.0 :019 &gt; b
 =&gt; [[nil, 2, nil], [nil, 2, nil], [nil, 2, nil]]          # HA, and here we passed by reference
</code></pre></div></div>

<p>As you can see, b was array that was created with default parameter, and array is passed by reference. Which means <code class="language-plaintext highlighter-rouge">b=Array.new(3, Array.new(5))</code>, <code class="language-plaintext highlighter-rouge">Array.new(5)</code> was evaluated once, and same object was passed to each element of outer element. To prove the point let’s check <code class="language-plaintext highlighter-rouge">object_id</code>s:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># a is created with block given a = Array.new(3) { Array.new(3) }
2.7.0 :020 &gt; a.map(&amp;:object_id)
 =&gt; [180, 200, 220]

# b is created with default value b=Array.new(3, Array.new(3))
2.7.0 :023 &gt; b.map(&amp;:object_id)
 =&gt; [240, 240, 240]
2.7.0 :024 &gt;
</code></pre></div></div>

<p>From official docs:</p>

<blockquote>
<p>Note that the second argument populates the array with references to the same object. Therefore, it is only recommended in cases when you need to instantiate arrays with natively immutable objects such as Symbols, numbers, true or false.
</p>
<p>
To create an array with separate objects a block can be passed instead. This method is safe to use with mutable objects such as hashes, strings or other arrays:
</p>
</blockquote>

<p>Alternatively, I could create outer array, and then use <code class="language-plaintext highlighter-rouge">#push</code> for pre-created internal arrays:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">internal_array</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]</span>
<span class="n">result</span><span class="p">.</span><span class="nf">push</span><span class="p">(</span><span class="n">internal_array</span><span class="p">)</span>
<span class="n">internal_array</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]</span>
<span class="n">result</span><span class="p">.</span><span class="nf">push</span><span class="p">(</span><span class="n">internal_array</span><span class="p">)</span>
</code></pre></div></div>

<p>(repetition here just to show the point)</p>

<p>results:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>2.7.0 :026 &gt; result = []
2.7.0 :027 &gt;
2.7.0 :028 &gt; internal_array = [1,2,3,4]
2.7.0 :029 &gt; result.push(internal_array)
 =&gt; [[1, 2, 3, 4]]
2.7.0 :030 &gt; internal_array = [2,3,1,2]
2.7.0 :031 &gt; result
 =&gt; [[1, 2, 3, 4]]
2.7.0 :032 &gt; result.push(internal_array)
 =&gt; [[1, 2, 3, 4], [2, 3, 1, 2]]
2.7.0 :033 &gt;
</code></pre></div></div>

<p>In addition to arrays, you may want to check about strings too: <a href="/2020/02/28/reference.html">references in ruby</a></p>]]></content><author><name></name></author><category term="ruby" /><summary type="html"><![CDATA[I needed to create a nested array(2d array, matrix). Usually, I do:]]></summary></entry></feed>