<?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://blog.ipepe.pl/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.ipepe.pl/" rel="alternate" type="text/html" /><updated>2024-12-07T04:51:07+00:00</updated><id>https://blog.ipepe.pl/feed.xml</id><title type="html">Patryk Ptasiński’s Dev &amp;amp; Life Blog</title><subtitle>Patryk Ptasiński&apos;s Dev &amp; Life Blog</subtitle><author><name>Patryk Ptasiński</name></author><entry><title type="html">Mastering zstd: Stdin Compression Tricks</title><link href="https://blog.ipepe.pl/2024/12/07/mastering-zstd-with-stdin/" rel="alternate" type="text/html" title="Mastering zstd: Stdin Compression Tricks" /><published>2024-12-07T00:00:00+00:00</published><updated>2024-12-07T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2024/12/07/mastering-zstd-with-stdin</id><content type="html" xml:base="https://blog.ipepe.pl/2024/12/07/mastering-zstd-with-stdin/"><![CDATA[<p>Zstandard (zstd) offers powerful compression directly from stdin, making file handling a breeze. Whether you’re archiving logs or transferring data, piping content is simple. For compression, just pipe your data: <code class="language-plaintext highlighter-rouge">cat file.txt | zstd &gt; compressed.zst</code>. Decompression is equally straightforward: <code class="language-plaintext highlighter-rouge">zstd -d &lt; compressed.zst &gt; restored.txt</code>. Pro tip: Use compression levels with <code class="language-plaintext highlighter-rouge">-#</code> to balance speed and size. Command-line enthusiasts will love how zstd seamlessly integrates with shell pipelines, providing efficient, flexible compression on the fly. Experiment with different levels to find your sweet spot!</p>]]></content><author><name>Patryk Ptasiński</name></author><category term="devops" /><category term="linux" /><summary type="html"><![CDATA[Zstandard (zstd) offers powerful compression directly from stdin, making file handling a breeze. Whether you’re archiving logs or transferring data, piping content is simple. For compression, just pipe your data: cat file.txt | zstd &gt; compressed.zst. Decompression is equally straightforward: zstd -d &lt; compressed.zst &gt; restored.txt. Pro tip: Use compression levels with -# to balance speed and size. Command-line enthusiasts will love how zstd seamlessly integrates with shell pipelines, providing efficient, flexible compression on the fly. Experiment with different levels to find your sweet spot!]]></summary></entry><entry><title type="html">Simple but genious ZFS snapshot schedule</title><link href="https://blog.ipepe.pl/2024/12/06/simple-but-genious-zfs-snapshot-schedule/" rel="alternate" type="text/html" title="Simple but genious ZFS snapshot schedule" /><published>2024-12-06T00:00:00+00:00</published><updated>2024-12-06T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2024/12/06/simple-but-genious-zfs-snapshot-schedule</id><content type="html" xml:base="https://blog.ipepe.pl/2024/12/06/simple-but-genious-zfs-snapshot-schedule/"><![CDATA[<p>ZFS is a powerful filesystem that allows you to take snapshots of your data. These snapshots can be used to restore your data to a previous state in case of accidental deletion or corruption. One of the best features of ZFS is its ability to take automatic snapshots at regular intervals. This allows you to easily roll back to a previous version of your data without having to manually create snapshots.</p>

<p>In this article, I’ll show you how to set up a simple but genius ZFS snapshot schedule that will automatically take snapshots of your data at regular intervals. This will help you protect your data and ensure that you always have a recent backup available.</p>

<p>Here’s how you can set up a ZFS snapshot schedule:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>nano /root/create_zfs_snapshot.sh
</code></pre></div></div>

<p>Add the following lines to the script:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>

<span class="c"># crontab -e</span>
<span class="c"># 0 * * * * /root/create_zfs_snapshot.sh</span>

zfs destroy tankz@hourly-<span class="si">$(</span><span class="nb">date</span> +%H<span class="si">)</span>
zfs snapshot tankz@hourly-<span class="si">$(</span><span class="nb">date</span> +%H<span class="si">)</span>

zfs destroy tankz@daily-<span class="si">$(</span><span class="nb">date</span> +%A<span class="si">)</span>
zfs snapshot tankz@daily-<span class="si">$(</span><span class="nb">date</span> +%A<span class="si">)</span>

