<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.7.0">Jekyll</generator><link href="http://maedi.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://maedi.com/" rel="alternate" type="text/html" /><updated>2019-09-10T13:45:35+00:00</updated><id>http://maedi.com/</id><title type="html">Maedi Prichard</title><entry><title type="html">Unity Cheatsheet</title><link href="http://maedi.com/code/unity-cheatsheet/" rel="alternate" type="text/html" title="Unity Cheatsheet" /><published>2019-06-07T00:00:00+00:00</published><updated>2019-09-10T00:00:00+00:00</updated><id>http://maedi.com/code/unity-cheatsheet</id><content type="html" xml:base="http://maedi.com/code/unity-cheatsheet/">&lt;p&gt;&lt;a href=&quot;https://unity.com/&quot;&gt;Unity&lt;/a&gt; lets you make games of any kind for any platform. It’s revolutionary but its flexibility can lead to a system which is hard to understand. Here’s what I learnt making &lt;a href=&quot;https://cluejar.com/delivery-duck-mobile&quot;&gt;my game&lt;/a&gt; as a handy reference.&lt;/p&gt;

&lt;h2 id=&quot;cheatsheet&quot;&gt;Cheatsheet&lt;/h2&gt;

&lt;p&gt;Which building blocks do I use and when?&lt;/p&gt;

&lt;!-- Create arrays of headings/rows from line seperated sentences. --&gt;

&lt;!-- Determine how many rows there will be. --&gt;

&lt;table&gt;
  &lt;thead&gt;
    
      &lt;th&gt;&lt;br /&gt;&lt;/th&gt;
    
      &lt;th&gt;
  GameObject&lt;/th&gt;
    
      &lt;th&gt;
  ScriptableObject&lt;/th&gt;
    
      &lt;th&gt;
  MonoBehaviour&lt;/th&gt;
    
      &lt;th&gt;
  No inheritance&lt;/th&gt;
    
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;!-- Output rows. --&gt;
    
      &lt;tr&gt;
        
          &lt;td&gt;&lt;strong&gt;What&lt;/strong&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;The entities that interact with each other.
&lt;/td&gt;
        
        
          &lt;td&gt;Data models editable via Unity UI.
&lt;/td&gt;
        
        
          &lt;td&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject&lt;/code&gt; actions and data flow.
&lt;/td&gt;
        
        
          &lt;td&gt;Basic C# class.
&lt;/td&gt;
        
      &lt;/tr&gt;
    
      &lt;tr&gt;
        
          &lt;td&gt;
&lt;strong&gt;When&lt;/strong&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
If it can be seen in the game world.
&lt;/td&gt;
        
        
          &lt;td&gt;
To define the settings of &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject&lt;/code&gt;s and general configuration.
&lt;/td&gt;
        
        
          &lt;td&gt;
To control &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject&lt;/code&gt;s, generate and handle events.
&lt;/td&gt;
        
        
          &lt;td&gt;
When behaviour not directly related to a &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject&lt;/code&gt;.
&lt;/td&gt;
        
      &lt;/tr&gt;
    
      &lt;tr&gt;
        
          &lt;td&gt;
&lt;strong&gt;Where&lt;/strong&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
Lives in the &lt;a href=&quot;https://docs.unity3d.com/Manual/Hierarchy.html&quot;&gt;Hierarchy&lt;/a&gt;.
&lt;/td&gt;
        
        
          &lt;td&gt;
Lives in the &lt;a href=&quot;https://docs.unity3d.com/Manual/ProjectView.html&quot;&gt;ProjectView&lt;/a&gt;. Initialized by Unity.
&lt;/td&gt;
        
        
          &lt;td&gt;
Attached to &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject&lt;/code&gt;s as a &lt;a href=&quot;https://docs.unity3d.com/Manual/Components.html&quot;&gt;Component&lt;/a&gt;, or lives in the &lt;a href=&quot;https://docs.unity3d.com/Manual/Hierarchy.html&quot;&gt;Hierarchy&lt;/a&gt;.
&lt;/td&gt;
        
        
          &lt;td&gt;
Lives in the &lt;a href=&quot;https://docs.unity3d.com/Manual/ProjectView.html&quot;&gt;ProjectView&lt;/a&gt;. Called programatically by other scripts.
&lt;/td&gt;
        
      &lt;/tr&gt;
    
      &lt;tr&gt;
        
          &lt;td&gt;
&lt;strong&gt;Example&lt;/strong&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;Scene.unity&lt;/code&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;Config : ScriptableObject&lt;/code&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;PlayerController : MonoBehaviour&lt;/code&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;code class=&quot;highlighter-rouge&quot;&gt;SaveController&lt;/code&gt;
&lt;/td&gt;
        
      &lt;/tr&gt;
    
      &lt;tr&gt;
        
          &lt;td&gt;
