<?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://barnesian.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://barnesian.com/" rel="alternate" type="text/html" /><updated>2026-06-05T21:50:10+00:00</updated><id>https://barnesian.com/feed.xml</id><title type="html">Barnesian</title><subtitle>Software Development and Audio Engineering</subtitle><entry><title type="html">Getting The Root Path of an Electron Application</title><link href="https://barnesian.com/getting-the-root-path-of-an-electron-application/" rel="alternate" type="text/html" title="Getting The Root Path of an Electron Application" /><published>2020-06-18T00:00:00+00:00</published><updated>2020-06-18T00:00:00+00:00</updated><id>https://barnesian.com/getting-the-root-path-of-an-electron-application</id><content type="html" xml:base="https://barnesian.com/getting-the-root-path-of-an-electron-application/"><![CDATA[<p>If you wound up here somehow, you are no doubt confused about how to get the root directory of an Electron app. It’s surprisingly complicated depending on the environmental setup. The path works a little differently in development mode than it does in a fully packaged application in an <a href="https://github.com/electron/asar">asar archive</a>. If you’re having trouble, make sure you test both scenarios.</p>

<p>There’s an <a href="https://www.electronjs.org/docs/api/app#appgetapppath">API that was added at some point that does exactly this</a>. Unfortunately, that won’t work in the renderer process. If you’re in the background process, then that should work just fine. Also worth noting, if you’re doing file access and dealing with paths, you probably ** should ** be in the background process. Take a minute to think about that and whether or not you should refactor to make that a reality. There’s also another way to get at this, as suggested by <a href="https://stackoverflow.com/questions/37213696/how-can-i-get-the-path-that-the-application-is-running-with-typescript">this StackOverflow post</a>.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">electron</span><span class="dl">'</span><span class="p">).</span><span class="nx">remote</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">getAppPath</span><span class="p">();</span>
</code></pre></div></div>

<p>For whatever reason, perhaps an outdated Electron version, that did not work when I tried it. There’s a surprisingly simple solution to this. If you’re using a bundler, this may be a little different.</p>

<p>Here’s the trick that works no matter what. Put a file at the root of the application, called <code class="language-plaintext highlighter-rouge">rootPath.js</code> and return <code class="language-plaintext highlighter-rouge">__dirname</code>. <a href="https://nodejs.org/docs/latest/api/globals.html#globals_dirname">__dirname in Node</a> is the directory of the currently executing file. Since it is at the root, this will always give you the root path.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">default</span> <span class="kd">function</span> <span class="nx">rootPath</span><span class="p">()</span> <span class="p">{</span>
  <span class="k">return</span> <span class="nx">__dirname</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Import it however you usually import things, and call it and you’ll get the root path.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nx">rootPath</span> <span class="k">from</span> <span class="dl">'</span><span class="s1">rootPath</span><span class="dl">'</span><span class="p">;</span>
<span class="k">import</span> <span class="nx">path</span> <span class="k">from</span> <span class="dl">'</span><span class="s1">path</span><span class="dl">'</span><span class="p">;</span>
<span class="c1">//or</span>
<span class="kd">const</span> <span class="nx">rootPath</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">rootPath</span><span class="dl">'</span><span class="p">);</span>
<span class="kd">const</span> <span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">path</span><span class="dl">'</span><span class="p">);</span>

<span class="kd">const</span> <span class="nx">somePath</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">resolve</span><span class="p">(</span><span class="s2">`</span><span class="p">${</span><span class="nx">rootPath</span><span class="p">()}</span><span class="s2">/some/path/to/something`</span><span class="p">);</span>
</code></pre></div></div>

<p>That’s it! After some hand wringing, that works all the time, everywhere, no matter what. Undoubtedly, it won’t work for someone, and we’ll hear from them in the comments.</p>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[If you wound up here somehow, you are no doubt confused about how to get the root directory of an Electron app. It’s surprisingly complicated depending on the environmental setup. The path works a little differently in development mode than it does in a fully packaged application in an asar archive. If you’re having trouble, make sure you test both scenarios. There’s an API that was added at some point that does exactly this. Unfortunately, that won’t work in the renderer process. If you’re in the background process, then that should work just fine. Also worth noting, if you’re doing file access and dealing with paths, you probably ** should ** be in the background process. Take a minute to think about that and whether or not you should refactor to make that a reality. There’s also another way to get at this, as suggested by this StackOverflow post. require('electron').remote.app.getAppPath(); For whatever reason, perhaps an outdated Electron version, that did not work when I tried it. There’s a surprisingly simple solution to this. If you’re using a bundler, this may be a little different. Here’s the trick that works no matter what. Put a file at the root of the application, called rootPath.js and return __dirname. __dirname in Node is the directory of the currently executing file. Since it is at the root, this will always give you the root path. export default function rootPath() { return __dirname; } Import it however you usually import things, and call it and you’ll get the root path. import rootPath from 'rootPath'; import path from 'path'; //or const rootPath = require('rootPath'); const path = require('path'); const somePath = path.resolve(`${rootPath()}/some/path/to/something`); That’s it! After some hand wringing, that works all the time, everywhere, no matter what. Undoubtedly, it won’t work for someone, and we’ll hear from them in the comments.]]></summary></entry><entry><title type="html">Deep Merging JavaScript Objects</title><link href="https://barnesian.com/deep-merging-javascript-objects/" rel="alternate" type="text/html" title="Deep Merging JavaScript Objects" /><published>2020-03-25T00:00:00+00:00</published><updated>2020-03-25T00:00:00+00:00</updated><id>https://barnesian.com/deep-merging-javascript-objects</id><content type="html" xml:base="https://barnesian.com/deep-merging-javascript-objects/"><![CDATA[<p><img src="/assets/posts//deep-merging-javascript-objects/merge-objects-code.png" alt="" /></p>

<p>Deep merging objects in JavaScript is a bit tricky. Here’s one solution; there are many many others. While this was fun to write, you’ll probably want to go <a href="https://lodash.com/docs#merge">use the merge function in lodash instead</a>. None the less here’s some code golf</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">merge</span><span class="p">(...</span><span class="nx">sources</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="nx">sources</span><span class="p">.</span><span class="nx">reduce</span><span class="p">((</span><span class="nx">target</span><span class="p">,</span> <span class="nx">source</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>  <span class="c1">// enumerate the sources</span>
    <span class="k">return</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">entries</span><span class="p">(</span><span class="nx">source</span><span class="p">).</span><span class="nx">reduce</span><span class="p">((</span><span class="nx">result</span><span class="p">,</span> <span class="p">[</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">])</span> <span class="o">=&gt;</span> <span class="p">{</span>  <span class="c1">// enumerate the properties</span>
      <span class="k">if</span><span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="p">{</span>
        <span class="k">if</span><span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]))</span> <span class="p">{</span>
          <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">].</span><span class="nx">concat</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span> <span class="c1">// got two arrays, merge them</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
          <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>  <span class="c1">// clobber it, either undefined or not an array</span>
        <span class="p">}</span>
      <span class="p">}</span> <span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">value</span> <span class="o">===</span> <span class="nb">Object</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="p">{</span>
        <span class="k">if</span><span class="p">(</span><span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">===</span> <span class="nb">Object</span><span class="p">(</span><span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]))</span> <span class="p">{</span>
          <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">],</span> <span class="nx">value</span><span class="p">);</span> <span class="c1">// two objects, recurse and merge them</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
          <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span> <span class="c1">// recurse and clobber it, either undefined or not an object</span>
        <span class="p">}</span>
      <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>  <span class="c1">// must be a primitive, clobber it</span>
      <span class="p">}</span>
      <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
    <span class="p">},</span> <span class="nx">target</span><span class="p">);</span>
  <span class="p">},</span> <span class="p">{});</span>
