<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Wiktor Mociun</title><link>https://voter101.github.io/</link><description>Recent content on Wiktor Mociun</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Wiktor Mociun (CC BY 4.0)</copyright><lastBuildDate>Mon, 19 Dec 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://voter101.github.io/index.xml" rel="self" type="application/rss+xml"/><item><title>Advent of Code 2022</title><link>https://voter101.github.io/blog/advent-of-code-2022/</link><pubDate>Mon, 19 Dec 2022 00:00:00 +0000</pubDate><guid>https://voter101.github.io/blog/advent-of-code-2022/</guid><description>Last few weeks I have been spending lots of time on this year&amp;rsquo;s edition of Advent of Code. There are still 7 days to go, but I thought I&amp;rsquo;d share my thoughts on the process so far.
Advent of Code is a set of coding challenges published between 1st and 25th of December every year. Everyone gets their own exclusive input and what matters is giving the correct answer.
This year I&amp;rsquo;ve made a effort to write my solutions in Rust.</description><content:encoded><![CDATA[<p>Last few weeks I have been spending lots of time on this year&rsquo;s edition of Advent of Code. There are still 7 days to go, but I thought I&rsquo;d share my thoughts on the process so far.</p>
<blockquote>
<p><a href="https://adventofcode.com/">Advent of Code</a> is a set of coding challenges published between 1st and 25th of December every year. Everyone gets their own exclusive input and what matters is giving the correct answer.</p>
</blockquote>
<p>This year I&rsquo;ve made a effort to write my solutions in Rust. Even though I ignore most of the generic parts of the language, I still get very effective with it. Rust clicked for me in 2022 for good. My coding style is very caveman-ish with strong influences of regular C, but I find it very effective. I post my solutions on <a href="https://github.com/voter101/aoc">my GitHub</a>.</p>
<p>Computer science problems are always on my list of things I would want to be better at. After leaving the university, I never really had an occasion for that. AoC has been a great hack for that. The problems are presented in very nice way. There is no pressure on being the most efficient. Some tasks require a trick to finish in a reasonable time, but there is a lot of room to do different optimizations.</p>
<p>I encourage everyone to give it a try. I haven&rsquo;t finished all challenges on time, nor I fight to get a good spot on the leaderboard. I still have a lot of fun. It&rsquo;s like LeetCode, but actually motivating. My brain haven&rsquo;t got that much focused thinking in a very long time.</p>
]]></content:encoded></item><item><title>Faster Heroku deploys with Rails and webpacker</title><link>https://voter101.github.io/blog/faster-heroku-deploys-rails-webpacker/</link><pubDate>Tue, 27 Aug 2019 00:00:00 +0000</pubDate><guid>https://voter101.github.io/blog/faster-heroku-deploys-rails-webpacker/</guid><description>Some time ago in Pilot, we switched to use webpacker as a tool for compiling our JavaScript code. It is a simple way to integrate webpack into your Rails project.
Lately, we noticed that our Heroku deploys got frustratingly long. Over 10 minutes to build and release our main application wasn&amp;rsquo;t acceptable. Add CI runtime and Heroku&amp;rsquo;s preboot to the mix and now we could easily end up with around 25-30 minutes of full deploy time.</description><content:encoded><![CDATA[<p>Some time ago in <a href="https://pilot.co/">Pilot</a>, we switched to use <a href="https://github.com/rails/webpacker">webpacker</a> as a tool for compiling our JavaScript code. It is a simple way to integrate webpack into your Rails project.</p>
<p>Lately, we noticed that our Heroku deploys got frustratingly long. Over 10 minutes to build and release our main application wasn&rsquo;t acceptable. Add CI runtime and Heroku&rsquo;s <a href="https://devcenter.heroku.com/articles/preboot#deploying-with-preboot">preboot</a> to the mix and now we could easily end up with around 25-30 minutes of full deploy time. This was getting very annoying when trying to ship a hotfix.</p>
<p>What if we could make it shorter?</p>
<h2 id="whats-going-on">What&rsquo;s going on?</h2>
<p>The biggest chunk of time in the build process has been asset compilation. With each build, Heroku was installing all npm dependencies (using yarn) and compiling webpacker assets from scratch. It took very long with each build, even if we didn&rsquo;t touch any code (deploying the same code twice).</p>
<p>Something didn&rsquo;t smell right as on local dev environment if there were no changes, the process ran in less than a second.</p>
<p>As time passed, we also noticed that our slug size was growing, which causes deploys to be longer. There were lots of uncleaned leftovers after each webpacker build. Simple <a href="https://github.com/heroku/heroku-repo">repo purging</a> was enough to get rid of this problem, but it required manual command execution.</p>
<p>It was clear that there are a couple of problems:</p>
<ul>
<li>Yarn cache isn&rsquo;t re-used.</li>
<li>Full webpacker build runs even if JavaScript code was not touched.</li>
<li>Old build products were not cleaned.</li>
</ul>
<h2 id="getting-to-a-solution">Getting to a solution</h2>
<p>Luckily some people already <a href="https://github.com/heroku/heroku-buildpack-ruby/pull/892">worked on a solution</a>. With that webpacker will reuse the previous build if JavaScript files were not touched. Otherwise, webpacker will do a full rebuild. On top of that, these changes include a Yarn cache, which remedies problems with dependencies installation (however this could be achieved installing official node.js buildpack from Heroku).</p>
<p>Another problem is that webpacker <a href="https://github.com/rails/webpacker/issues/1410">does not ship with a cleaning task</a> (similar to `assets:clean``). Without it, the slug size of our application will keep growing in time. Luckily for us, there is a webpack plugin called <a href="https://github.com/johnagan/clean-webpack-plugin">clean-webpack-plugin</a> that does exactly this.</p>
<p>Combining that plugin and making a little tweak in the <a href="https://github.com/heroku/heroku-buildpack-ruby/pull/892">solution</a> by <a href="https://github.com/kpheasey">@kpheasey</a> we can achieve the effect we want. We included that tweak on our GitHub fork of <a href="https://github.com/pilotcreative/heroku-buildpack-ruby/tree/feat/yarn-cache">heroku-buildpack-ruby</a>.</p>
<h2 id="putting-the-solution-together">Putting the solution together</h2>
<h4 id="technical-note">Technical note:</h4>
<blockquote>
<p>This solution works on Rails versions &gt;= 5.1, &lt; 6.0. It should be easy to modify it to work with other versions.</p>
</blockquote>
<p>Firstly, you need to have `clean-webpack-plugin`` in place:</p>
<pre tabindex="0"><code>yarn add clean-webpack-plugin
</code></pre><p>Now add plugin&rsquo;s config code to <code>config/webpack/environment.js</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-js" data-lang="js"><span class="line"><span class="ln">1</span><span class="cl"><span class="c1">// ...
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="c1"></span><span class="kr">const</span> <span class="p">{</span> <span class="nx">CleanWebpackPlugin</span> <span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&#34;clean-webpack-plugin&#34;</span><span class="p">);</span>
</span></span><span class="line"><span class="ln">3</span><span class="cl">
</span></span><span class="line"><span class="ln">4</span><span class="cl"><span class="nx">environment</span><span class="p">.</span><span class="nx">plugins</span><span class="p">.</span><span class="nx">prepend</span><span class="p">(</span><span class="s2">&#34;CleanWebpackPlugin&#34;</span><span class="p">,</span> <span class="k">new</span> <span class="nx">CleanWebpackPlugin</span><span class="p">());</span>
</span></span><span class="line"><span class="ln">5</span><span class="cl">
</span></span><span class="line"><span class="ln">6</span><span class="cl"><span class="c1">// ...
</span></span></span></code></pre></div><p>And the last step – replace the official Ruby buildpack with the custom one in your app&rsquo;s Settings on Heroku.</p>
<pre tabindex="0"><code>https://github.com/pilotcreative/heroku-buildpack-ruby.git#feat/yarn-cache
</code></pre><p><img src="/blog/images/faster-heroku-deploys/buildpacks.png" alt="Heroku buildpacks order showing Pilot&rsquo;s buildpack as a first one"></p>
<p>Now run a full build to build your cache and you&rsquo;re done! For us builds take from 2.5 to 5 minutes depending on what changes are being deployed.</p>
<h2 id="sources">Sources</h2>
<ul>
<li><a href="https://github.com/rails/webpacker/issues/1410">https://github.com/rails/webpacker/issues/1410</a></li>
<li><a href="https://github.com/heroku/heroku-buildpack-ruby/pull/892">https://github.com/heroku/heroku-buildpack-ruby/pull/892</a></li>
<li><a href="https://github.com/johnagan/clean-webpack-plugin">https://github.com/johnagan/clean-webpack-plugin</a></li>
<li><a href="https://github.com/rails/webpacker/pull/1744">https://github.com/rails/webpacker/pull/1744</a></li>
<li><a href="https://thoughtbot.com/blog/how-to-reduce-a-large-heroku-compiled-slug-size">https://thoughtbot.com/blog/how-to-reduce-a-large-heroku-compiled-slug-size</a></li>
</ul>
]]></content:encoded></item><item><title>Quick Terminal Tip</title><link>https://voter101.github.io/blog/quick-terminal-tip/</link><pubDate>Sun, 11 Mar 2018 00:00:00 +0000</pubDate><guid>https://voter101.github.io/blog/quick-terminal-tip/</guid><description>There is one small thing that made my life as a software developer a little better. And not many people seem to know about it.
The trick is hotkey terminal window. It is basically an additional terminal window that is always visible, and you can show/hide it using a keyboard shortcut.
This additional window seemed to be really handy as a code scratchpad or dedicated man window. It is so convenient that I sometimes use it as the main terminal.</description><content:encoded><![CDATA[<p>There is one small thing that made my life as a software developer a little better. And not many people seem to know about it.</p>
<p>The trick is hotkey terminal window. It is basically an additional terminal window that is always visible, and you can show/hide it using a keyboard shortcut.</p>
<p><img src="/blog/images/quick-terminal-tip/preview.gif" alt="Animation showing hotkey terminal window overlaying active content"></p>
<p>This additional window seemed to be really handy as a code scratchpad or dedicated man window. It is so convenient that I sometimes use it as the main terminal.</p>
<p>I believe this feature should be available on most platforms. I personally use <a href="https://www.iterm2.com/">iTerm2</a> (Mac only) and it has this functionality built-in. In my case, the new window show/hide up after I press CTRL two times.</p>
<p><img src="/blog/images/quick-terminal-tip/iterm.png" alt="Setup hotkey window in iTerm2"></p>
]]></content:encoded></item></channel></rss>