zfs destroy tankz@weekly-<span class="si">$(</span><span class="nb">date</span> +%U<span class="si">)</span>
zfs snapshot tankz@weekly-<span class="si">$(</span><span class="nb">date</span> +%U<span class="si">)</span>

zfs destroy tankz@monthly-<span class="si">$(</span><span class="nb">date</span> +%m<span class="si">)</span>
zfs snapshot tankz@monthly-<span class="si">$(</span><span class="nb">date</span> +%m<span class="si">)</span>

zfs destroy tankz@yearly-<span class="si">$(</span><span class="nb">date</span> +%Y<span class="si">)</span>
zfs snapshot tankz@yearly-<span class="si">$(</span><span class="nb">date</span> +%Y<span class="si">)</span>
</code></pre></div></div>

<p>Make the script executable:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo chmod</span> +x /root/create_zfs_snapshot.sh
</code></pre></div></div>

<p>Add the script to the crontab to run every hour:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>crontab <span class="nt">-e</span>
</code></pre></div></div>

<p>Add the following line to the crontab:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>0 <span class="k">*</span> <span class="k">*</span> <span class="k">*</span> <span class="k">*</span> /root/create_zfs_snapshot.sh
</code></pre></div></div>

<p>This script will create snapshots of your ZFS dataset <code class="language-plaintext highlighter-rouge">tankz</code> every hour, day, week, month, and year. The snapshots will be named <code class="language-plaintext highlighter-rouge">hourly-&lt;hour&gt;</code>, <code class="language-plaintext highlighter-rouge">daily-&lt;day&gt;</code>, <code class="language-plaintext highlighter-rouge">weekly-&lt;week&gt;</code>, <code class="language-plaintext highlighter-rouge">monthly-&lt;month&gt;</code>, and <code class="language-plaintext highlighter-rouge">yearly-&lt;year&gt;</code>, respectively. This schedule will ensure that you always have a recent backup of your data available for recovery.</p>]]></content><author><name>Patryk Ptasiński</name></author><category term="devops" /><category term="zfs" /><summary type="html"><![CDATA[ZFS is a powerful filesystem that allows you to take snapshots of your data. These snapshots can be used to restore your data to a previous state in case of accidental deletion or corruption. One of the best features of ZFS is its ability to take automatic snapshots at regular intervals. This allows you to easily roll back to a previous version of your data without having to manually create snapshots.]]></summary></entry><entry><title type="html">ZRAM is memory compression solution for cheap VPS</title><link href="https://blog.ipepe.pl/2024/12/06/zram-is-memory-compression-solution-for-cheap-vps/" rel="alternate" type="text/html" title="ZRAM is memory compression solution for cheap VPS" /><published>2024-12-06T00:00:00+00:00</published><updated>2024-12-06T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2024/12/06/zram-is-memory-compression-solution-for-cheap-vps</id><content type="html" xml:base="https://blog.ipepe.pl/2024/12/06/zram-is-memory-compression-solution-for-cheap-vps/"><![CDATA[<p>ZRAM is a compressed block device that uses a part of your RAM as a swap partition. It can be used to improve performance on systems with low memory by compressing data in memory. This can help reduce the amount of data that needs to be written to disk, which can improve performance on systems with slow disk I/O.</p>

<p>This is a great solution for cheap VPS with low memory. It can help you to run more services on a single VPS without running out of memory.</p>

<p>Here’s how you can set up ZRAM on your Linux system:</p>

<ol>
  <li>Install ZRAM:</li>
</ol>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt-get <span class="nt">-uy</span> <span class="nb">install </span>zram-config nohang
</code></pre></div></div>

<ol>
  <li>Enable and start the ZRAM service:</li>
</ol>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>service zram-config start
</code></pre></div></div>

<ol>
  <li>Check the status of the ZRAM service:</li>
</ol>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>service zram-config status
</code></pre></div></div>

<p>Sources:</p>
<ul>
  <li><a href="https://github.com/alexmyczko/autoexec.bat/blob/master/config.sys/ubuntu-system-zram">https://github.com/alexmyczko/autoexec.bat/blob/master/config.sys/ubuntu-system-zram</a></li>
  <li><a href="https://docs.kernel.org/admin-guide/blockdev/zram.html">https://docs.kernel.org/admin-guide/blockdev/zram.html</a></li>
  <li><a href="https://unix.stackexchange.com/questions/594817/why-does-zram-occupy-much-more-memory-compared-to-its-compressed-value">https://unix.stackexchange.com/questions/594817/why-does-zram-occupy-much-more-memory-compared-to-its-compressed-value</a></li>
  <li><a href="https://lore.kernel.org/lkml/20160606194836.3624-2-hannes@cmpxchg.org/">https://lore.kernel.org/lkml/20160606194836.3624-2-hannes@cmpxchg.org/</a></li>
  <li><a href="https://unix.stackexchange.com/questions/32333/what-does-the-vm-swappiness-parameter-really-control">https://unix.stackexchange.com/questions/32333/what-does-the-vm-swappiness-parameter-really-control</a></li>
</ul>]]></content><author><name>Patryk Ptasiński</name></author><category term="devops" /><category term="linux" /><summary type="html"><![CDATA[ZRAM is a compressed block device that uses a part of your RAM as a swap partition. It can be used to improve performance on systems with low memory by compressing data in memory. This can help reduce the amount of data that needs to be written to disk, which can improve performance on systems with slow disk I/O.]]></summary></entry><entry><title type="html">Public SSH Keys: Download from GitHub</title><link href="https://blog.ipepe.pl/2024/03/27/public-ssh-keys-download-from-github/" rel="alternate" type="text/html" title="Public SSH Keys: Download from GitHub" /><published>2024-03-27T00:00:00+00:00</published><updated>2024-03-27T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2024/03/27/public-ssh-keys-download-from-github</id><content type="html" xml:base="https://blog.ipepe.pl/2024/03/27/public-ssh-keys-download-from-github/"><![CDATA[<p>Github has a feature that allows users to download their public SSH keys. This feature is useful when you need to add your SSH keys to a server or service that requires them. Here’s how you can download your public SSH keys from GitHub.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl https://github.com/username.keys
</code></pre></div></div>

<p>You can try on my account:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl https://github.com/ipepe.keys
</code></pre></div></div>

<p>This command will output the public SSH keys associated with the specified GitHub account. You can then copy the keys and add them to the authorized_keys file on the server or service where you need to use them.</p>]]></content><author><name>Patryk Ptasiński</name></author><category term="ssh" /><category term="github" /><category term="devops" /><summary type="html"><![CDATA[Github has a feature that allows users to download their public SSH keys. This feature is useful when you need to add your SSH keys to a server or service that requires them. Here’s how you can download your public SSH keys from GitHub.]]></summary></entry><entry><title type="html">How I setup VPS</title><link href="https://blog.ipepe.pl/2023/07/14/how-i-setup-vps/" rel="alternate" type="text/html" title="How I setup VPS" /><published>2023-07-14T00:00:00+00:00</published><updated>2023-07-14T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2023/07/14/how-i-setup-vps</id><content type="html" xml:base="https://blog.ipepe.pl/2023/07/14/how-i-setup-vps/"><![CDATA[<p>My essential setup for a new VPS/Ubuntu server.</p>

<h2 id="setup-swap">Setup swap</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>fallocate <span class="nt">-l</span> 1G /swapfile
<span class="nb">sudo chmod </span>600 /swapfile
<span class="nb">sudo </span>mkswap /swapfile
<span class="nb">sudo </span>swapon /swapfile
<span class="nb">sudo cp</span> /etc/fstab /etc/fstab.bkp_before_swap_config
<span class="nb">echo</span> <span class="s1">'/swapfile none swap sw 0 0'</span> | <span class="nb">sudo tee</span> <span class="nt">-a</span> /etc/fstab
<span class="nb">sudo </span>sysctl vm.swappiness<span class="o">=</span>10
<span class="nb">sudo </span>sh <span class="nt">-c</span> <span class="s2">"echo 'vm.swappiness=10' &gt;&gt; /etc/sysctl.conf"</span>
</code></pre></div></div>

<h2 id="setup-docker-and-add-current-user-to-docker-group">Setup docker and add current user to docker group</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>apt <span class="nb">install </span>docker-compose docker.io
<span class="nb">sudo </span>usermod <span class="nt">-aG</span> docker <span class="nv">$USER</span>
</code></pre></div></div>

<h2 id="show-ip-address-on-tty-login">Show IP address on tty login</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>nano /etc/issue
</code></pre></div></div>

<p>Add the following lines to display the IP address of your network interface (replace <code class="language-plaintext highlighter-rouge">enp2s0</code> with your actual interface name):</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Ubuntu \n \l

enp2s0 (IPv4): \4{enp2s0}
enp2s0 (IPv6): \6{enp2s0}
</code></pre></div></div>]]></content><author><name>Patryk Ptasiński</name></author><category term="devops" /><category term="linux" /><summary type="html"><![CDATA[My essential setup for a new VPS/Ubuntu server.]]></summary></entry><entry><title type="html">How to Disable Touchscreen in Ubuntu 20.04 on a Dell XPS 17</title><link href="https://blog.ipepe.pl/2023/06/19/how-to-disable-touchscreen-in-xps-17/" rel="alternate" type="text/html" title="How to Disable Touchscreen in Ubuntu 20.04 on a Dell XPS 17" /><published>2023-06-19T00:00:00+00:00</published><updated>2023-06-19T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2023/06/19/how-to-disable-touchscreen-in-xps-17</id><content type="html" xml:base="https://blog.ipepe.pl/2023/06/19/how-to-disable-touchscreen-in-xps-17/"><![CDATA[<p>The touchscreen feature on a laptop can sometimes be more of a hindrance than a help. There are times when you might accidentally touch the screen, resulting in unwanted clicks or drags. Thankfully, there’s an easy way to disable this feature on your Dell XPS 17 running Ubuntu 20.04.</p>

<p>First, <strong>identify your touchscreen device</strong> by opening the Terminal. You can do this by searching for “Terminal” in your applications menu, or by pressing <code class="language-plaintext highlighter-rouge">Ctrl+Alt+T</code>. In the terminal, type the following command:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>xinput
</code></pre></div></div>
<p>This command will display a list of all input devices. Find your touchscreen in this list, which might be named something like “ELAN Touchscreen” or “FTSC1000:00 2808:1015”.</p>

<p>Next, <strong>disable the touchscreen</strong> using the <code class="language-plaintext highlighter-rouge">xinput disable [id]</code> command, replacing [id] with your touchscreen device’s ID number. If your touchscreen’s ID is 10, for instance, you would enter:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>xinput disable 10
</code></pre></div></div>
<p>Please remember to replace [id] with your own device’s ID. Be careful not to disable other devices as it might affect the functionality of your mouse, keyboard, or other important input devices.</p>

<p>This method will only disable the touchscreen until the next reboot. For a permanent solution, consider adding the command to a startup script. However, the process to do this may vary depending on your desktop environment.</p>

<p>By following these steps, you can easily control the touchscreen feature on your Dell XPS 17 and make your Ubuntu 20.04 experience even more enjoyable.</p>

<hr />

<p><em>Disclaimer:</em> Be sure to replace “[id]” with the actual ID number of your touchscreen. Each hardware configuration will have a unique ID. Be careful not to disable any other devices, as you might lose the ability to use your mouse, keyboard, or other important input devices.</p>]]></content><author><name>Patryk Ptasiński</name></author><category term="linux" /><category term="ubuntu" /><category term="xps" /><summary type="html"><![CDATA[The touchscreen feature on a laptop can sometimes be more of a hindrance than a help. There are times when you might accidentally touch the screen, resulting in unwanted clicks or drags. Thankfully, there’s an easy way to disable this feature on your Dell XPS 17 running Ubuntu 20.04.]]></summary></entry><entry><title type="html">How to Permanently Hide a Volume in Windows using Diskpart and Registry</title><link href="https://blog.ipepe.pl/2023/06/17/how-to-hide-volume-in-diskpart/" rel="alternate" type="text/html" title="How to Permanently Hide a Volume in Windows using Diskpart and Registry" /><published>2023-06-17T00:00:00+00:00</published><updated>2023-06-17T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2023/06/17/how-to-hide-volume-in-diskpart</id><content type="html" xml:base="https://blog.ipepe.pl/2023/06/17/how-to-hide-volume-in-diskpart/"><![CDATA[<p>Are you looking to tidy up your workspace by hiding volumes in Windows that you don’t often use? While Windows provides a temporary solution, you may notice the hidden volume reappearing after a restart. Luckily, there’s a way to hide these volumes permanently.</p>

<p>Before we start, remember that making changes to your system can have significant effects, especially when using the <strong>DiskPart</strong> utility or editing the <strong>Windows Registry</strong>. Always back up your data and double-check all steps.</p>

<h3 id="hiding-a-volume-temporarily">Hiding a Volume Temporarily</h3>
<p>Firstly, here’s how you can temporarily hide a volume using the DiskPart utility:</p>

<ol>
  <li>Open the <strong>Command Prompt</strong> as an Administrator (Press <code class="language-plaintext highlighter-rouge">Win + X</code> -&gt; Choose “Command Prompt (Admin)”).</li>
  <li>Launch DiskPart by typing <code class="language-plaintext highlighter-rouge">diskpart</code> and pressing <code class="language-plaintext highlighter-rouge">Enter</code>.</li>
  <li>List all volumes by entering <code class="language-plaintext highlighter-rouge">list volume</code>.</li>
  <li>Identify and select the volume you want to hide: <code class="language-plaintext highlighter-rouge">select volume X</code> (Replace <code class="language-plaintext highlighter-rouge">X</code> with the volume number).</li>
  <li>Remove the drive letter to hide the volume: <code class="language-plaintext highlighter-rouge">remove letter=Y</code> (Replace <code class="language-plaintext highlighter-rouge">Y</code> with the letter assigned to the volume).</li>
</ol>

<p>This will hide the chosen volume, and it won’t appear in File Explorer. However, the volume will reappear after a system restart.</p>

<h3 id="hiding-a-volume-permanently">Hiding a Volume Permanently</h3>
<p>For a more permanent solution, you need to dive into the Windows Registry:</p>

<ol>
  <li>Press <code class="language-plaintext highlighter-rouge">Win + R</code>, type <code class="language-plaintext highlighter-rouge">regedit</code> and hit <code class="language-plaintext highlighter-rouge">Enter</code> to open <strong>Registry Editor</strong>.</li>
  <li>Navigate to <code class="language-plaintext highlighter-rouge">HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices</code>.</li>
  <li>Find the registry key corresponding to the drive letter you want to hide: <code class="language-plaintext highlighter-rouge">\DosDevices\X:</code>, where <code class="language-plaintext highlighter-rouge">X</code> is the drive letter.</li>
  <li>Right-click on the key, select <code class="language-plaintext highlighter-rouge">Rename</code>, and change <code class="language-plaintext highlighter-rouge">\DosDevices\X:</code> to <code class="language-plaintext highlighter-rouge">\DosDevices\ZZX:</code> (<code class="language-plaintext highlighter-rouge">ZZ</code> being a unique prefix).</li>
  <li>Restart your computer.</li>
</ol>

<p>Voila! The drive should remain hidden even after a system restart.</p>

<blockquote>
  <p><strong>Note:</strong> Always exercise caution when modifying the Windows Registry as incorrect modifications can lead to serious system issues.</p>
</blockquote>

<p>By following these steps, you can create a more streamlined and uncluttered workspace, ensuring that only the most essential volumes are in sight!</p>]]></content><author><name>Patryk Ptasiński</name></author><category term="windows" /><category term="diskpart" /><summary type="html"><![CDATA[Are you looking to tidy up your workspace by hiding volumes in Windows that you don’t often use? While Windows provides a temporary solution, you may notice the hidden volume reappearing after a restart. Luckily, there’s a way to hide these volumes permanently.]]></summary></entry><entry><title type="html">Why small ‘it’s are bad</title><link href="https://blog.ipepe.pl/2023/05/19/why-small-its-are-bad/" rel="alternate" type="text/html" title="Why small ‘it’s are bad" /><published>2023-05-19T00:00:00+00:00</published><updated>2023-05-19T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2023/05/19/why-small-its-are-bad</id><content type="html" xml:base="https://blog.ipepe.pl/2023/05/19/why-small-its-are-bad/"><![CDATA[<p>I recently was tasked with optimizing a very slow test suite. While looking at it, I noticed that we had a lot of small <code class="language-plaintext highlighter-rouge">it</code> blocks that had very slow <code class="language-plaintext highlighter-rouge">before</code> blocks running before them.</p>

<p>Instead of running each <code class="language-plaintext highlighter-rouge">it</code> block separately with the entire setup each time, a clever solution was provided by <a href="https://test-prof.evilmartians.io/">TestProf</a> through their <code class="language-plaintext highlighter-rouge">RuboCop</code> cops. They encourage using one of RSpec’s excellent features – the aggregation of failures within a single example. This approach permits grouping independent assertions together, running all setup hooks only once and considerably boosting test suite performance by reducing the total number of examples.</p>

<p>This change required only a minor alteration to our <code class="language-plaintext highlighter-rouge">.rubocop.yml</code> file to enable the <code class="language-plaintext highlighter-rouge">RuboCop</code> cops:</p>

<div class="language-yml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># .rubocop.yml</span>
<span class="na">require</span><span class="pi">:</span>
 <span class="pi">-</span> <span class="s1">'</span><span class="s">test_prof/rubocop'</span>
</code></pre></div></div>

<p>One of the cops provided by TestProf is <code class="language-plaintext highlighter-rouge">RSpec/AggregateExamples</code>. Here’s an example of how to modify your tests to take advantage of it:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># before</span>
<span class="n">it</span> <span class="p">{</span> <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">be_success</span> <span class="p">}</span>
<span class="n">it</span> <span class="p">{</span> <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">have_header</span><span class="p">(</span><span class="s2">"X-TOTAL-PAGES"</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span> <span class="p">}</span>
<span class="n">it</span> <span class="p">{</span> <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">have_header</span><span class="p">(</span><span class="s2">"X-NEXT-PAGE"</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="p">}</span>
<span class="n">its</span><span class="p">(</span><span class="ss">:status</span><span class="p">)</span> <span class="p">{</span> <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">eq</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span> <span class="p">}</span>

<span class="c1"># after</span>
<span class="n">it</span> <span class="s2">"returns the second page"</span><span class="p">,</span> <span class="ss">:aggregate_failures</span> <span class="k">do</span>
  <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">be_success</span>
  <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">have_header</span><span class="p">(</span><span class="s2">"X-TOTAL-PAGES"</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
  <span class="n">is_expected</span><span class="p">.</span><span class="nf">to</span> <span class="n">have_header</span><span class="p">(</span><span class="s2">"X-NEXT-PAGE"</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
  <span class="n">expect</span><span class="p">(</span><span class="n">subject</span><span class="p">.</span><span class="nf">status</span><span class="p">).</span><span class="nf">to</span> <span class="n">eq</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span>
<span class="k">end</span>
</code></pre></div></div>

<p>Notice that we now have just a single <code class="language-plaintext highlighter-rouge">it</code> block with multiple assertions. This allows the setup (the <code class="language-plaintext highlighter-rouge">before</code> blocks) to run only once for this group of assertions, rather than once per assertion, dramatically speeding up our test suite.</p>

<p>Also, TestProf’s <code class="language-plaintext highlighter-rouge">RuboCop</code> cops come with an auto-correct feature, which can make these adjustments automatically!</p>

<p>For more details on this and other cops provided by TestProf, you can check out their <a href="https://test-prof.evilmartians.io/#/misc/rubocop?id=rspecaggregateexamples">documentation</a>. Happy testing!</p>

<p>Sources:</p>
<ul>
  <li><a href="https://test-prof.evilmartians.io/#/misc/rubocop?id=rspecaggregateexamples">https://test-prof.evilmartians.io/#/misc/rubocop?id=rspecaggregateexamples</a></li>
</ul>]]></content><author><name>Patryk Ptasiński</name></author><category term="ruby" /><category term="rails" /><category term="testing" /><summary type="html"><![CDATA[I recently was tasked with optimizing a very slow test suite. While looking at it, I noticed that we had a lot of small it blocks that had very slow before blocks running before them.]]></summary></entry><entry><title type="html">How to turn on ActiveRecord query tracing</title><link href="https://blog.ipepe.pl/2023/05/18/how-to-turn-on-activerecord-query-tracing/" rel="alternate" type="text/html" title="How to turn on ActiveRecord query tracing" /><published>2023-05-18T00:00:00+00:00</published><updated>2023-05-18T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2023/05/18/how-to-turn-on-activerecord-query-tracing</id><content type="html" xml:base="https://blog.ipepe.pl/2023/05/18/how-to-turn-on-activerecord-query-tracing/"><![CDATA[<p>When working with ActiveRecord in Ruby on Rails, it can be helpful to see all SQL queries that are executed. This can help with debugging and optimizing your application. In this post, we’ll show you how to turn on ActiveRecord query tracing.</p>

<h3 id="built-in-method">Built-in Method</h3>

<p>Rails provides a built-in method to turn on query tracing. You can do this by setting the <code class="language-plaintext highlighter-rouge">verbose_query_logs</code> option to <code class="language-plaintext highlighter-rouge">true</code> in your <code class="language-plaintext highlighter-rouge">config/application.rb</code> file:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># config/application.rb</span>
<span class="n">config</span><span class="p">.</span><span class="nf">active_record</span><span class="p">.</span><span class="nf">verbose_query_logs</span> <span class="o">=</span> <span class="kp">true</span>
</code></pre></div></div>

<p>This will log all SQL queries to your console.</p>

<h3 id="gem">Gem</h3>

<p>Alternatively, you can use the <code class="language-plaintext highlighter-rouge">active-record-query-trace</code> gem to turn on query tracing. This gem provides more detailed information about the queries that are executed.</p>

<p>To use the gem, add it to your Gemfile:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Gemfile</span>
<span class="n">gem</span> <span class="s1">'active-record-query-trace'</span>
</code></pre></div></div>

<p>Then, enable query tracing in an initializer file:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># config/initializers/active_record_query_trace.rb</span>
<span class="k">if</span> <span class="no">Rails</span><span class="p">.</span><span class="nf">env</span><span class="p">.</span><span class="nf">development?</span>
  <span class="no">ActiveRecordQueryTrace</span><span class="p">.</span><span class="nf">enabled</span> <span class="o">=</span> <span class="kp">true</span>
<span class="k">end</span>
</code></pre></div></div>

<p>This will log all SQL queries to your console, along with information about the source of the query (e.g. file name and line number).</p>

<h3 id="conclusion">Conclusion</h3>

<p>By turning on ActiveRecord query tracing, you can get a better understanding of the SQL queries that are executed by your application. This can help you identify and fix performance issues, as well as debug any issues that arise.</p>]]></content><author><name>Patryk Ptasiński</name></author><category term="ruby" /><category term="rails" /><category term="activerecord" /><summary type="html"><![CDATA[When working with ActiveRecord in Ruby on Rails, it can be helpful to see all SQL queries that are executed. This can help with debugging and optimizing your application. In this post, we’ll show you how to turn on ActiveRecord query tracing.]]></summary></entry><entry><title type="html">My Onshape feature scripts</title><link href="https://blog.ipepe.pl/2023/05/01/my-onshape-feature-scripts/" rel="alternate" type="text/html" title="My Onshape feature scripts" /><published>2023-05-01T00:00:00+00:00</published><updated>2023-05-01T00:00:00+00:00</updated><id>https://blog.ipepe.pl/2023/05/01/my-onshape-feature-scripts</id><content type="html" xml:base="https://blog.ipepe.pl/2023/05/01/my-onshape-feature-scripts/"><![CDATA[<h2 id="timing-belts---gt2-2mm-and-gt2-3mm">Timing belts - GT2-2mm and GT2-3mm</h2>
<p>URL: <a href="https://cad.onshape.com/documents/55ae3138e0cd7c325239208b/w/c97698491e3111712f79c19b/e/d2190ac9a7351530ae3efe66?renderMode=0&amp;uiState=62f0911532b0144649ff3945">https://cad.onshape.com/documents/55ae3138e0cd7c325239208b/w/c97698491e3111712f79c19b/e/d2190ac9a7351530ae3efe66?renderMode=0&amp;uiState=62f0911532b0144649ff3945</a></p>]]></content><author><name>Patryk Ptasiński</name></author><category term="onshape" /><category term="cad" /><summary type="html"><![CDATA[Timing belts - GT2-2mm and GT2-3mm URL: https://cad.onshape.com/documents/55ae3138e0cd7c325239208b/w/c97698491e3111712f79c19b/e/d2190ac9a7351530ae3efe66?renderMode=0&amp;uiState=62f0911532b0144649ff3945]]></summary></entry></feed>