<span class="p">}</span>
</code></pre></div></div>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[Deep merging objects in JavaScript is a bit tricky. Here’s one solution; there are many many others. While this was fun to write, you’ll probably want to go use the merge function in lodash instead. None the less here’s some code golf function merge(...sources) { return sources.reduce((target, source) =&gt; { // enumerate the sources return Object.entries(source).reduce((result, [key, value]) =&gt; { // enumerate the properties if(Array.isArray(value)) { if(Array.isArray(result[key])) { result[key] = result[key].concat(value); // got two arrays, merge them } else { result[key] = value; // clobber it, either undefined or not an array } } else if(value === Object(value)) { if(result[key] === Object(result[key])) { result[key] = merge(result[key], value); // two objects, recurse and merge them } else { result[key] = merge(value); // recurse and clobber it, either undefined or not an object } } else { result[key] = value; // must be a primitive, clobber it } return result; }, target); }, {}); }]]></summary></entry><entry><title type="html">Fastmail Settings for WP Mail SMTP</title><link href="https://barnesian.com/fastmail-settings-for-wp-mail-smtp/" rel="alternate" type="text/html" title="Fastmail Settings for WP Mail SMTP" /><published>2020-03-25T00:00:00+00:00</published><updated>2020-03-25T00:00:00+00:00</updated><id>https://barnesian.com/fastmail-settings-for-wp-mail-smtp</id><content type="html" xml:base="https://barnesian.com/fastmail-settings-for-wp-mail-smtp/"><![CDATA[<p><img src="/assets/posts//fastmail-settings-for-wp-mail-smtp/fastmail-panel.png" alt="" /></p>

<p>After having migrated my mail provider from <a href="https://outlook.com/">Outlook.com</a> to <a href="https://www.fastmail.com/">Fastmail</a> I needed to get the contact form up and running for <a href="https://wordpress.org">WordPress</a>. The Fastmail settings are <a href="https://www.fastmail.com/help/clients/defineimap.html">plainly available and located over here</a>.</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SMTP Host: smtp.fastmail.com
Encryption: SSL
SMTP Port: 465
Auto TLS: On
Authentication: On
SMTP Username: your primary email address
SMTP Password: &lt;your password, use at your own risk, it’s better to use WordPress variables for this&gt;
</code></pre></div></div>

<p>While your primary password may work, it’s better to create a unique password per application using Fastmail. This password can be revoked easily if something goes wrong. In Fastmail, under <code class="language-plaintext highlighter-rouge">Settings -&gt; Password &amp; Security</code> you’ll see there is a section called App Passwords. Generate a new password here and put these two variables into <code class="language-plaintext highlighter-rouge">wp-config.php</code></p>
<div class="language-php highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">define</span><span class="p">(</span><span class="s1">'WPMS_ON'</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
<span class="nb">define</span><span class="p">(</span><span class="s1">'WPMS_SMTP_PASS'</span><span class="p">,</span> <span class="s1">'your per application password'</span><span class="p">);</span>
</code></pre></div></div>
<p>Use the “Send a Test Email” section to make sure everything works.</p>

<p>If you have a firewall setup (and you should), you’ll have to let that traffic out as well. If you are using Linux and iptables here are the iptables rules that allow that traffic to get out while still blocking new incoming connections on port 465. Note these must be run with <code class="language-plaintext highlighter-rouge">sudo</code></p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>iptables <span class="nt">-A</span> OUTPUT <span class="nt">-p</span> tcp –sport 465 <span class="nt">-m</span> state –state NEW,ESTABLISHED <span class="nt">-j</span> ACCEPT
iptables <span class="nt">-A</span> OUTPUT <span class="nt">-p</span> tcp –dport 465 <span class="nt">-m</span> state –state NEW,ESTABLISHED <span class="nt">-j</span> ACCEPT
iptables <span class="nt">-A</span> INPUT <span class="nt">-p</span> tcp –sport 465 <span class="nt">-m</span> state –state RELATED,ESTABLISHED <span class="nt">-j</span> ACCEPT
</code></pre></div></div>
<p>And now you’ve got WordPress using Fastmail for all of the notifications. Enjoy</p>]]></content><author><name></name></author><category term="Software" /><summary type="html"><![CDATA[After having migrated my mail provider from Outlook.com to Fastmail I needed to get the contact form up and running for WordPress. The Fastmail settings are plainly available and located over here. SMTP Host: smtp.fastmail.com Encryption: SSL SMTP Port: 465 Auto TLS: On Authentication: On SMTP Username: your primary email address SMTP Password: &lt;your password, use at your own risk, it’s better to use WordPress variables for this&gt; While your primary password may work, it’s better to create a unique password per application using Fastmail. This password can be revoked easily if something goes wrong. In Fastmail, under Settings -&gt; Password &amp; Security you’ll see there is a section called App Passwords. Generate a new password here and put these two variables into wp-config.php define('WPMS_ON', true); define('WPMS_SMTP_PASS', 'your per application password'); Use the “Send a Test Email” section to make sure everything works. If you have a firewall setup (and you should), you’ll have to let that traffic out as well. If you are using Linux and iptables here are the iptables rules that allow that traffic to get out while still blocking new incoming connections on port 465. Note these must be run with sudo iptables -A OUTPUT -p tcp –sport 465 -m state –state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -p tcp –dport 465 -m state –state NEW,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp –sport 465 -m state –state RELATED,ESTABLISHED -j ACCEPT And now you’ve got WordPress using Fastmail for all of the notifications. Enjoy]]></summary></entry><entry><title type="html">Perfect Footers</title><link href="https://barnesian.com/perfect-footers/" rel="alternate" type="text/html" title="Perfect Footers" /><published>2017-02-15T00:00:00+00:00</published><updated>2017-02-15T00:00:00+00:00</updated><id>https://barnesian.com/perfect-footers</id><content type="html" xml:base="https://barnesian.com/perfect-footers/"><![CDATA[<p><img src="/assets/posts//perfect-footers/footer.png" alt="" /></p>

<p>Styling footers proves to be a bit tricky. On a site where there’s a lot of content, this is not an issue. However, if you want to have the page be full height and scroll when the content overflows, there is some subtlety to styling the footer. It’s pretty easy to accidentally have the footer float in the middle of the page when the content overflows and the page scrolls. It’s also pretty easy to have the content hide underneath the footer. I am hardly the first person to write about this; this post was inspired by and slightly modified from <a href="http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page">this blog post</a>.</p>

<p>Here’s how to deal with that. First of all, if you don’t have a normalize and reset, you should probably do that. In the example I’ve included a quick reset of body and all of the header elements. Without that reset this won’t quite work like you might expect. The kernel of getting the page to be full height while allowing it to scroll is setting <code class="language-plaintext highlighter-rouge">html</code> to <code class="language-plaintext highlighter-rouge">height: 100%</code> and setting <code class="language-plaintext highlighter-rouge">body</code> to <code class="language-plaintext highlighter-rouge">min-height: 100%</code> and <code class="language-plaintext highlighter-rouge">position: relative</code>. With those styles, it allows the short pages to be full height, without scroll bars, and allows longer pages to scroll and keep the footer at the bottom. Finally, another important note: the main content container needs to have some padding so its content doesn’t hide underneath the footer.</p>

<p>A demo is worth many words; here’s a CodePen:</p>
<iframe allowfullscreen="true" allowpaymentrequest="true" allowtransparency="true" class="cp_embed_iframe " name="cp_embed_1" scrolling="no" src="https://codepen.io/chrishalebarnes/embed/egoOoX?height=400&amp;theme-id=0&amp;slug-hash=egoOoX&amp;default-tab=result&amp;user=chrishalebarnes&amp;embed-version=2&amp;pen-title=Perfect%20Footer&amp;name=cp_embed_1" style="width: 100%; overflow:hidden; display:block;" title="Perfect Footer" loading="lazy" id="cp_embed_egoOoX" width="100%" height="400" frameborder="0"></iframe>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[Styling footers proves to be a bit tricky. On a site where there’s a lot of content, this is not an issue. However, if you want to have the page be full height and scroll when the content overflows, there is some subtlety to styling the footer. It’s pretty easy to accidentally have the footer float in the middle of the page when the content overflows and the page scrolls. It’s also pretty easy to have the content hide underneath the footer. I am hardly the first person to write about this; this post was inspired by and slightly modified from this blog post. Here’s how to deal with that. First of all, if you don’t have a normalize and reset, you should probably do that. In the example I’ve included a quick reset of body and all of the header elements. Without that reset this won’t quite work like you might expect. The kernel of getting the page to be full height while allowing it to scroll is setting html to height: 100% and setting body to min-height: 100% and position: relative. With those styles, it allows the short pages to be full height, without scroll bars, and allows longer pages to scroll and keep the footer at the bottom. Finally, another important note: the main content container needs to have some padding so its content doesn’t hide underneath the footer. A demo is worth many words; here’s a CodePen:]]></summary></entry><entry><title type="html">Quick Tip: Download Offline Documentation with wget</title><link href="https://barnesian.com/download-offline-documentation-with-wget/" rel="alternate" type="text/html" title="Quick Tip: Download Offline Documentation with wget" /><published>2016-12-17T00:00:00+00:00</published><updated>2016-12-17T00:00:00+00:00</updated><id>https://barnesian.com/download-offline-documentation-with-wget</id><content type="html" xml:base="https://barnesian.com/download-offline-documentation-with-wget/"><![CDATA[<p>Here’s a quick way to download developer documentation for any language or framework that has a public website. Maybe you’re about to get on a plane or train that doesn’t have WiFi and you want to use that dead time to actually get some development work done. The key here is two switches in the <code class="language-plaintext highlighter-rouge">wget</code> command, <code class="language-plaintext highlighter-rouge">–r</code> and <code class="language-plaintext highlighter-rouge">–k</code>.</p>

<p>Given any URL you can download all pages recursively and have wget convert the links to local links after the download is complete. You could, for example, run this with the <a href="http://guides.rubyonrails.org/">Ruby on Rails Guides</a>. There is a wait included, which you can remove, but be aware that it might not be nice to overload some poor web server.</p>

<p>Here’s the command:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>wget —mirror —convert–links —adjust–extension —wait<span class="o">=</span>1 &lt;url&gt;
</code></pre></div></div>

<p>or the short form:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>wget –mkE –w 1 &lt;url&gt;
</code></pre></div></div>

<p>There are a lot more options which are all <a href="https://www.gnu.org/software/wget/manual/wget.html">documented here</a>. However, here are the options used here.</p>

<blockquote>
  <p>-k or –convert-links</p>
</blockquote>

<p>Converts links on the downloaded pages into local filesystem links 1ctvbeq.</p>

<blockquote>
  <p>-E or –adjust-extension</p>
</blockquote>

<p>Saves files according their content type; CSS will be saved as a .css file for example</p>

<blockquote>
  <p>–mirror or -m</p>
</blockquote>

<p>Flips on a bunch of options for exactly this kind of purpose. It is equivalent to
–r –N –l inf —no–remove–listing</p>

<blockquote>
  <p>-r –recursive</p>
</blockquote>

<p>Downloads all webpages recursively. All links will be followed and those pages will be downloaded as well.</p>

<blockquote>
  <p>-l inf</p>
</blockquote>

<p>Sets the recursion level to infinite, so it will follow all links. This could be made smaller if you don’t want it to follow that many links.</p>

<blockquote>
  <p>-N or –timestamping</p>
</blockquote>

<p>Turns on timestamping so that if you fetch the pages again it will not download the file unless the timestamp has changed.</p>

<blockquote>
  <p>–no-remove-listing</p>
</blockquote>

<p>Not entirely sure about this one, but it has something to do with FTP files. See the <a href="https://www.gnu.org/software/wget/manual/wget.html">documentation for it here</a>.</p>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[Here’s a quick way to download developer documentation for any language or framework that has a public website. Maybe you’re about to get on a plane or train that doesn’t have WiFi and you want to use that dead time to actually get some development work done. The key here is two switches in the wget command, –r and –k. Given any URL you can download all pages recursively and have wget convert the links to local links after the download is complete. You could, for example, run this with the Ruby on Rails Guides. There is a wait included, which you can remove, but be aware that it might not be nice to overload some poor web server. Here’s the command: wget —mirror —convert–links —adjust–extension —wait=1 &lt;url&gt; or the short form: wget –mkE –w 1 &lt;url&gt; There are a lot more options which are all documented here. However, here are the options used here. -k or –convert-links Converts links on the downloaded pages into local filesystem links 1ctvbeq. -E or –adjust-extension Saves files according their content type; CSS will be saved as a .css file for example –mirror or -m Flips on a bunch of options for exactly this kind of purpose. It is equivalent to –r –N –l inf —no–remove–listing -r –recursive Downloads all webpages recursively. All links will be followed and those pages will be downloaded as well. -l inf Sets the recursion level to infinite, so it will follow all links. This could be made smaller if you don’t want it to follow that many links. -N or –timestamping Turns on timestamping so that if you fetch the pages again it will not download the file unless the timestamp has changed. –no-remove-listing Not entirely sure about this one, but it has something to do with FTP files. See the documentation for it here.]]></summary></entry><entry><title type="html">How to Fix Dell XPS 13 Touchscreen and Suspend Issues In Fedora</title><link href="https://barnesian.com/how-to-fix-dell-xps-13-touchscreen/" rel="alternate" type="text/html" title="How to Fix Dell XPS 13 Touchscreen and Suspend Issues In Fedora" /><published>2016-11-11T00:00:00+00:00</published><updated>2016-11-11T00:00:00+00:00</updated><id>https://barnesian.com/how-to-fix-dell-xps-13-touchscreen</id><content type="html" xml:base="https://barnesian.com/how-to-fix-dell-xps-13-touchscreen/"><![CDATA[<p>After updating <a href="https://getfedora.org/">Fedora</a> on my <a href="http://www.dell.com/us/business/p/xps-13-linux/pd">Dell XPS 13 Developer Edition</a>, the suspend/resume stopped functioning. After resuming from being suspended, the laptop would immediately reboot. There had also been a long running issue where the touchscreen would not work after resuming from being suspended. The latter did not bother me that much, since I don’t feel the need to use the touchscreen all that often. The former, however, was going to be a huge issue. After a lot of digging and trying out all kinds of things, I stumbled upon something that finally worked. As it turns out, this also seems to have fixed the touchscreen issue as well. I’m still not entirely sure if the update fixed the touchscreen or if this kernel parameter fixed the touchscreen. I’m also still not entirely sure what this parameter actually does or if there are some drawbacks to using it. Anyway, I wanted to write this down here in case it helped someone else who has the same issue.</p>

<p>The fix ended up being adding a parameter to the Linux kernel via Grub. That parameter is <code class="language-plaintext highlighter-rouge">acpi_sleep=nonvs</code></p>

<p>Edit <code class="language-plaintext highlighter-rouge">/etc/default/grub</code> using whatever text editor you prefer and find the line that looks like this <code class="language-plaintext highlighter-rouge">GRUB_CMDLINE_LINUX="rhgb quiet"</code>. And you’ll need <code class="language-plaintext highlighter-rouge">sudo</code>
Add <code class="language-plaintext highlighter-rouge">acpi_sleep=nonvs</code> to the end of that string so it looks something like this</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">GRUB_CMDLINE_LINUX</span><span class="o">=</span><span class="s2">"&lt;a bunch of other parameters&gt;; rhgb quiet acpi_sleep=nonvs pcie_aspm=force acpi_osi=Linux"</span>
</code></pre></div></div>

<p>Now you have to update Grub. In Fedora there is no <a href="http://manpages.ubuntu.com/manpages/trusty/man8/update-grub.8.html">update-grub command</a> so you have to update it like this and then reboot. You’ll also need <code class="language-plaintext highlighter-rouge">sudo</code> to run this command.</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>grub2-mkconfig <span class="nt">-o</span> /boot/efi/EFI/fedora/grub.cfg
</code></pre></div></div>

<p>According to the <a href="https://github.com/torvalds/linux/blob/master/Documentation/kernel-parameters.txt">kernel parameters documentation</a>, this parameter “prevents the kernel from saving/restoring the ACPI NVS memory during suspend/hibernation and resume.”</p>

<p>Thanks to <a href="http://askubuntu.com/questions/24048/suspend-fails-reboot-on-resume-and-no-hibernate-option">this helpful thread</a> and this other <a href="https://ask.fedoraproject.org/en/question/80362/how-do-i-update-grub-in-fedora-23/">helpful thread over here</a>.</p>]]></content><author><name></name></author><category term="Technology" /><category term="Electronics" /><summary type="html"><![CDATA[After updating Fedora on my Dell XPS 13 Developer Edition, the suspend/resume stopped functioning. After resuming from being suspended, the laptop would immediately reboot. There had also been a long running issue where the touchscreen would not work after resuming from being suspended. The latter did not bother me that much, since I don’t feel the need to use the touchscreen all that often. The former, however, was going to be a huge issue. After a lot of digging and trying out all kinds of things, I stumbled upon something that finally worked. As it turns out, this also seems to have fixed the touchscreen issue as well. I’m still not entirely sure if the update fixed the touchscreen or if this kernel parameter fixed the touchscreen. I’m also still not entirely sure what this parameter actually does or if there are some drawbacks to using it. Anyway, I wanted to write this down here in case it helped someone else who has the same issue. The fix ended up being adding a parameter to the Linux kernel via Grub. That parameter is acpi_sleep=nonvs Edit /etc/default/grub using whatever text editor you prefer and find the line that looks like this GRUB_CMDLINE_LINUX="rhgb quiet". And you’ll need sudo Add acpi_sleep=nonvs to the end of that string so it looks something like this GRUB_CMDLINE_LINUX="&lt;a bunch of other parameters&gt;; rhgb quiet acpi_sleep=nonvs pcie_aspm=force acpi_osi=Linux" Now you have to update Grub. In Fedora there is no update-grub command so you have to update it like this and then reboot. You’ll also need sudo to run this command. grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg According to the kernel parameters documentation, this parameter “prevents the kernel from saving/restoring the ACPI NVS memory during suspend/hibernation and resume.” Thanks to this helpful thread and this other helpful thread over here.]]></summary></entry><entry><title type="html">Quick Tip: Routes for a Non-Resourceful Rails Controller</title><link href="https://barnesian.com/quick-tip-routes-for-a-non-resourceful-rails-controller/" rel="alternate" type="text/html" title="Quick Tip: Routes for a Non-Resourceful Rails Controller" /><published>2016-08-18T00:00:00+00:00</published><updated>2016-08-18T00:00:00+00:00</updated><id>https://barnesian.com/quick-tip-routes-for-a-non-resourceful-rails-controller</id><content type="html" xml:base="https://barnesian.com/quick-tip-routes-for-a-non-resourceful-rails-controller/"><![CDATA[<p><img src="/assets/posts//quick-tip-routes-for-a-non-resourceful-rails-controller/controller-route.png" alt="" /></p>