&lt;strong&gt;Use Cases&lt;/strong&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;ul&gt; &lt;li&gt;Player&lt;/li&gt; &lt;li&gt;Camera&lt;/li&gt; &lt;li&gt;Scene&lt;/li&gt; &lt;/ul&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;ul&gt; &lt;li&gt;Player&lt;/li&gt; &lt;li&gt;Config&lt;/li&gt; &lt;/ul&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;ul&gt; &lt;li&gt;Player&lt;/li&gt; &lt;li&gt;Camera&lt;/li&gt; &lt;li&gt;Scene&lt;/li&gt; &lt;/ul&gt;
&lt;/td&gt;
        
        
          &lt;td&gt;
&lt;ul&gt; &lt;li&gt;Saves&lt;/li&gt; &lt;li&gt;User Input&lt;/li&gt; &lt;li&gt;Utilities&lt;/li&gt; &lt;/ul&gt;
&lt;/td&gt;
        
      &lt;/tr&gt;
    
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;accessors&quot;&gt;Accessors&lt;/h2&gt;

&lt;p&gt;In Unity most things are &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject&lt;/code&gt;s which scripts are attached to. In your scripts you can access most things with these 3 snippets:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Get the instance of the script/class we’re in with &lt;code class=&quot;highlighter-rouge&quot;&gt;this&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Get the GameObject the script is attached to with &lt;code class=&quot;highlighter-rouge&quot;&gt;this.gameObject&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Get the GameObject’s components with &lt;code class=&quot;highlighter-rouge&quot;&gt;GetComponent&amp;lt;ComponentName&amp;gt;()&lt;/code&gt;.&lt;br /&gt;
The longer version &lt;code class=&quot;highlighter-rouge&quot;&gt;this.gameObject.GetComponent&amp;lt;ComponentName&amp;gt;()&lt;/code&gt; will also work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re searching for GameObjects in the Scene Hierarchy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Find a GameObject by name: &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject.Find(&quot;name&quot;)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Find a GameObject of a certain type: &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject.FindObjectsOfType(typeof(MyType));&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Find a GameObject with a certain tag: &lt;code class=&quot;highlighter-rouge&quot;&gt;GameObject.FindGameObjectsWithTag(&quot;MyTag&quot;);&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;debugging&quot;&gt;Debugging&lt;/h2&gt;

&lt;p&gt;Using breakpoints via Visual Studio is the best way to debug complex data flows, but sometimes you just want good old fashioned debugging.&lt;/p&gt;

&lt;h3 id=&quot;list-components-and-all-their-variables&quot;&gt;List components and all their variables&lt;/h3&gt;

&lt;p&gt;Put &lt;code class=&quot;highlighter-rouge&quot;&gt;using System.Reflection;&lt;/code&gt; at top of file then paste:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;Component&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;components&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Component&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;GetComponents&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Component&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Component&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;components&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;Debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Name: &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; Type: &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; BaseType: &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FieldInfo&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;Debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Name: &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; Value: &quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;shortcuts&quot;&gt;Shortcuts&lt;/h2&gt;

&lt;p&gt;You will need to keep running the main scene and navigating to it in Unity then running it is tedious. Create a keyboard shortcut instead with:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;UnityEditor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;EditorSceneManager&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UnityEditor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SceneManagement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EditorSceneManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PlayMainMenu&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Add keyboard shortcut.&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;MenuItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Edit/Play Main Menu _m&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;PlayFromPrelaunchScene&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EditorApplication&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isPlaying&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;EditorApplication&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isPlaying&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;EditorSceneManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;SaveCurrentModifiedScenesIfUserWantsTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;EditorSceneManager&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;OpenScene&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Assets/Scenes/&amp;lt;scene-name&amp;gt;.unity&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;EditorApplication&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isPlaying&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Replace &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;scene-name&amp;gt;&lt;/code&gt; with the name of your scene. Now &lt;code class=&quot;highlighter-rouge&quot;&gt;M&lt;/code&gt; key on your keyboard will run the main scene from anywhere.&lt;/p&gt;</content><author><name></name></author><category term="code" /><category term="Unity" /><summary type="html">Unity lets you make games of any kind for any platform. It’s revolutionary but its flexibility can lead to a system which is hard to understand. Here’s what I learnt making my game as a handy reference.</summary></entry><entry><title type="html">Send email from your custom domain for free (Gmail, Mailgun, Cloudflare)</title><link href="http://maedi.com/code/email-custom-domain-free/" rel="alternate" type="text/html" title="Send email from your custom domain for free (Gmail, Mailgun, Cloudflare)" /><published>2018-12-17T00:00:00+00:00</published><updated>2018-12-17T00:00:00+00:00</updated><id>http://maedi.com/code/email-custom-domain-free</id><content type="html" xml:base="http://maedi.com/code/email-custom-domain-free/">&lt;p&gt;A recipe for setting up your email address at your custom domain for free. Using Gmail, Cloudflare, Mailgun and optionally Mailchimp.&lt;/p&gt;

&lt;h2 id=&quot;mailgun&quot;&gt;Mailgun&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://signup.mailgun.com/new/signup&quot;&gt;Create an account&lt;/a&gt; then verify it. You need to add a credit card to get all of the features, but it’s still free for the first 10,000 emails a month.&lt;/p&gt;

&lt;h3 id=&quot;add-domain&quot;&gt;Add domain&lt;/h3&gt;