<p>Let’s say you have a few routes that are all related, but don’t really map to the usual resources. For example, a login/logout controller named SessionsController doesn’t really fit the usual resourceful route model. One could use the usual routes HTTP verb syntax like this</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Rails</span><span class="p">.</span><span class="nf">application</span><span class="p">.</span><span class="nf">routes</span><span class="p">.</span><span class="nf">draw</span> <span class="k">do</span>
  <span class="c1">#...</span>
  <span class="n">get</span>  <span class="s1">'login'</span><span class="p">,</span>  <span class="ss">to: </span><span class="s1">'sessions#index'</span>
  <span class="n">post</span> <span class="s1">'login'</span><span class="p">,</span>  <span class="ss">to: </span><span class="s1">'sessions#login'</span>
  <span class="n">post</span> <span class="s1">'logout'</span><span class="p">,</span> <span class="ss">to: </span><span class="s1">'sessions#logout'</span>
<span class="k">end</span>
</code></pre></div></div>

<p>However, there’s a nifty little helper that’s not in the <a href="http://guides.rubyonrails.org/routing.html">routing guide</a> but is in the <a href="http://api.rubyonrails.org/classes/ActionDispatch/Routing.html">API docs</a> called controller which feels a bit cleaner.</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="no">Rails</span><span class="p">.</span><span class="nf">application</span><span class="p">.</span><span class="nf">routes</span><span class="p">.</span><span class="nf">draw</span> <span class="k">do</span>
  <span class="c1">#...</span>
  <span class="n">controller</span> <span class="ss">:sessions</span> <span class="k">do</span>
    <span class="n">get</span>  <span class="ss">:login</span><span class="p">,</span>  <span class="ss">action: :index</span>
    <span class="n">post</span> <span class="ss">:login</span><span class="p">,</span>  <span class="ss">action: :login</span>
    <span class="n">post</span> <span class="ss">:logout</span><span class="p">,</span> <span class="ss">action: :logout</span>
  <span class="k">end</span>