&lt;p&gt;Go to &lt;a href=&quot;https://app.mailgun.com/app/domains&quot;&gt;Domains&lt;/a&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Click “Add Domain” button&lt;/li&gt;
  &lt;li&gt;Under “Domain Name” enter your domain (ex: &lt;code class=&quot;highlighter-rouge&quot;&gt;example.com&lt;/code&gt;)
Ignore the message “We highly recommend using a subdomain”. You should not include a subdomain if you want to &lt;em&gt;receive&lt;/em&gt; email too.&lt;/li&gt;
  &lt;li&gt;Submit the form&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;forward-email-to-gmail&quot;&gt;Forward email to Gmail&lt;/h3&gt;

&lt;p&gt;Go to &lt;a href=&quot;https://app.mailgun.com/app/routes&quot;&gt;Routes&lt;/a&gt;:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Click “Create Route” button&lt;/li&gt;
  &lt;li&gt;Set “Expression Type” to “Match Recipient”&lt;/li&gt;
  &lt;li&gt;Set “Recipient” to your email address (ex: &lt;code class=&quot;highlighter-rouge&quot;&gt;info@example.com&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Under “Actions” check “Forward” and add your Gmail address (ex: &lt;code class=&quot;highlighter-rouge&quot;&gt;example@gmail.com&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Submit the form&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;cloudflare&quot;&gt;Cloudflare&lt;/h2&gt;

&lt;h3 id=&quot;get-config-from-mailgun&quot;&gt;Get config from Mailgun&lt;/h3&gt;

&lt;p&gt;In Mailgun go to your domain (ex: &lt;code class=&quot;highlighter-rouge&quot;&gt;https://app.mailgun.com/app/domains/example.com&lt;/code&gt;). Keep this page open as you will be copying and pasting values from here to Cloudflare.&lt;/p&gt;

&lt;h3 id=&quot;configure-dns&quot;&gt;Configure DNS&lt;/h3&gt;

&lt;p&gt;In Cloudflare go to the DNS section.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Add the 2 TXT records using their supplied values. (ex: &lt;code class=&quot;highlighter-rouge&quot;&gt;v=spf1 include:mailgun.org ~all&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;k=rsa&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Add a CNAME record with “email” as the “Name” and &lt;code class=&quot;highlighter-rouge&quot;&gt;mailgun.org&lt;/code&gt; as the “Value”.&lt;/li&gt;
  &lt;li&gt;Uncheck the cloud icon for the CNAME.&lt;/li&gt;
  &lt;li&gt;Add an MX record with your domain as the “Name” and “mxa.mailgun.org” as the “Value” and a “Priority” of “10”.&lt;/li&gt;
  &lt;li&gt;Add an MX record with your domain as the “Name” and “mxb.mailgun.org” as the “Value” and a “Priority” of “10”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Mailgun click the “Check DNS Records Now” button to confirm settings are correct.&lt;/p&gt;

&lt;h2 id=&quot;gmail&quot;&gt;Gmail&lt;/h2&gt;

&lt;p&gt;Go to Gmail:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Click the “Cog” icon and go to Settings&lt;/li&gt;
  &lt;li&gt;Click the “Accounts and Import” tab.&lt;/li&gt;
  &lt;li&gt;Under “Send mail as” click “Add another email address”:
    &lt;ul&gt;
      &lt;li&gt;Set “Name” to your personal or company name&lt;/li&gt;
      &lt;li&gt;Set “Email address” to your email address (ex: &lt;code class=&quot;highlighter-rouge&quot;&gt;info@example.com&lt;/code&gt;)&lt;/li&gt;
      &lt;li&gt;Ensure “Treat as an alias” is checked&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Click “Next Step” button&lt;/li&gt;
  &lt;li&gt;Fill in the form with settings from you domains “Domain Information” at Mailgun.
    &lt;ul&gt;
      &lt;li&gt;Gmail’s “SMTP Server” equals Mailgun’s “SMTP Hostname”&lt;/li&gt;
      &lt;li&gt;Gmail’s “Username” equals Mailgun’s “Default SMTP Login”&lt;/li&gt;
      &lt;li&gt;Gmail’s “Password” equals Mailgun’s “Default Password”&lt;/li&gt;
      &lt;li&gt;Ensure “Secured connection using TLS” is checked&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Click “Add Account” button&lt;/li&gt;
  &lt;li&gt;You should receive a message like:
“Congratulations, we successfully located your other server and verified your credentials.”&lt;/li&gt;
  &lt;li&gt;Verify your new email address in Gmail&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;mailchimp-optional&quot;&gt;Mailchimp (optional)&lt;/h2&gt;

&lt;p&gt;In Mailchimp add your domain at Account -&amp;gt; Domains:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Click “Verify A Domain”&lt;/li&gt;
  &lt;li&gt;Under “Email Address” enter you email address&lt;/li&gt;
  &lt;li&gt;Go to Gmail and click the verification link&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Cloudflare add &lt;a href=&quot;https://mailchimp.com/help/set-up-custom-domain-authentication-dkim-and-spf/&quot;&gt;these&lt;/a&gt; records:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Add a CNAME record with &lt;code class=&quot;highlighter-rouge&quot;&gt;k1._domainkey.example.com&lt;/code&gt; for “Name” and &lt;code class=&quot;highlighter-rouge&quot;&gt;dkim.mcsv.net&lt;/code&gt; for “Value”.&lt;/li&gt;
  &lt;li&gt;Add a TXT record with &lt;code class=&quot;highlighter-rouge&quot;&gt;example.com&lt;/code&gt; for “Name” and &lt;code class=&quot;highlighter-rouge&quot;&gt;v=spf1 include:servers.mcsv.net ?all&lt;/code&gt; for “Value”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In Mailchimp at Account -&amp;gt; Domains:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Click “Authenticate” button to the right of your domain.&lt;/li&gt;
&lt;/ol&gt;</content><author><name></name></author><category term="code" /><category term="Email" /><summary type="html">A recipe for setting up your email address at your custom domain for free. Using Gmail, Cloudflare, Mailgun and optionally Mailchimp.</summary></entry><entry><title type="html">Host Your Git And Deploy It Too!</title><link href="http://maedi.com/code/host-git-deploy/" rel="alternate" type="text/html" title="Host Your Git And Deploy It Too!" /><published>2018-09-04T00:00:00+00:00</published><updated>2019-06-10T00:00:00+00:00</updated><id>http://maedi.com/code/host-git-deploy</id><content type="html" xml:base="http://maedi.com/code/host-git-deploy/">&lt;p&gt;After the rise of cloud hosting with their multiple environments and slick UIs it’s easy to forget why we started using them in the first place… Git. &lt;strong&gt;What if I told you can put Git on any old server?&lt;/strong&gt; That you can still host sites yourself and deploy code to production with a simple &lt;code class=&quot;highlighter-rouge&quot;&gt;git push&lt;/code&gt;? Yes, you can have (host) your cake (git) and eat (deploy) it too.&lt;/p&gt;

&lt;h2 id=&quot;1-create-the-user&quot;&gt;1. Create the user&lt;/h2&gt;

&lt;p&gt;A requirement of this method is that the Git user and the Unix user who owns the web accessible directory are the same account. With this structure in place we can work our magic.&lt;/p&gt;

&lt;p&gt;We will connect to this user when we push changes up from our local. Create this user like you would any other user on a Unix machine:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo adduser &amp;lt;username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Add the &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;ssh&lt;/code&gt; groups to this user:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;usermod -a -G ssh &amp;lt;username&amp;gt;;
usermod -a -G sudo &amp;lt;username&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;2-give-remote-user-your-public-key&quot;&gt;2. Give remote user your public key&lt;/h2&gt;

&lt;p&gt;SSH to the remote server as the &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;username&amp;gt;&lt;/code&gt; user. In their home directory:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir ~/.ssh &amp;amp;&amp;amp; chmod 700 ~/.ssh;
touch ~/.ssh/authorized_keys &amp;amp;&amp;amp; chmod 600 ~/.ssh/authorized_keys;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On your local machine copy the contents of your public key which is usually found at:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;~/.ssh/id_rsa.pub
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Back on the server paste your public key into authorized_keys:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nano ~/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3-create-a-bare-git-repo&quot;&gt;3. Create a bare Git repo&lt;/h2&gt;

&lt;p&gt;A bare git repo just means that only the “.git” folder exists in the repo’s folder, not the tracked files. The bare git repo becomes the central “host” for the files. This host will then export the tracked files to our web accessible destination directory.&lt;/p&gt;

&lt;p&gt;Create a bare repo in your remote user’s home directory:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir .git;
cd .git;
git init --bare;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Though you’ve created this repo in &lt;code class=&quot;highlighter-rouge&quot;&gt;~/&lt;/code&gt; it will not try to track the contents of your home directory.&lt;/p&gt;

&lt;h2 id=&quot;4-push-to-the-bare-repo&quot;&gt;4. Push to the bare repo&lt;/h2&gt;

&lt;p&gt;Add the bare repo “host” as the remote on your local repo:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git remote add origin &amp;lt;username&amp;gt;@&amp;lt;server&amp;gt;:/home/&amp;lt;username&amp;gt;/.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the example above &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;server&amp;gt;&lt;/code&gt; is either the server’s IP address or a domain that points to it.&lt;/p&gt;

&lt;h2 id=&quot;5-on-push-export-to-destination-directory&quot;&gt;5. On push export to destination directory&lt;/h2&gt;

&lt;p&gt;On the remote server add a &lt;code class=&quot;highlighter-rouge&quot;&gt;post-receive&lt;/code&gt; hook:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nano ~/.git/hooks/post-receive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Paste:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;read &lt;/span&gt;old new ref
&lt;span class=&quot;k&quot;&gt;do
  if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$ref&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;~ .&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;/master&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;then
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Deploying master...&quot;&lt;/span&gt;
    git &lt;span class=&quot;nt&quot;&gt;--work-tree&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/home/&amp;lt;username&amp;gt; &lt;span class=&quot;nt&quot;&gt;--git-dir&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$PWD&lt;/span&gt; checkout &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;else
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$ref&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; received but not deployed.&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;fi
done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This script will export Git’s working tree (the tracked files) to &lt;code class=&quot;highlighter-rouge&quot;&gt;/home/&amp;lt;username&amp;gt;&lt;/code&gt;. Replace &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;username&amp;gt;&lt;/code&gt; with your destination directory. In my case my repo contains a &lt;code class=&quot;highlighter-rouge&quot;&gt;docroot&lt;/code&gt; folder which will be web accessible via Apache, so I have no issue exporting the tracked files directly into my user’s home directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; As mentioned at the start of the tutorial, the destination directory has to be owned by the Git user in order for Git to have permission to create files and folders. This is why we’re exporting within the user’s home directory.&lt;/p&gt;

&lt;p&gt;Save file with &lt;code class=&quot;highlighter-rouge&quot;&gt;Control/Command + O&lt;/code&gt; and exit nano with &lt;code class=&quot;highlighter-rouge&quot;&gt;Control/Command + X&lt;/code&gt; then make the script executable:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;chmod +x ~/.git/hooks/post-receive
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Save the file and we’re almost done!&lt;/p&gt;

&lt;h2 id=&quot;making-a-deployment&quot;&gt;Making a deployment&lt;/h2&gt;

&lt;p&gt;To test things out simply add a dummy commit to your local repo, then &lt;code class=&quot;highlighter-rouge&quot;&gt;git push&lt;/code&gt;. Now when the base repo receives the push it exports the latest tracked files to the &lt;code class=&quot;highlighter-rouge&quot;&gt;/home/&amp;lt;username&amp;gt;&lt;/code&gt; destination directory. Visit your website’s URL to see the changes!&lt;/p&gt;

&lt;h2 id=&quot;file-system-permissions&quot;&gt;File System permissions&lt;/h2&gt;

&lt;p&gt;We’re only human and you’ve likely uploaded files and folders already that are owned by the wrong users and groups. The &lt;code class=&quot;highlighter-rouge&quot;&gt;post-receive&lt;/code&gt; hook will only be able to modify files and folders under the control of &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;username&amp;gt;&lt;/code&gt;. So if you &lt;code class=&quot;highlighter-rouge&quot;&gt;git push&lt;/code&gt; and something’s not updating then chances are that file/folder is owned by another user.&lt;/p&gt;

&lt;p&gt;Find incorrectly owned directories with:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ls -al
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then change the owner and groups of folders and their children with:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;chown -R &amp;lt;user&amp;gt;:&amp;lt;group&amp;gt; &amp;lt;directory-path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;done&quot;&gt;Done!&lt;/h2&gt;

&lt;p&gt;This is my method. If you have any improvements please let me know.&lt;/p&gt;</content><author><name></name></author><category term="code" /><category term="Git" /><category term="Unix" /><summary type="html">After the rise of cloud hosting with their multiple environments and slick UIs it’s easy to forget why we started using them in the first place… Git. What if I told you can put Git on any old server? That you can still host sites yourself and deploy code to production with a simple git push? Yes, you can have (host) your cake (git) and eat (deploy) it too.</summary></entry><entry><title type="html">Jekyll: Dynamically Filter By Date</title><link href="http://maedi.com/code/filter-by-date/" rel="alternate" type="text/html" title="Jekyll: Dynamically Filter By Date" /><published>2018-04-09T00:00:00+00:00</published><updated>2018-04-09T00:00:00+00:00</updated><id>http://maedi.com/code/filter-by-date</id><content type="html" xml:base="http://maedi.com/code/filter-by-date/">&lt;p&gt;Jekyll produces static HTML… but what if we want to filter content by the current date? Say we have a list of events and want to hide past events. The following 2 options have you covered.&lt;/p&gt;

&lt;h2 id=&quot;static-liquid-filter&quot;&gt;Static liquid filter&lt;/h2&gt;

&lt;p&gt;Use this in your template to filter &lt;code class=&quot;highlighter-rouge&quot;&gt;posts&lt;/code&gt; by current date:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;&lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;capture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}{{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'now'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'%s'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;}&lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;endcapture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;post&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;in&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;site.posts&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;capture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'%s'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;}&lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;endcapture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;now&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
    &amp;lt;!-- post content here --&amp;gt;
  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;endif&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;endfor&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This code captures the current time (at build time) into the &lt;code class=&quot;highlighter-rouge&quot;&gt;now&lt;/code&gt; variable and only shows the post if its &lt;code class=&quot;highlighter-rouge&quot;&gt;date&lt;/code&gt; is larger than &lt;code class=&quot;highlighter-rouge&quot;&gt;now&lt;/code&gt; (in the future). The &lt;code class=&quot;highlighter-rouge&quot;&gt;date: '%s'&lt;/code&gt; filter captures the post’s date as a timestamp and &lt;code class=&quot;highlighter-rouge&quot;&gt;plus: 0&lt;/code&gt; ensures that any string values are cast to integers. (Method from &lt;a href=&quot;http://stackoverflow.com/a/23025858&quot;&gt;Stack Overflow&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Of course this filtering still only happens whenever Jekyll is built…&lt;/p&gt;

&lt;h2 id=&quot;dynamic-javascript-filter&quot;&gt;Dynamic javascript filter&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;/code/date-filter&quot;&gt;jQuery Date Filter&lt;/a&gt; is a little javascript library which filters out items by date on the client-side. So if your static site hasn’t been rebuilt in a while and is showing stale content, &lt;a href=&quot;/code/date-filter&quot;&gt;this library will hide it&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><category term="code" /><category term="jekyll" /><category term="date" /><summary type="html">Jekyll produces static HTML… but what if we want to filter content by the current date? Say we have a list of events and want to hide past events. The following 2 options have you covered.</summary></entry><entry><title type="html">CSS Tricks</title><link href="http://maedi.com/code/css-tricks/" rel="alternate" type="text/html" title="CSS Tricks" /><published>2017-11-28T00:00:00+00:00</published><updated>2018-01-18T00:00:00+00:00</updated><id>http://maedi.com/code/css-tricks</id><content type="html" xml:base="http://maedi.com/code/css-tricks/">&lt;h2 id=&quot;flex&quot;&gt;Flex&lt;/h2&gt;

&lt;h3 id=&quot;flex-css-columns-with-margin&quot;&gt;Flex CSS columns with margin&lt;/h3&gt;

&lt;p&gt;Use this mixin when you want 3 columns + margin with flex!&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-scss&quot; data-lang=&quot;scss&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// Flex columns using all the tricks.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;@mixin&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;three-columns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;$gutter-column&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;10px&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Remove gutter.&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$gutter-column&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nl&quot;&gt;justify-content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;center&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;li&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// Add gutter.&lt;/span&gt;
      &lt;span class=&quot;nl&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$gutter-column&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// 3 columns including gutter.&lt;/span&gt;
      &lt;span class=&quot;nl&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;calc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;33&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;.3333333333333%&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$gutter-column&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;preload-images-via-css&quot;&gt;Preload images via CSS&lt;/h3&gt;

&lt;p&gt;Browsers doesn’t preload images that show on hover, leading to an awful flicker as the new image loads. Preload the image via CSS to avoid this flicker:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-scss&quot; data-lang=&quot;scss&quot;&gt;&lt;span class=&quot;nt&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;:after&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nl&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;url('&amp;lt;path&amp;gt;.jpg')&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;links&quot;&gt;Links&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/25066214/flexbox-not-giving-equal-width-to-elements&quot;&gt;Equal width elements&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/philipwalton/flexbugs&quot;&gt;IE Flex bugs and their workarounds&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><category term="code" /><category term="Tricks" /><category term="CSS" /><summary type="html">Flex</summary></entry><entry><title type="html">Jekyll: Check if string is a number</title><link href="http://maedi.com/code/jekyll-check-if-string-number/" rel="alternate" type="text/html" title="Jekyll: Check if string is a number" /><published>2017-10-01T00:00:00+00:00</published><updated>2017-10-01T00:00:00+00:00</updated><id>http://maedi.com/code/jekyll-check-if-string-number</id><content type="html" xml:base="http://maedi.com/code/jekyll-check-if-string-number/">&lt;p&gt;How do you check if a string in Jekyll is actually a number? For example you might want to do one thing when a value is &lt;code class=&quot;highlighter-rouge&quot;&gt;'123'&lt;/code&gt; and another when the value is &lt;code class=&quot;highlighter-rouge&quot;&gt;'ABC'&lt;/code&gt;. Jekyll doesn’t seem to provide a simple way to do this out of the box. Crazy that such a simple feature doesn’t exist!&lt;/p&gt;

&lt;p&gt;I’ve come up with a method. The logic is to treat the string as if it were a number and see how it reacts. A string of letters cannot be added to, but a string of numbers can. &lt;code class=&quot;highlighter-rouge&quot;&gt;plus&lt;/code&gt;ing a string that’s not a number will return &lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt;, while &lt;code class=&quot;highlighter-rouge&quot;&gt;plus&lt;/code&gt;ing a string that’s a number will return the original number.&lt;/p&gt;

&lt;h2 id=&quot;method&quot;&gt;Method&lt;/h2&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  
    &amp;lt;!-- Get the value. --&amp;gt;
    &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'123'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
    &amp;lt;!-- Add the value. --&amp;gt;
    &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;addition&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;plus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
    &amp;lt;!-- Convert addition to string for comparison. --&amp;gt;
    &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;capture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;addition&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;addition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;endcapture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;

    &amp;lt;!-- Value is a number if addition has no effect. --&amp;gt;
    &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;addition&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
      &amp;lt;!-- Value is number. --&amp;gt;
    &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;endif&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;
  &lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Let me know if there’s a better way to do this!&lt;/p&gt;

&lt;p&gt;This method seems pretty robust. Only integers and floats without other characters in the string are considered numbers. The value &lt;code class=&quot;highlighter-rouge&quot;&gt;'0'&lt;/code&gt; is correctly identified as a number.&lt;/p&gt;</content><author><name></name></author><category term="code" /><category term="jekyll" /><summary type="html">How do you check if a string in Jekyll is actually a number? For example you might want to do one thing when a value is '123' and another when the value is 'ABC'. Jekyll doesn’t seem to provide a simple way to do this out of the box. Crazy that such a simple feature doesn’t exist!</summary></entry><entry><title type="html">Semantic blockquotes in HTML5</title><link href="http://maedi.com/code/semantic-blockquote-html5/" rel="alternate" type="text/html" title="Semantic blockquotes in HTML5" /><published>2017-09-22T00:00:00+00:00</published><updated>2019-06-07T00:00:00+00:00</updated><id>http://maedi.com/code/semantic-blockquote-html5</id><content type="html" xml:base="http://maedi.com/code/semantic-blockquote-html5/">&lt;p&gt;If you’re like me you’ve been doing blockquotes like this for years:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;blockquote&amp;gt;&lt;/span&gt;
  The quote...
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;cite&amp;gt;&lt;/span&gt;The author...&lt;span class=&quot;nt&quot;&gt;&amp;lt;/cite&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/blockquote&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Well it turns out &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;cite&amp;gt;&lt;/code&gt; isn’t what we thought it was. It doesn’t mean the &lt;em&gt;source&lt;/em&gt; of the quote, it means the &lt;em&gt;name&lt;/em&gt; of the source material that the quote is from (book, article, song). So it’s not the author or the company, it’s the publication. This just isn’t the right tag to use.&lt;/p&gt;

&lt;p&gt;There’s also another problem; the &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;cite&amp;gt;&lt;/code&gt; is inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; tag, indicating that the author attribution is part of the quote itself. This is sad semantics :(&lt;/p&gt;

&lt;h2 id=&quot;theres-got-to-be-a-better-way&quot;&gt;There’s got to be a better way?&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://html5doctor.com/blockquote-q-cite/&quot;&gt;Apparently&lt;/a&gt; the &lt;a href=&quot;https://web.archive.org/web/20140330092659/https://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-February/034822.html&quot;&gt;correct way&lt;/a&gt; to quote is like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;figure&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;blockquote&amp;gt;&lt;/span&gt;
    The quote...
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/blockquote&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;figcaption&amp;gt;&lt;/span&gt;The author...&lt;span class=&quot;nt&quot;&gt;&amp;lt;/figcaption&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/figure&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The quote is still a &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt; but this time there’s no &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;cite&amp;gt;&lt;/code&gt; inside. The author sits beneath as a &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;figcaption&amp;gt;&lt;/code&gt;, with both elements inside a &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;figure&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;This method basically borrows the logic behind how &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags are attributed. For images the structure is:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;figure&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;image.jpg&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;figcaption&amp;gt;&lt;/span&gt;Fig 1: Description&lt;span class=&quot;nt&quot;&gt;&amp;lt;/figcaption&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/figure&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Basically the same thing.&lt;/p&gt;

&lt;p&gt;Though there’s no true consensus, the &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;figcaption&amp;gt;&lt;/code&gt; method makes sense. It re-uses a structure that’s been around for a while that already means exactly what we’re trying to express; a thing that is attributed to another thing.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/twbs/bootstrap/issues/11660&quot;&gt;Some&lt;/a&gt; people like to replace &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;figcaption&amp;gt;&lt;/code&gt; with &lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;lt;footer&amp;gt;&lt;/code&gt;, which semantically means a similar thing. All in all I think this structure is a great improvement on something that’s always been bugging me about quotes in HTML.&lt;/p&gt;</content><author><name></name></author><category term="code" /><category term="html5" /><category term="blockquote" /><summary type="html">If you’re like me you’ve been doing blockquotes like this for years:</summary></entry><entry><title type="html">Jekyll Tricks</title><link href="http://maedi.com/code/jekyll-tricks/" rel="alternate" type="text/html" title="Jekyll Tricks" /><published>2017-09-17T00:00:00+00:00</published><updated>2018-06-08T00:00:00+00:00</updated><id>http://maedi.com/code/jekyll-tricks</id><content type="html" xml:base="http://maedi.com/code/jekyll-tricks/">&lt;h2 id=&quot;how-to-create-an-empty-array&quot;&gt;How to create an empty array&lt;/h2&gt;

&lt;p&gt;In your &lt;code class=&quot;highlighter-rouge&quot;&gt;_config.yml&lt;/code&gt; initialize an empty array into a YAML property:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;emptyArray: []
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then access that property in your Liquid template:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;my_array&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;site&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;emptyArray&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You can push values into the array like so:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;my_array&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;my_array&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;push&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'value'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;get-any-item-by-its-id&quot;&gt;Get any item by its ID&lt;/h2&gt;

&lt;p&gt;The ID of any posts or collection item in Jekyll will be its filename. This is what you see in the URL as the item’s path (not including the parent path). For example a file called &lt;code class=&quot;highlighter-rouge&quot;&gt;about-us.md&lt;/code&gt; with have the ID of &lt;code class=&quot;highlighter-rouge&quot;&gt;about-us&lt;/code&gt;. With this ID in hand you can now embed any post/collection item anywhere by filtering for it:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;site&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;posts&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;id&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'about-us'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;string-concatenation&quot;&gt;String concatenation&lt;/h2&gt;

&lt;p&gt;Append method:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;new_var&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;var_first&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;' - '&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;var_second&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Capture method:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  &lt;span class=&quot;p&quot;&gt;{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;capture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;new_var&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}{{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;var_first&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt; - &lt;span class=&quot;p&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;var_second&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}{%&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;endcapture&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;%}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;date-formatting&quot;&gt;Date formatting&lt;/h2&gt;

&lt;p&gt;Format a date by appending a date filter to your variable like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-liquid&quot; data-lang=&quot;liquid&quot;&gt;  &lt;span class=&quot;p&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'%Y %B %d'&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.shopify.com/themes/liquid/filters/additional-filters#date&quot;&gt;Here are the docs&lt;/a&gt; and &lt;a href=&quot;http://www.strfti.me/&quot;&gt;here’s&lt;/a&gt; a handy reference on %placholders.&lt;/p&gt;</content><author><name></name></author><category term="code" /><category term="Tricks" /><category term="Jekyll" /><category term="Jekyll Collections" /><summary type="html">Various rare Jekyll snippets...</summary></entry><entry><title type="html">SQL Tricks</title><link href="http://maedi.com/code/sql-tricks/" rel="alternate" type="text/html" title="SQL Tricks" /><published>2017-09-13T00:00:00+00:00</published><updated>2017-09-13T00:00:00+00:00</updated><id>http://maedi.com/code/sql-tricks</id><content type="html" xml:base="http://maedi.com/code/sql-tricks/">&lt;h2 id=&quot;import-a-database-via-command-line&quot;&gt;Import a database via command line&lt;/h2&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mysql -uroot -proot [existing-database] &amp;lt; ~/dev/[new-database].sql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;specifically-ask-for-mamp-pro-mysql&quot;&gt;Specifically ask for MAMP PRO mysql&lt;/h3&gt;
&lt;p&gt;MAMP/MAMP Pro is an application that runs a MySQL, Apache and PHP stack on Mac.&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;get-size-of-all-databases&quot;&gt;Get size of all databases&lt;/h2&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT table_schema AS &quot;Database name&quot;, SUM(data_length + index_length) / 1024 / 1024 AS &quot;Size (MB)&quot; FROM information_schema.TABLES GROUP BY table_schema;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;get-size-of-all-tables-in-a-database&quot;&gt;Get size of all tables in a database&lt;/h2&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT
  table_schema as `Database`,
  table_name AS `Table`,
  round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="code" /><category term="Tricks" /><category term="SQL" /><category term="MySQL" /><summary type="html">MySQL and database related trickery...</summary></entry><entry><title type="html">UNIX Tricks</title><link href="http://maedi.com/code/unix-tricks/" rel="alternate" type="text/html" title="UNIX Tricks" /><published>2017-09-12T00:00:00+00:00</published><updated>2017-03-17T00:00:00+00:00</updated><id>http://maedi.com/code/unix-tricks</id><content type="html" xml:base="http://maedi.com/code/unix-tricks/">&lt;h2 id=&quot;file-system&quot;&gt;File System&lt;/h2&gt;

&lt;p&gt;List directory tree:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tree -df .
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;List directory tree with full paths:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;find . -type d
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;List the actual size of each directory/file within a directory:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;du -sh */ | sort -n
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;List all files bigger than 100MB for the entire disk:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;du --all --one-file-system / | awk '{if($1 &amp;gt; 102400) print int($1/1024) &quot;MB&quot; &quot; &quot; $2 }'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;encoding&quot;&gt;Encoding&lt;/h2&gt;

&lt;h3 id=&quot;convert-the-charset-of-a-file-to-utf-8&quot;&gt;Convert the charset of a file to UTF-8&lt;/h3&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iconv -f [old-charset] -t utf-8 [old-filepath] &amp;gt; [new-filepath]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;find-non-ascii-characters-in-a-text-file&quot;&gt;Find non-ASCII characters in a text file&lt;/h3&gt;

&lt;p&gt;Linux:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;grep --color='auto' -P -n &quot;[\x80-\xFF]&quot; file.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Mac OS X:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;brew install pcre
pcregrep --color='auto' -n &quot;[\x80-\xFF]&quot; file.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You may need to increase your buffer with &lt;code class=&quot;highlighter-rouge&quot;&gt;--buffer-size=999999999&lt;/code&gt;.
&lt;cite&gt;– &lt;a href=&quot;https://github.com/jekyll/jekyll/issues/4268#issuecomment-165617139&quot;&gt;Source&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;h2 id=&quot;backups&quot;&gt;Backups&lt;/h2&gt;

&lt;p&gt;Download a copy of a directory to a local directory:&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rsync --dry-run --archive -vv --stats --progress &amp;lt;source&amp;gt; ~/dev/&amp;lt;destination&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name></name></author><category term="code" /><category term="Tricks" /><category term="UNIX" /><category term="Mac" /><summary type="html">UNIX trickery...</summary></entry></feed>