<span class="k">end</span>
</code></pre></div></div>

<p>After running <code class="language-plaintext highlighter-rouge">rake routes</code> or <code class="language-plaintext highlighter-rouge">rails routes</code> to see what routes we’ve got, we’ll see three routes.</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>login  GET  /login<span class="o">(</span>.:format<span class="o">)</span>  sessions#index
       POST /login<span class="o">(</span>.:format<span class="o">)</span>  sessions#login
<span class="nb">logout </span>POST /logout<span class="o">(</span>.:format<span class="o">)</span> sessions#logout
</code></pre></div></div>

<p>If there’s an even better way, let me know in the comments!</p>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[Let’s say you have a few routes that are all related, but don’t really map to the usual resources. For example, a login/logout controller named SessionsController doesn’t really fit the usual resourceful route model. One could use the usual routes HTTP verb syntax like this Rails.application.routes.draw do #... get 'login', to: 'sessions#index' post 'login', to: 'sessions#login' post 'logout', to: 'sessions#logout' end However, there’s a nifty little helper that’s not in the routing guide but is in the API docs called controller which feels a bit cleaner. Rails.application.routes.draw do #... controller :sessions do get :login, action: :index post :login, action: :login post :logout, action: :logout end end After running rake routes or rails routes to see what routes we’ve got, we’ll see three routes. login GET /login(.:format) sessions#index POST /login(.:format) sessions#login logout POST /logout(.:format) sessions#logout If there’s an even better way, let me know in the comments!]]></summary></entry><entry><title type="html">SASS Antipattern: The Selector Bomb</title><link href="https://barnesian.com/sass-antipattern-selector-bomb/" rel="alternate" type="text/html" title="SASS Antipattern: The Selector Bomb" /><published>2016-01-14T00:00:00+00:00</published><updated>2016-01-14T00:00:00+00:00</updated><id>https://barnesian.com/sass-antipattern-selector-bomb</id><content type="html" xml:base="https://barnesian.com/sass-antipattern-selector-bomb/"><![CDATA[<p><img src="/assets/posts//sass-antipattern-selector-bomb/sass-extend-2.png" alt="" /></p>

<p>SASS is a really powerful tool, which sometimes means that one has to be careful. It can generate all kinds of insane CSS that is hard for debugging and hard for the browser to parse and apply. Now and then, you have to take a step back and ask yourself if you really need to use SASS for the task at hand. I’d like to attempt to coin a new term for an anti-pattern that I, and many others, have stumbled upon.</p>

<blockquote>
  <h4 id="the-selector-bomb">The Selector Bomb</h4>

  <p>A gigantic selector that is hard to debug and hard for the browser to parse and apply, generated by SASS when using <code class="language-plaintext highlighter-rouge">@extend</code> as a utility that spans across many selectors.</p>
</blockquote>

<h4 id="an-example">An Example</h4>

<p>There is a lot of jargon in the above statement. Let’s break it down with a clear example with three pages. Keep in mind that three pages is not really a problem, but when you scale this up to a huge amount of pages, it really becomes a problem. This especially applies to utility classes – something like a clearfix class or a text-align class. Each page has a panel with a different background color. This is a fairly common pattern, especially if you’re concatenating all of your CSS into a single file. You want to share the common styles and yet still change the background color. You decide to use a <a href="http://thesassway.com/intermediate/understanding-placeholder-selectors">SASS placeholder</a> and use <code class="language-plaintext highlighter-rouge">@extend</code> to bring in the common styles. Let’s have a look at the markup and SASS for each page.</p>

<h4 id="first-page">First Page</h4>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"panel"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;h2&gt;</span>Sass<span class="nt">&lt;/h2&gt;</span>
  <span class="nt">&lt;p&gt;</span>CSS with superpowers<span class="nt">&lt;/p&gt;</span>
<span class="nt">&lt;div&gt;</span>
</code></pre></div></div>
<div class="language-scss highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.page.sass</span> <span class="p">{</span>
  <span class="nc">.panel</span> <span class="p">{</span>
    <span class="k">@extend</span> <span class="nv">%panel</span><span class="p">;</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#e1faea</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
<h4 id="second-page">Second Page</h4>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"page stylus"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"panel css-library"</span><span class="nt">&gt;</span>
    <span class="nt">&lt;h2&gt;</span>Stylus<span class="nt">&lt;/h2&gt;</span>
    <span class="nt">&lt;p&gt;</span>Expressive, dynamic, robust CSS<span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>
<div class="language-scss highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.page.stylus</span> <span class="p">{</span>
  <span class="nc">.panel</span> <span class="p">{</span>
    <span class="k">@extend</span> <span class="nv">%panel</span><span class="p">;</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#def0fc</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<h4 id="third-page">Third Page</h4>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"page less"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"panel"</span><span class="nt">&gt;</span>
    <span class="nt">&lt;h2&gt;</span>Less<span class="nt">&lt;/h2&gt;</span>
    <span class="nt">&lt;p&gt;</span>Leaner CSS<span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>
<div class="language-scss highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.page.less</span> <span class="p">{</span>
  <span class="nc">.panel</span> <span class="p">{</span>
    <span class="k">@extend</span> <span class="nv">%panel</span><span class="p">;</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#ebebeb</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>And finally, the common styles are in the placeholder, which is extended in each panel.</p>
<div class="language-scss highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">%panel</span> <span class="p">{</span>
  <span class="nl">padding</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">margin</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">300px</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>This will render these three components on each of the three different pages.</p>

<p><img src="/assets/posts//sass-antipattern-selector-bomb/sass-panels.png" alt="" /></p>

<p>Unfortunately that will compile to this. See how it merges all of the selectors into one for the common styles? This is the <strong><em>selector bomb</em></strong>. Every time you add a page that has <code class="language-plaintext highlighter-rouge">@extend %panel</code> , it will add one more selector here. Do that across enough pages and you can get a huge selector that is hard to debug and hard for the browser to parse and apply.</p>
<div class="language-scss highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.page.sass</span> <span class="nc">.panel</span><span class="o">,</span> <span class="nc">.page.stylus</span> <span class="nc">.panel</span><span class="o">,</span> <span class="nc">.page.less</span> <span class="nc">.panel</span> <span class="p">{</span>
  <span class="nl">padding</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">margin</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">300px</span><span class="p">;</span>
<span class="p">}</span>

<span class="nc">.page.sass</span> <span class="nc">.panel</span> <span class="p">{</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#e1faea</span><span class="p">;</span>
<span class="p">}</span>

<span class="nc">.page.stylus</span> <span class="nc">.panel</span> <span class="p">{</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#def0fc</span><span class="p">;</span>
<span class="p">}</span>

<span class="nc">.page.less</span> <span class="nc">.panel</span> <span class="p">{</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#ebebeb</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<h4 id="solutions">Solutions</h4>

<p>There are a couple ways to get around this. Depending upon the context of what you’re doing, one of these (or even something else) may make sense. First, a mixin will alleviate the pain, since a mixin will actually copy the CSS everywhere it is included. This could cause more pain, since it makes the file size a bit larger. However, worrying about the size of a CSS file is very likely to be overthinking the problem.</p>
<div class="language-scss highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">@mixin</span> <span class="nf">panel</span><span class="p">()</span> <span class="p">{</span>
  <span class="nl">padding</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">margin</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">300px</span><span class="p">;</span>
<span class="p">}</span>

<span class="nc">.page.sass</span> <span class="p">{</span>
  <span class="nc">.panel</span> <span class="p">{</span>
    <span class="k">@include</span> <span class="nd">panel</span><span class="p">();</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#e1faea</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>

<span class="nc">.page.stylus</span> <span class="p">{</span>
  <span class="nc">.panel</span> <span class="p">{</span>
    <span class="k">@include</span> <span class="nd">panel</span><span class="p">();</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#def0fc</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>

<span class="nc">.page.less</span> <span class="p">{</span>
  <span class="nc">.panel</span> <span class="p">{</span>
    <span class="k">@include</span> <span class="nd">panel</span><span class="p">();</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="mh">#ebebeb</span><span class="p">;</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Secondly, CSS is called Cascading Stylesheets for a reason. Depending upon the context, it’s probably better to not even bother with SASS features. Sometimes SASS makes you forget about some of the reusability features that plain old HTML and CSS have in the first place. Just add a class for scope and style it globally. I know, I know, global is bad from what you’ve heard, but often it makes sense. Here is what that might look like.</p>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"page sass"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"panel css-library"</span><span class="nt">&gt;</span>
    <span class="nt">&lt;h2&gt;</span>Sass<span class="nt">&lt;/h2&gt;</span>
    <span class="nt">&lt;p&gt;</span>CSS with superpowers<span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"page stylus"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"panel css-library"</span><span class="nt">&gt;</span>
    <span class="nt">&lt;h2&gt;</span>Stylus<span class="nt">&lt;/h2&gt;</span>
    <span class="nt">&lt;p&gt;</span>Expressive, dynamic, robust CSS<span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"page less"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"panel css-library"</span><span class="nt">&gt;</span>
    <span class="nt">&lt;h2&gt;</span>Less<span class="nt">&lt;/h2&gt;</span>
    <span class="nt">&lt;p&gt;</span>Leaner CSS<span class="nt">&lt;/p&gt;</span>
  <span class="nt">&lt;/div&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>
<div class="language-css highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.page</span> <span class="nc">.panel.css-library</span> <span class="p">{</span>
  <span class="nl">padding</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">margin</span><span class="p">:</span> <span class="m">1em</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">300px</span><span class="p">;</span>
<span class="p">}</span>

<span class="nc">.page.sass</span> <span class="p">{</span>
  <span class="err">.panel</span> <span class="err">{</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="m">#e1faea</span><span class="p">;</span>
  <span class="p">}</span>
<span class="err">}</span>

<span class="nc">.page.stylus</span> <span class="p">{</span>
  <span class="err">.panel</span> <span class="err">{</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="m">#def0fc</span><span class="p">;</span>
  <span class="p">}</span>
<span class="err">}</span>

<span class="nc">.page.less</span> <span class="p">{</span>
  <span class="err">.panel</span> <span class="err">{</span>
    <span class="nl">background-color</span><span class="p">:</span> <span class="m">#ebebeb</span><span class="p">;</span>
  <span class="p">}</span>
<span class="err">}</span>
</code></pre></div></div>

<p>Don’t avoid <code class="language-plaintext highlighter-rouge">@extend</code> and placeholders out of principle, but do be very careful, particularly if <code class="language-plaintext highlighter-rouge">@extend</code> is used for some kind of common utility. It will not scale out to many, many pages. Know what you’re using, and know what CSS it’s generating.</p>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[SASS is a really powerful tool, which sometimes means that one has to be careful. It can generate all kinds of insane CSS that is hard for debugging and hard for the browser to parse and apply. Now and then, you have to take a step back and ask yourself if you really need to use SASS for the task at hand. I’d like to attempt to coin a new term for an anti-pattern that I, and many others, have stumbled upon. The Selector Bomb A gigantic selector that is hard to debug and hard for the browser to parse and apply, generated by SASS when using @extend as a utility that spans across many selectors. An Example There is a lot of jargon in the above statement. Let’s break it down with a clear example with three pages. Keep in mind that three pages is not really a problem, but when you scale this up to a huge amount of pages, it really becomes a problem. This especially applies to utility classes – something like a clearfix class or a text-align class. Each page has a panel with a different background color. This is a fairly common pattern, especially if you’re concatenating all of your CSS into a single file. You want to share the common styles and yet still change the background color. You decide to use a SASS placeholder and use @extend to bring in the common styles. Let’s have a look at the markup and SASS for each page. First Page &lt;div class="panel"&gt; &lt;h2&gt;Sass&lt;/h2&gt; &lt;p&gt;CSS with superpowers&lt;/p&gt; &lt;div&gt; .page.sass { .panel { @extend %panel; background-color: #e1faea; } } Second Page &lt;div class="page stylus"&gt; &lt;div class="panel css-library"&gt; &lt;h2&gt;Stylus&lt;/h2&gt; &lt;p&gt;Expressive, dynamic, robust CSS&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; .page.stylus { .panel { @extend %panel; background-color: #def0fc; } } Third Page &lt;div class="page less"&gt; &lt;div class="panel"&gt; &lt;h2&gt;Less&lt;/h2&gt; &lt;p&gt;Leaner CSS&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; .page.less { .panel { @extend %panel; background-color: #ebebeb; } } And finally, the common styles are in the placeholder, which is extended in each panel. %panel { padding: 1em; margin: 1em; width: 300px; } This will render these three components on each of the three different pages. Unfortunately that will compile to this. See how it merges all of the selectors into one for the common styles? This is the selector bomb. Every time you add a page that has @extend %panel , it will add one more selector here. Do that across enough pages and you can get a huge selector that is hard to debug and hard for the browser to parse and apply. .page.sass .panel, .page.stylus .panel, .page.less .panel { padding: 1em; margin: 1em; width: 300px; } .page.sass .panel { background-color: #e1faea; } .page.stylus .panel { background-color: #def0fc; } .page.less .panel { background-color: #ebebeb; } Solutions There are a couple ways to get around this. Depending upon the context of what you’re doing, one of these (or even something else) may make sense. First, a mixin will alleviate the pain, since a mixin will actually copy the CSS everywhere it is included. This could cause more pain, since it makes the file size a bit larger. However, worrying about the size of a CSS file is very likely to be overthinking the problem. @mixin panel() { padding: 1em; margin: 1em; width: 300px; } .page.sass { .panel { @include panel(); background-color: #e1faea; } } .page.stylus { .panel { @include panel(); background-color: #def0fc; } } .page.less { .panel { @include panel(); background-color: #ebebeb; } } Secondly, CSS is called Cascading Stylesheets for a reason. Depending upon the context, it’s probably better to not even bother with SASS features. Sometimes SASS makes you forget about some of the reusability features that plain old HTML and CSS have in the first place. Just add a class for scope and style it globally. I know, I know, global is bad from what you’ve heard, but often it makes sense. Here is what that might look like. &lt;div class="page sass"&gt; &lt;div class="panel css-library"&gt; &lt;h2&gt;Sass&lt;/h2&gt; &lt;p&gt;CSS with superpowers&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="page stylus"&gt; &lt;div class="panel css-library"&gt; &lt;h2&gt;Stylus&lt;/h2&gt; &lt;p&gt;Expressive, dynamic, robust CSS&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="page less"&gt; &lt;div class="panel css-library"&gt; &lt;h2&gt;Less&lt;/h2&gt; &lt;p&gt;Leaner CSS&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; .page .panel.css-library { padding: 1em; margin: 1em; width: 300px; } .page.sass { .panel { background-color: #e1faea; } } .page.stylus { .panel { background-color: #def0fc; } } .page.less { .panel { background-color: #ebebeb; } } Don’t avoid @extend and placeholders out of principle, but do be very careful, particularly if @extend is used for some kind of common utility. It will not scale out to many, many pages. Know what you’re using, and know what CSS it’s generating.]]></summary></entry><entry><title type="html">Quick Tip: Multiple Background Images in CSS</title><link href="https://barnesian.com/multiple-background-image-in-css/" rel="alternate" type="text/html" title="Quick Tip: Multiple Background Images in CSS" /><published>2015-12-19T00:00:00+00:00</published><updated>2015-12-19T00:00:00+00:00</updated><id>https://barnesian.com/multiple-background-image-in-css</id><content type="html" xml:base="https://barnesian.com/multiple-background-image-in-css/"><![CDATA[<p>Nearly every software developer who works with front-end code has probably used the CSS property <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-image">background-image</a>. What some might not know is that background-image can take many images and set how those images are positioned. This could be particularly useful if you don’t have full control over the HTML that is being generated for whatever reason. You could also have multiple elements and use an <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/%3Anth-of-type">nth-of-type</a> selector to achieve the same effect. Here is a quick demo of how you can use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-image">background-image</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-size">background-size</a>, and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-position">background-position</a> in concert to apply three images to a single div on top of a span of text.</p>

<p>HTML:</p>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"box"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"icon"</span><span class="nt">&gt;&lt;/div&gt;</span>
  <span class="nt">&lt;span&gt;</span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  <span class="nt">&lt;/span&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>

<p>CSS:</p>
<div class="language-css highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nc">.box</span> <span class="p">{</span>
  <span class="nl">margin</span><span class="p">:</span> <span class="m">20px</span><span class="p">;</span>
  <span class="nl">border</span><span class="p">:</span> <span class="m">1px</span> <span class="nb">solid</span> <span class="no">black</span><span class="p">;</span>
  <span class="nl">padding</span><span class="p">:</span> <span class="m">20px</span><span class="p">;</span>
  <span class="nl">background-color</span><span class="p">:</span> <span class="m">#eee</span><span class="p">;</span>
  <span class="nl">min-width</span><span class="p">:</span> <span class="m">430px</span><span class="p">;</span>  <span class="c">/* Set a min-width, so the images don't spill outside of the container */</span>
<span class="p">}</span>

<span class="nc">.icon</span> <span class="p">{</span>
  <span class="nl">height</span><span class="p">:</span> <span class="m">100px</span><span class="p">;</span>
  <span class="nl">width</span><span class="p">:</span> <span class="m">450px</span><span class="p">;</span>        <span class="c">/* Set a fixed width, so the images don't float off to the left and right */</span>
  <span class="nl">margin</span><span class="p">:</span> <span class="m">0</span> <span class="nb">auto</span><span class="p">;</span>      <span class="c">/* Center the images */</span>
  <span class="nl">margin-bottom</span><span class="p">:</span> <span class="m">20px</span><span class="p">;</span> <span class="c">/* Push the text away by 20px */</span>
  <span class="nl">background-image</span><span class="p">:</span>
    <span class="sx">url('https://www.barnesian.com/wp-content/uploads/2015/12/ruby.png')</span><span class="p">,</span>
    <span class="sx">url('https://www.barnesian.com/wp-content/uploads/2015/12/php.png')</span><span class="p">,</span>
    <span class="sx">url('https://www.barnesian.com/wp-content/uploads/2015/12/go.png')</span><span class="p">;</span>
  <span class="nl">background-repeat</span><span class="p">:</span> <span class="nb">no-repeat</span><span class="p">,</span> <span class="nb">no-repeat</span><span class="p">,</span> <span class="nb">no-repeat</span><span class="p">;</span>
  <span class="nl">background-size</span><span class="p">:</span>
    <span class="m">100px</span><span class="p">,</span>       <span class="c">/* height and width of 100px */</span>
    <span class="nb">auto</span> <span class="m">100px</span><span class="p">,</span>  <span class="c">/* height auto and width of 100px */</span>
    <span class="m">100px</span><span class="p">;</span>       <span class="c">/* height and width of 100px */</span>
  <span class="nl">background-position</span><span class="p">:</span> <span class="nb">left</span><span class="p">,</span> <span class="nb">center</span><span class="p">,</span> <span class="nb">right</span><span class="p">;</span>  <span class="c">/* You can also set an offset here if you need to */</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Those will produce the following result:</p>

<p><img src="/assets/posts//multiple-background-image-in-css/multiple-background-images.png" alt="" /></p>

<p>Here’s a quick demo on JSFiddle:</p>
<iframe src="//jsfiddle.net/4h5wL5gd/embedded/result,html,css,js/" allowfullscreen="allowfullscreen" width="100%" height="300" frameborder="0"></iframe>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[Nearly every software developer who works with front-end code has probably used the CSS property background-image. What some might not know is that background-image can take many images and set how those images are positioned. This could be particularly useful if you don’t have full control over the HTML that is being generated for whatever reason. You could also have multiple elements and use an nth-of-type selector to achieve the same effect. Here is a quick demo of how you can use the background-image, background-size, and background-position in concert to apply three images to a single div on top of a span of text. HTML: &lt;div class="box"&gt; &lt;div class="icon"&gt;&lt;/div&gt; &lt;span&gt; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. &lt;/span&gt; &lt;/div&gt; CSS: .box { margin: 20px; border: 1px solid black; padding: 20px; background-color: #eee; min-width: 430px; /* Set a min-width, so the images don't spill outside of the container */ } .icon { height: 100px; width: 450px; /* Set a fixed width, so the images don't float off to the left and right */ margin: 0 auto; /* Center the images */ margin-bottom: 20px; /* Push the text away by 20px */ background-image: url('https://www.barnesian.com/wp-content/uploads/2015/12/ruby.png'), url('https://www.barnesian.com/wp-content/uploads/2015/12/php.png'), url('https://www.barnesian.com/wp-content/uploads/2015/12/go.png'); background-repeat: no-repeat, no-repeat, no-repeat; background-size: 100px, /* height and width of 100px */ auto 100px, /* height auto and width of 100px */ 100px; /* height and width of 100px */ background-position: left, center, right; /* You can also set an offset here if you need to */ } Those will produce the following result: Here’s a quick demo on JSFiddle:]]></summary></entry><entry><title type="html">Quick Tip: Parsing a Config String in Ruby</title><link href="https://barnesian.com/quick-tip-parsing-a-config-string-in-ruby/" rel="alternate" type="text/html" title="Quick Tip: Parsing a Config String in Ruby" /><published>2015-03-19T00:00:00+00:00</published><updated>2015-03-19T00:00:00+00:00</updated><id>https://barnesian.com/quick-tip-parsing-a-config-string-in-ruby</id><content type="html" xml:base="https://barnesian.com/quick-tip-parsing-a-config-string-in-ruby/"><![CDATA[<p><img src="/assets/posts//quick-tip-parsing-a-config-string-in-ruby/irb_config.png" alt="" /></p>

<p>Recently I came across the need to parse a bit of a config file, in this kind of format: “Category=filetype;…” Here is how one would do such a thing using <a href="http://ruby-doc.org/core-2.2.1/String.html#method-i-split">split</a>, <a href="http://ruby-doc.org/core-2.2.1/Enumerable.html#method-i-inject" title="Docs for enumerable inject">inject</a> and <a href="http://ruby-doc.org/core-2.2.1/Enumerable.html#method-i-map" title="Docs for enumerable map">map</a>.</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">raw_config</span> <span class="o">=</span> <span class="s2">"Image=jpg,tiff,png;Document=docx,doc,pdf;Other=rb,cs,c;"</span>

<span class="n">config</span> <span class="o">=</span> <span class="n">raw_config</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">inject</span><span class="p">({})</span> <span class="k">do</span> <span class="o">|</span><span class="n">result</span><span class="p">,</span> <span class="n">fragment</span><span class="o">|</span>
  <span class="n">type</span><span class="p">,</span> <span class="n">extensions</span> <span class="o">=</span> <span class="n">fragment</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="s2">"="</span><span class="p">)</span>
  <span class="n">result</span><span class="p">[</span><span class="n">type</span><span class="p">.</span><span class="nf">strip</span><span class="p">.</span><span class="nf">downcase</span><span class="p">.</span><span class="nf">to_sym</span><span class="p">]</span> <span class="o">=</span> <span class="n">extensions</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">map</span><span class="p">{</span> <span class="o">|</span><span class="n">s</span><span class="o">|</span> <span class="n">s</span><span class="p">.</span><span class="nf">strip</span> <span class="p">}</span>
  <span class="n">result</span>
<span class="k">end</span>
</code></pre></div></div>

<p>The result is a <a href="http://ruby-doc.org/core-2.2.1/Hash.html" title="Docs for Ruby Hash">hash</a> where you can get an array of the file extensions for a given category like this
<code class="language-plaintext highlighter-rouge">config[:image]</code>
and the resulting hash looks like this:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span>
  <span class="ss">:image</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s2">"jpg"</span><span class="p">,</span> <span class="s2">"tiff"</span><span class="p">,</span> <span class="s2">"png"</span><span class="p">],</span>
  <span class="ss">:document</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s2">"docx"</span><span class="p">,</span> <span class="s2">"doc"</span><span class="p">,</span> <span class="s2">"pdf"</span><span class="p">],</span>
  <span class="ss">:other</span> <span class="o">=&gt;</span> <span class="p">[</span><span class="s2">"rb"</span><span class="p">,</span> <span class="s2">"cs"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">]</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Let me know in the comments if you have a better way!</p>]]></content><author><name></name></author><category term="Software Development" /><summary type="html"><![CDATA[Recently I came across the need to parse a bit of a config file, in this kind of format: “Category=filetype;…” Here is how one would do such a thing using split, inject and map. raw_config = "Image=jpg,tiff,png;Document=docx,doc,pdf;Other=rb,cs,c;" config = raw_config.split(";").inject({}) do |result, fragment| type, extensions = fragment.split("=") result[type.strip.downcase.to_sym] = extensions.split(",").map{ |s| s.strip } result end The result is a hash where you can get an array of the file extensions for a given category like this config[:image] and the resulting hash looks like this: { :image =&gt; ["jpg", "tiff", "png"], :document =&gt; ["docx", "doc", "pdf"], :other =&gt; ["rb", "cs", "c"] } Let me know in the comments if you have a better way!]]></summary></entry></feed>