<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
<title>Klaudjan&#39;s Webpage</title>
<link>https://klaudjanpepaj.com/</link>
<description>Recent content in Klaudjan&#39;s Website on Klaudjan&#39;s Webpage</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<lastBuildDate>Mon, 17 Apr 2023 22:40:44 +0200</lastBuildDate>
    
        <atom:link href="https://klaudjanpepaj.com/index.xml" rel="self" type="application/rss+xml" />


<item>
<title>Awk the Unchained</title>
<link>https://klaudjanpepaj.com/posts/awk_the_unchained/</link>
<pubDate>Fri, 28 Mar 2025 20:29:18 +0000</pubDate>

<guid>https://klaudjanpepaj.com/posts/awk_the_unchained/</guid>
<description>&lt;p&gt;&lt;em&gt;awk&lt;/em&gt; is a powerful text-processing language great for working with files (like
CSV and logs), processing data streams (like the output of commands), and
handling tasks like transforming data in a variety of ways.&lt;/p&gt;
&lt;p&gt;I see &lt;em&gt;awk&lt;/em&gt; as a tool that makes the difference and brings you to the next level
by setting you free from the standard way of elaborating stream of data and
files.&lt;/p&gt;

&lt;h2 id=&#34;syntax&#34;&gt;Syntax
  &lt;a class=&#34;header-link&#34; href=&#34;#syntax&#34;
    aria-label=&#34;Link to this section: Syntax&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;pattern { action }&amp;#39;&lt;/span&gt; &amp;lt;path_to_file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;pattern&lt;/strong&gt;: This specifies when the action should be executed. It can be a
regular expression, a condition (like matching a specific value), or simply true
(to apply the action to every line). If no pattern is provided, the action is
applied to every line of input.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;action&lt;/strong&gt;: This defines what &lt;em&gt;awk&lt;/em&gt; should do when the pattern matches. The action
is enclosed in curly braces &lt;code&gt;{}&lt;/code&gt;. If no action is provided, &lt;em&gt;awk&lt;/em&gt; will simply print
the matched lines.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;lt;path_to_file&amp;gt;&lt;/strong&gt;: This is the path to the file to be processed. If the path is
not provided, &lt;em&gt;awk&lt;/em&gt; will process input from the standard input.&lt;/p&gt;

&lt;h2 id=&#34;basic-use&#34;&gt;Basic use
  &lt;a class=&#34;header-link&#34; href=&#34;#basic-use&#34;
    aria-label=&#34;Link to this section: Basic use&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;

&lt;h3 id=&#34;print-specific-columns&#34;&gt;Print specific columns
  &lt;a class=&#34;header-link&#34; href=&#34;#print-specific-columns&#34;
    aria-label=&#34;Link to this section: Print specific columns&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;To print ids of the running containers we can print only the first column of the
&lt;code&gt;docker ps&lt;/code&gt; command.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;docker ps | awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;{print $1}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;$1&lt;/strong&gt; represents the first column in each line of the &lt;code&gt;docker ps&lt;/code&gt; output. In this
case, it&amp;rsquo;s the container ID.&lt;/p&gt;

&lt;h3 id=&#34;using-a-pattern-to-match-lines&#34;&gt;Using a pattern to match lines
  &lt;a class=&#34;header-link&#34; href=&#34;#using-a-pattern-to-match-lines&#34;
    aria-label=&#34;Link to this section: Using a pattern to match lines&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If I want to get the ID of the Postgres container&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;docker ps | awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39; /postgres/ {print $1}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;perform-an-action-on-a-line&#34;&gt;Perform an action on a line
  &lt;a class=&#34;header-link&#34; href=&#34;#perform-an-action-on-a-line&#34;
    aria-label=&#34;Link to this section: Perform an action on a line&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If I want to get the total amount of space occupied by the files in the current
directory&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;ls -l | awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;{ sum += $5 } END {print sum}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;END&lt;/strong&gt;: is a block that will be executed after all the lines have been
processed.&lt;/p&gt;
&lt;p&gt;There is also the &lt;strong&gt;BEGIN&lt;/strong&gt; block that is executed before any line is processed.&lt;/p&gt;
&lt;p&gt;this is an example of the usage&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;BEGIN { print &amp;#34;Start processing&amp;#34; }
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;     { print $1 }
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;     END { print &amp;#34;Finished processing&amp;#34; }&amp;#39;&lt;/span&gt; &amp;lt;path_to_file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&#34;advanced-use&#34;&gt;Advanced use
  &lt;a class=&#34;header-link&#34; href=&#34;#advanced-use&#34;
    aria-label=&#34;Link to this section: Advanced use&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;

&lt;h3 id=&#34;filter-out-rows-from-a-csv-file&#34;&gt;Filter out rows from a CSV file
  &lt;a class=&#34;header-link&#34; href=&#34;#filter-out-rows-from-a-csv-file&#34;
    aria-label=&#34;Link to this section: Filter out rows from a CSV file&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Given a CSV file like this&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-csv&#34; data-lang=&#34;csv&#34;&gt;id,product_id,business_id
1,23,45
9,45,89
39,356,45
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We want to get the header and all the lines of a specific business_id&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;awk -F&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;NR==1 || $3==45 { print $0 }&amp;#39;&lt;/span&gt; &amp;lt;path_to_file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;-F&lt;/strong&gt;: is used to specify the column separator. By default, it is a space but
with our CSV we are using a comma &amp;lsquo;,&amp;rsquo;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NR&lt;/strong&gt;: holds the number of the line in which &lt;em&gt;awk&lt;/em&gt; is operating at the moment&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;||&lt;/strong&gt;: it is the boolean or&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;remove-duplicated-lines-without-changing-the-order-of-the-lines&#34;&gt;Remove duplicated lines without changing the order of the lines
  &lt;a class=&#34;header-link&#34; href=&#34;#remove-duplicated-lines-without-changing-the-order-of-the-lines&#34;
    aria-label=&#34;Link to this section: Remove duplicated lines without changing the order of the lines&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;With awk, it is possible to remove all duplicate lines, regardless of their
position in the file, unlike the &lt;code&gt;uniq&lt;/code&gt; command, which only removes adjacent
duplicate lines.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;!seen[$0]++&amp;#39;&lt;/span&gt; &amp;lt;path_to_file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;By using &lt;code&gt;seen[$0]&lt;/code&gt;, we track whether each line has appeared before. If a line
has already been seen, it’s skipped; otherwise, it’s printed.&lt;/p&gt;
&lt;p&gt;We are not limited to use only &lt;code&gt;$0&lt;/code&gt;, with&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;awk &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;!seen[$1$2]++&amp;#39;&lt;/span&gt; &amp;lt;path_to_file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;$1$2&lt;/code&gt; concatenates the values of the first and second fields. This will ensure
that duplicates are only removed based on the combination of the first two
fields, while ignoring the rest of the line.&lt;/p&gt;
&lt;p&gt;Explanation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;seen[]&lt;/strong&gt; is an associative array (similar to a map or dictionary) that &lt;em&gt;awk&lt;/em&gt;
initializes the first time we access it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;seen[$0]&lt;/strong&gt; accesses the value stored in the map by the key $0&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;!&lt;/strong&gt; negates the returned values of the map:
&lt;ul&gt;
&lt;li&gt;In &lt;em&gt;awk&lt;/em&gt;, any nonzero numeric value or any nonempty string value is true.&lt;/li&gt;
&lt;li&gt;By default, variables are initialized to the empty string, which is zero if converted to a number.&lt;/li&gt;
&lt;li&gt;That being said:
&lt;ul&gt;
&lt;li&gt;If &lt;em&gt;seen[$0] = 0 or empty string&lt;/em&gt; then the negation is resolved to true.&lt;/li&gt;
&lt;li&gt;If &lt;em&gt;seen[$0] &amp;gt; 0&lt;/em&gt; then the negation is resolved to false.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;++&lt;/strong&gt; is a post-increment operator. This means that the value of &lt;em&gt;seen[$0]&lt;/em&gt; is
accessed first to evaluate the expression, and only
then is it incremented.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Summing up, the whole expression evaluates to:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;true&lt;/strong&gt; if the occurrences are zero/empty string&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;false&lt;/strong&gt; if the occurrences are greater than zero&lt;/p&gt;
&lt;p&gt;If the pattern succeeds, then the associated action is executed. If we don&amp;rsquo;t
provide an action, &lt;em&gt;awk&lt;/em&gt;, by default, prints the line.&lt;/p&gt;
</description>
</item>

<item>
<title>Knots: the first step to becoming the next MacGyver</title>
<link>https://klaudjanpepaj.com/posts/knots/</link>
<pubDate>Tue, 01 Oct 2024 22:41:05 +0000</pubDate>

<guid>https://klaudjanpepaj.com/posts/knots/</guid>
<description>&lt;p&gt;It all started in the woods, in a survival training meant to forge new Rambos;
it ended in the city with a cheaper version of MacGyver.&lt;/p&gt;
&lt;p&gt;Actually, the survival training didn&amp;rsquo;t explain how useful knots might be in
day-to-day life, but it was enough to spark an interest in me.&lt;/p&gt;
&lt;p&gt;So I took 
&lt;a href=&#34;https://www.amazon.com/Morrow-Guide-Knots-Sailing-Climbing/dp/0688012264&#34; 
  target=&#34;_blank&#34; &gt;The Morrow Guide to
Knots
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;

(MGTK), an illustrated book that shows how to tie the most common knots and
explains why they are used. Even though the book was good, it didn&amp;rsquo;t fuel my
interest. I was just learning the knots as a hobby.&lt;/p&gt;
&lt;p&gt;Then I started thinking outside my box, which didn’t have ropes at the time, and
understood that ropes and knots can be very helpful in everyday life.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://klaudjanpepaj.com/images/mindblow.gif&#34;alt=&#34;mindblow&#34; title=&#34;my mind exploding&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Whenever I had a problem, I started to think about whether a rope could help me.
For example:&lt;/p&gt;
&lt;p&gt;I used it to lock my cat’s leash to my jeans, created a handle for a garage box,
attached shirts and bottles to my backpack, made a leash for my dog&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; and
fixed my car bumper in the middle of the road. For this reason, I have a rope
tied to my backpack in a 
&lt;a href=&#34;https://www.youtube.com/watch?v=KN3d8vvHgWE&#34; 
  target=&#34;_blank&#34; &gt;quick-release
manner
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
, just in case I need it.&lt;/p&gt;
&lt;p&gt;I’ve discovered that a simple knot can solve many problems; sometimes the most
unexpected skills can become invaluable tools in our everyday lives,
transforming challenges into manageable tasks.&lt;/p&gt;
&lt;hr&gt;

&lt;h2 id=&#34;types-and-uses&#34;&gt;Types and uses
  &lt;a class=&#34;header-link&#34; href=&#34;#types-and-uses&#34;
    aria-label=&#34;Link to this section: Types and uses&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There are a lot of knots out there, that can be categorized in many types. The
following are the categories I utilize:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;#stopper-knots&#34; 
 &gt;Stopper
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#hitch-knots&#34; 
 &gt;Hitch
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#noose-knots&#34; 
 &gt;Noose
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#loop-knots&#34; 
 &gt;Loop
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#bend-knots&#34; 
 &gt;Bend
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#lashings-knots&#34; 
 &gt;Lashing
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#decorative-knots&#34; 
 &gt;Decorative
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;#shoelace-knots&#34; 
 &gt;Shoelace
&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I will list all the knots that I use and for each paragraph I will highlight
the most significant knot with &lt;code&gt;(*)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Many of these notes appear in 
&lt;a href=&#34;https://www.amazon.it/Ashley-Book-Knots-Clifford-W/dp/057109659X/ref=sr_1_1?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;amp;s=books&amp;amp;sr=1-1&#34; 
  target=&#34;_blank&#34; &gt;The Ashley Book of Knots
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
 (ABOK),
the bible of the knots, and will have a reference to the pages of the book.&lt;/p&gt;

&lt;h3 id=&#34;stopper-knots&#34;&gt;Stopper Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#stopper-knots&#34;
    aria-label=&#34;Link to this section: Stopper Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Stoppers are used primarily to make other knots more secure: are made in the end
of a rope to prevent its slipping through an aperture when the rope is being
used.&lt;/p&gt;
&lt;p&gt;For example, it is added to the 
&lt;a href=&#34;#bowline-knot-&#34; 
 &gt;Bowline
&lt;/a&gt;
, which can shake loose, to
eliminate the risk of undoing.&lt;/p&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;double-overhand-&#34;&gt;Double Overhand (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#double-overhand-&#34;
    aria-label=&#34;Link to this section: Double Overhand (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 516, p 84]&lt;/p&gt;
&lt;p&gt;The Double Overhand Knot is based on the Overhand Knot with one additional
turn. It creates a larger knot that is far less likely to shake loose and
looks cooler. It is also really easy to tie. Beyond two tuns, the knot must be
worked into shape, and for that reason, it may be considered more decorative
than practical.&lt;/p&gt;
&lt;p&gt;The Overhand knot, in its variations (Double and Triple), provide the basis
for other useful knots as the 
&lt;a href=&#34;#fishermans-bend&#34; 
 &gt;Fisherman&amp;rsquo;s Bend
&lt;/a&gt;
, 
&lt;a href=&#34;#scaffold-knot-&#34; 
 &gt;Scaffold
Knot
&lt;/a&gt;
, and Strangle knot.&lt;/p&gt;
&lt;p&gt;I used this knot in my dog leash&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; as a stopper for the Scaffold knot. I had a
fair excess of rope, enough to make the double overhand knot. It is more
beautiful and secure than the simple overhand knot.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;ashley-stopper-knot&#34;&gt;Ashley Stopper Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#ashley-stopper-knot&#34;
    aria-label=&#34;Link to this section: Ashley Stopper Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 526, p 86]&lt;/p&gt;
&lt;p&gt;This is a less-known knot that is &lt;strong&gt;bulkier&lt;/strong&gt; and less prone to shake than the
other Stopper knots. It may be better in some circumstances when you need a
bulkier knot; but remember that It is easy to do it right, and unfortunately,
it is also easy to get it wrong.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;heaving-line-knot&#34;&gt;Heaving Line Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#heaving-line-knot&#34;
    aria-label=&#34;Link to this section: Heaving Line Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 538, p 88]&lt;/p&gt;
&lt;p&gt;The Heaving Line knots are very strong and don&amp;rsquo;t wear the fibers of the rope,
and add weight to the end of a rope making it heavier.&lt;/p&gt;
&lt;p&gt;There are different types of Heaving Line Knots, I prefer the Franciscan or
Monk&amp;rsquo;s Knot [MGTK p 36] because it is very easy and quick to tie and hard to
untie.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I tie it at each end of my dog&amp;rsquo;s toy rope, to make them bulkier and strong,
becoming easy to hold for both of us when we are playing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;They are also used to make the end of the rope heavier before throwing it,
making the throw more precise.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;hitch-knots&#34;&gt;Hitch Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#hitch-knots&#34;
    aria-label=&#34;Link to this section: Hitch Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Hitches are used for tying a rope directly to or around an object, and many of
them capsize if removed from the supporting object.&lt;/p&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;half-hitch-&#34;&gt;Half Hitch (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#half-hitch-&#34;
    aria-label=&#34;Link to this section: Half Hitch (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 50, p 14]&lt;br&gt;
[MGTK p 58]&lt;/p&gt;
&lt;p&gt;Half Hitches are temporary knots not intended to support a lot of strain. They
are often used to complete and make other knots stronger and more secure, like
with the 
&lt;a href=&#34;#anchor-hitch&#34; 
 &gt;Anchor Hitch
&lt;/a&gt;
 and the 
&lt;a href=&#34;#taut-line-hitch-&#34; 
 &gt;Taut Line
Hitch
&lt;/a&gt;
, and the more Half Hitches you concatenate the more
secure a knot becomes&lt;/p&gt;
&lt;p&gt;The Half Hitch is similar to the Clove Hitch because they have the same knot
form, but the difference is that the first is tied around its own standing
end, and the second is tied around another object.&lt;/p&gt;
&lt;p&gt;As I said it is mainly used to make other knots more secure, but I also use it
to attach &lt;strong&gt;little things&lt;/strong&gt; to my backpack, like my Hat, because It is very
easy and quick to tie and untie.&lt;/p&gt;

&lt;h4 id=&#34;anchor-hitch&#34;&gt;Anchor Hitch
  &lt;a class=&#34;header-link&#34; href=&#34;#anchor-hitch&#34;
    aria-label=&#34;Link to this section: Anchor Hitch&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 1841, p 309]
[MGTK p 60]&lt;/p&gt;
&lt;p&gt;Also known as Fisherman&amp;rsquo;s Bend Hitch, this is &lt;strong&gt;one of the strongest and most
secure hitches&lt;/strong&gt;. Used to anchor the extremity of a rope to something.&lt;/p&gt;

&lt;h4 id=&#34;bull-hitch&#34;&gt;Bull hitch
  &lt;a class=&#34;header-link&#34; href=&#34;#bull-hitch&#34;
    aria-label=&#34;Link to this section: Bull hitch&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;It is a better version of the more famous Cow Hitch, it is more stable
and less prone to slipping. This hitch is very easy to tie and is typically
tied around a &lt;em&gt;ring&lt;/em&gt;. I use it to tie a lanyard to my keychain or Swiss army
knife.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;noose-knots&#34;&gt;Noose Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#noose-knots&#34;
    aria-label=&#34;Link to this section: Noose Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Also known as Running Knots, this type of knot is tied in hand, and, when placed
around an object, renders and constricts when the standing part is pulled. It is
not a hitch because a hitch is tied directly to an object, and it doesn&amp;rsquo;t always
constrict when the rope is pulled.&lt;br&gt;
Any 
&lt;a href=&#34;#loop-knots&#34; 
 &gt;Loop Knots
&lt;/a&gt;
 becomes a Noose if the running end passes through
the loop.&lt;/p&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;scaffold-knot-&#34;&gt;Scaffold Knot (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#scaffold-knot-&#34;
    aria-label=&#34;Link to this section: Scaffold Knot (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 1120, p 204]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;This knot is one of my favorites.&lt;br&gt;
It is easy to tie, strong, and secure.&lt;/p&gt;
&lt;p&gt;I used it in my dog&amp;rsquo;s leash&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; and also in some circumstances when I want to
tie a rope around an object that cannot be easily reached, like when I needed
to tie a rope around a screw to fix my car.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;canadian-jam-knot&#34;&gt;Canadian Jam Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#canadian-jam-knot&#34;
    aria-label=&#34;Link to this section: Canadian Jam Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 2069, p 336]&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;This noose is simple and quick to tie; however, it can loosen easily. To
maintain its form, I secure it with two 
&lt;a href=&#34;#half-hithces-&#34; 
 &gt;Half Hitches
&lt;/a&gt;
 or a

&lt;a href=&#34;#taut-line-hithc-&#34; 
 &gt;Taut Line Hitch
&lt;/a&gt;
 tied to the same rope.&lt;/p&gt;
&lt;p&gt;I like this knot because it is really &lt;strong&gt;easy to tighten&lt;/strong&gt; the rope around the
object without needing too much force.&lt;/p&gt;
&lt;p&gt;I use this method to bundle my sets of blankets and to secure one corner of the
comforter cover: this allows me to hold the comforter in place while I insert
the remaining portion inside.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;loop-knots&#34;&gt;Loop Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#loop-knots&#34;
    aria-label=&#34;Link to this section: Loop Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;These knots serve the same purpose as a hitch, but they are tied in hand,
which is the main distinction between the two. Its shape, a loop, is not
dependent on the object that it is fast to, and it may be removed at any time
and will still retain its shape.&lt;br&gt;
A Loop Knot can become a Noose if the standing part is passed through the loop.&lt;/p&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;bowline-knot-&#34;&gt;Bowline Knot (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#bowline-knot-&#34;
    aria-label=&#34;Link to this section: Bowline Knot (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 1010, p 186]&lt;br&gt;
[MGTK p 70]&lt;/p&gt;
&lt;p&gt;If you have to remember only one knot, this is the one.&lt;/p&gt;
&lt;p&gt;The Bowline Loop Knot can hold heavy weights and it is  easy to tie and untie.
It is so easy that it can be tied with one hand, it is useful if you are
injured or cannot use the other hand for some reason.&lt;/p&gt;
&lt;p&gt;It is pretty secure, but it can very readily work its way untied when unloaded
and I would not put my life on it. So It is best to add a 
&lt;a href=&#34;#stopper-knots&#34; 
 &gt;Stopper
Knot
&lt;/a&gt;
 or a more secure Bowline variant like the &lt;strong&gt;Scott&amp;rsquo;s
Locked Bowline&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;double-dragon-loop&#34;&gt;Double Dragon Loop
  &lt;a class=&#34;header-link&#34; href=&#34;#double-dragon-loop&#34;
    aria-label=&#34;Link to this section: Double Dragon Loop&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;The Double Dragon Loop is a less known knot, and it is a shame because it is&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;more secure than the standard 
&lt;a href=&#34;#bowline-knot-&#34; 
 &gt;Bowline
&lt;/a&gt;
: doesn&amp;rsquo;t need a

&lt;a href=&#34;#stopper-knots&#34; 
 &gt;Stopper knot
&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;it doesn&amp;rsquo;t bind: it is easy to untie,&lt;/li&gt;
&lt;li&gt;it is highly adjustable: while you are tieing you can easily determine the loop size
that you want,&lt;/li&gt;
&lt;li&gt;it is an &lt;strong&gt;inline&lt;/strong&gt; knot: can be tied in the middle of the rope.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even though it has all these advantages, it is not present in the ABOK, but we can
find a similar one: the Angler&amp;rsquo;s Loop [ABOK # 1017 p186-187], which is tied
with only one loop around the knot, making it is less secure than the Double
Dragon Loop.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;bend-knots&#34;&gt;Bend Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#bend-knots&#34;
    aria-label=&#34;Link to this section: Bend Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Bends are used for joining two ropes at the ends to form a longer rope, or to
tie two ending parts of the same rope together closing the rope.
Bends should only be used as a temporary measure.&lt;/p&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;square-knot&#34;&gt;Square Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#square-knot&#34;
    aria-label=&#34;Link to this section: Square Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 1402, p 258]&lt;br&gt;
[MGTK p 128]&lt;/p&gt;
&lt;p&gt;Also known as Reef Knot.&lt;/p&gt;
&lt;p&gt;This bend knot is very easy to tie and untie, for this reason, it is widely
known. But it must not be used to secure things, it is slippery and it comes
undone. If tied with two ends of unequal size, or if one end is stiffer or more
slippery than the other, it is bound to spill.&lt;/p&gt;
&lt;p&gt;For this reason &lt;strong&gt;it cannot be trusted&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It should only be used for making temporary joints in identical ropes which will
not be subject to strain.&lt;/p&gt;
&lt;p&gt;Nevertheless, the Square Knot has many uses but not where safety is critical.&lt;/p&gt;
&lt;p&gt;For example, I use it when I tie my water bottle to my backpack: do a 
&lt;a href=&#34;#purcell-prusik-loop&#34; 
 &gt;Purcell
Prusik Loop
&lt;/a&gt;
 over the bottle and close the rope with a
Square knot over the handler of the backpack. I use the Square Knot and not the

&lt;a href=&#34;#fishermans-bend&#34; 
 &gt;Fisherman&amp;rsquo;s Bend
&lt;/a&gt;
, because I want to tie and untie it often.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Tip for tiening&lt;/strong&gt;: put always the same rope on top of the other and under the
other, this will make it easy to remember.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;sheet-bend-&#34;&gt;Sheet Bend (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#sheet-bend-&#34;
    aria-label=&#34;Link to this section: Sheet Bend (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 1431, p 262]&lt;br&gt;
[MGTK p 122]&lt;/p&gt;
&lt;p&gt;This Bend Knot can be used to bend two ropes of the same, or different,
diameters and types. It has the interesting property that the greater the strain
put on the ropes, the better the jamming action.&lt;/p&gt;
&lt;p&gt;It is quickly made and easily untied and by doubling the knot you make the
Double Sheet Bend that is more secure especially when you have two ropes that
are markedly different in size.&lt;/p&gt;
&lt;p&gt;The 
&lt;a href=&#34;https://youtu.be/3R0Lp86GEBk?si=RatPH-B8dAISzeOY&#34; 
  target=&#34;_blank&#34; &gt;Slippery version
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
 of it
can be used to tie pants easily.&lt;/p&gt;

&lt;h4 id=&#34;fishermans-bend&#34;&gt;Fisherman&amp;rsquo;s Bend
  &lt;a class=&#34;header-link&#34; href=&#34;#fishermans-bend&#34;
    aria-label=&#34;Link to this section: Fisherman&amp;amp;rsquo;s Bend&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 294, p 50]&lt;br&gt;
[MGTK p 140]&lt;/p&gt;
&lt;p&gt;This is one of my favorite knots. It is a very secure, easy to tie, and hard
to untie, for this reason it is used by climbers to bend the ropes.&lt;/p&gt;
&lt;p&gt;It is made with two or three 
&lt;a href=&#34;#double-overhand-&#34; 
 &gt;Overhand Knots
&lt;/a&gt;
 tied around
the other standing end, obtaining two knots that hold each other ropes and
when pulled they will crash with each other, welding the knots together.&lt;/p&gt;
&lt;p&gt;It is suggested to tie more than one overhand knot because it is not secure
enough. The more overhand knots are done, the more it is secure,  and make
sure to leave enough extra rope.&lt;/p&gt;
&lt;p&gt;I use this knot only when I don&amp;rsquo;t want to untie it, like in my dog leash&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
or for example, it is used with the 
&lt;a href=&#34;#prusik-knot&#34; 
 &gt;Prusik Knot
&lt;/a&gt;
.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;lashings-knots&#34;&gt;Lashings Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#lashings-knots&#34;
    aria-label=&#34;Link to this section: Lashings Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;A lashing may wrap and bind, or else bind only with a multiplicity of turns, a
parcel, box, chest or other container, either for transportation or for storage.
It may secure something movable to something that is fixed, with various turns
and hitches, so that it cannot shift from its position. Some of these knots act
like the zip ties.&lt;/p&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;truckers-hitch&#34;&gt;Trucker&amp;rsquo;s Hitch
  &lt;a class=&#34;header-link&#34; href=&#34;#truckers-hitch&#34;
    aria-label=&#34;Link to this section: Trucker&amp;amp;rsquo;s Hitch&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 2124, p 344]&lt;/p&gt;
&lt;p&gt;This knot is used primarily for securing loads or tensioning ropes for
tarpaulins, or any other cases when you need to tension the rope. It is widely
used for its simplicity and the fact that it &lt;strong&gt;provides a mechanical advantage
when tightening the rope&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;
&lt;a href=&#34;https://www.youtube.com/watch?v=1lLkoWJPmTs&#34; 
  target=&#34;_blank&#34; &gt;Here
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;

you can find a cool variant of it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;taut-line-hitch-&#34;&gt;Taut Line Hitch (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#taut-line-hitch-&#34;
    aria-label=&#34;Link to this section: Taut Line Hitch (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;The Taut Line Hitch knot creates an adjustable loop at the end of a rope, like
a zip tie, that can be slid by hand either to lengthen or to shorten the rope
but, left alone, &lt;strong&gt;it stays where it is&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;There are three different knots, very similar to each other, that are called
in this manner: Midshipman&amp;rsquo;s Hitch [ABOK # 1855, p 310], Rolling Hitch [ABOK #
1856, p 310], and the [ABOK # 1857, p 310]&lt;/p&gt;
&lt;p&gt;The Midshipman&amp;rsquo;s Hitch is the strongest, the other two are easier to adjust
and secure enough for most applications.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(What makes the Midshipman’s Hitch Knot the strongest and most secure is the
creation of the useful intermediate Awning Hitch; this takes the strain while
tying the final Half Hitch. Also, it is relatively easy to tie or untie under
load and, even after being heavily loaded, it is reasonably easy to release
For more information look at this

&lt;a href=&#34;https://www.youtube.com/watch?v=Ks2FskttO_4&amp;amp;list=PLoJVwcUSuyad-mR4-v80Yt3_-EXiTdg81&#34; 
  target=&#34;_blank&#34; &gt;video
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;These knots are extremely versatile and quick to make, I often use them to tie
the end rope to itself and tension it a little bit (if you want to tension
your rope, you better use the 
&lt;a href=&#34;#truckers-hitch&#34; 
 &gt;Trucker&amp;rsquo;s Hitch
&lt;/a&gt;
, which have a
stronger tension power), or, using the loop that is formed, to compress
object, like sleeping bag, or to hold objects together like a couple of books.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;prusik-knot&#34;&gt;Prusik Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#prusik-knot&#34;
    aria-label=&#34;Link to this section: Prusik Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;This knot is one of the best knots for friction hitch: &lt;strong&gt;it holds its place
even under load&lt;/strong&gt;, you have to manually pull it to move it. It is very secure.&lt;/p&gt;
&lt;p&gt;Because the Prusik Knot is a symmetrical slide and grip knot, it is useful if
a load might need to be applied in either direction&lt;/p&gt;
&lt;p&gt;It is widely used in climbing, and I used it in my dog leash&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;, in which it
is the main protagonist because enables the leash to fold in itself without
losing strength.&lt;/p&gt;
&lt;p&gt;This knot is also used to create the 
&lt;a href=&#34;#purcell-prusik-loop&#34; 
 &gt;Purcell Prusik
Loop
&lt;/a&gt;
, a zip tie knot, as you will see next.&lt;/p&gt;

&lt;h4 id=&#34;purcell-prusik-loop&#34;&gt;Purcell Prusik Loop
  &lt;a class=&#34;header-link&#34; href=&#34;#purcell-prusik-loop&#34;
    aria-label=&#34;Link to this section: Purcell Prusik Loop&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;This is a 
&lt;a href=&#34;#prusik-knot&#34; 
 &gt;Prusik knot
&lt;/a&gt;
 that is tied to the same rope, basically
to itself.&lt;/p&gt;
&lt;p&gt;To tie it you have to bend the two ends of the rope, for example with a

&lt;a href=&#34;#fishermans-bend&#34; 
 &gt;Fisherman&amp;rsquo;s Bend Knot
&lt;/a&gt;
, if you need a secure bend, or a

&lt;a href=&#34;#square-knot&#34; 
 &gt;Square Knot
&lt;/a&gt;
 if you want to untie it later on. After the bend,
you create the Prusik Knot and pass the rest of the rope inside it.&lt;/p&gt;
&lt;p&gt;This knot takes a lot of rope, the double of the end result, but I like it and
it feels more secure than other zip tie knots, for this reason it is my first
chooise if I need a zip tie knot that is secure. I use it to hold my water
bottle because my rope is too long to use the 
&lt;a href=&#34;#taut-line-hithc-&#34; 
 &gt;Taut Line
Hitch
&lt;/a&gt;
 which doesn&amp;rsquo;t need the bend.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;decorative-knots&#34;&gt;Decorative Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#decorative-knots&#34;
    aria-label=&#34;Link to this section: Decorative Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;diamond-knot-&#34;&gt;Diamond knot (*)
  &lt;a class=&#34;header-link&#34; href=&#34;#diamond-knot-&#34;
    aria-label=&#34;Link to this section: Diamond knot (*)&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;[ABOK # 787, p 141]&lt;br&gt;
[MGTK p 200]
Also known as Lanyard Knot&lt;/p&gt;
&lt;p&gt;This knot can be categorized as a stopper knot, loop knot, lanyard knot, and
decorative knot. But it is mainly used as a decorative, lanyard knot.&lt;/p&gt;
&lt;p&gt;It ties together two ends of the rope, usually of the same rope, and it looks
cool for this reason it is used for decorating any cord that is to be left in
view such as a knife or lanyard.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;monks-knot&#34;&gt;Monk&amp;rsquo;s Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#monks-knot&#34;
    aria-label=&#34;Link to this section: Monk&amp;amp;rsquo;s Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;I already talked of this knot in the 
&lt;a href=&#34;#heaving-line-knot&#34; 
 &gt;Heaving Line Knot
&lt;/a&gt;
,
and I quote it here because I use it even as a decorative knot for lanyards.&lt;/p&gt;
&lt;p&gt;I use this knot when I have only the end of a rope to decorate: it is bulky, a
bit long, and also a bit decorative.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&#34;shoelace-knots&#34;&gt;Shoelace Knots
  &lt;a class=&#34;header-link&#34; href=&#34;#shoelace-knots&#34;
    aria-label=&#34;Link to this section: Shoelace Knots&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;blockquote&gt;

&lt;h4 id=&#34;berluti-knot&#34;&gt;Berluti Knot
  &lt;a class=&#34;header-link&#34; href=&#34;#berluti-knot&#34;
    aria-label=&#34;Link to this section: Berluti Knot&#34;&gt;«&lt;/a&gt;
&lt;/h4&gt;
&lt;p&gt;Also known as the &amp;ldquo;Parisian Knot&amp;rdquo;, this is a very secure knot.
It is a popular choice for tying dress shoes and it is favored for its sleek appearance and functionality:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Appearance: The knot is low-profile and symmetrical, making it visually appealing for formal occasions.&lt;/li&gt;
&lt;li&gt;Stability: It stays tied throughout the day, providing reliable hold without the bulk of a double knot.&lt;/li&gt;
&lt;li&gt;Ease of Release: The knot can be easily untied by pulling both ends, allowing for quick removal.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;
&lt;a href=&#34;https://github.com/Klodii/dog_leash&#34; 
  target=&#34;_blank&#34; &gt;My dog leash
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
 &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
</item>

<item>
<title>Git triks</title>
<link>https://klaudjanpepaj.com/posts/git_triks/</link>
<pubDate>Mon, 23 Oct 2023 16:38:27 +0000</pubDate>

<guid>https://klaudjanpepaj.com/posts/git_triks/</guid>
<description>
&lt;h2 id=&#34;selective-adding-changes-to-staging-area&#34;&gt;Selective adding changes to staging area
  &lt;a class=&#34;header-link&#34; href=&#34;#selective-adding-changes-to-staging-area&#34;
    aria-label=&#34;Link to this section: Selective adding changes to staging area&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git add -p &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Git will break down your file into what it thinks are sensible &lt;em&gt;hunks&lt;/em&gt; (portions
of the file). It will then prompt you with this question:
&lt;code&gt;Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Here is a description of each option:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;y&lt;/strong&gt; stage this hunk for the next commit&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;n&lt;/strong&gt; do not stage this hunk for the next commit&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;q&lt;/strong&gt; quit; do not stage this hunk or any of the remaining hunks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;a&lt;/strong&gt; stage this hunk and all later hunks in the file&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;d&lt;/strong&gt; do not stage this hunk or any of the later hunks in the file&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;g&lt;/strong&gt; select a hunk to go to&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;/&lt;/strong&gt; search for a hunk matching the given regex&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;j&lt;/strong&gt; leave this hunk undecided, see next undecided hunk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;J&lt;/strong&gt; leave this hunk undecided, see next hunk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;k&lt;/strong&gt; leave this hunk undecided, see previous undecided hunk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;K&lt;/strong&gt; leave this hunk undecided, see previous hunk&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;s&lt;/strong&gt; split the current hunk into smaller hunks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;e&lt;/strong&gt; manually edit the current hunk
&lt;ul&gt;
&lt;li&gt;You can then edit the hunk manually by replacing +/- by #&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;?&lt;/strong&gt; print hunk help&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the file is not in the repository yet, you can first do &lt;code&gt;git add -N &amp;lt;filename&amp;gt;&lt;/code&gt;.
Afterwards you can go on with &lt;code&gt;git add -p &amp;lt;filename&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can use:
&lt;code&gt;git reset -p&lt;/code&gt; to unstage mistakenly added hunks.&lt;/p&gt;

&lt;h2 id=&#34;rename-branch&#34;&gt;Rename branch
  &lt;a class=&#34;header-link&#34; href=&#34;#rename-branch&#34;
    aria-label=&#34;Link to this section: Rename branch&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;To change the name &lt;strong&gt;locally&lt;/strong&gt; go into the branch you want to rename, and rename
it&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git switch &amp;lt;branch_name&amp;gt;
git branch -m &amp;lt;new_branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or you can do it without changing branch&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git branch -m &amp;lt;old_name&amp;gt; &amp;lt;new_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To change the name &lt;strong&gt;remotely&lt;/strong&gt; you have to delete the old name and push the new
branch&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git push origin --delete &amp;lt;old_name&amp;gt;
git push origin -u &amp;lt;new_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&#34;stash-single-files&#34;&gt;Stash single files
  &lt;a class=&#34;header-link&#34; href=&#34;#stash-single-files&#34;
    aria-label=&#34;Link to this section: Stash single files&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;When you don&amp;rsquo;t want to stash all the edited files, but only a subset, you can
use this command&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git stash push &amp;lt;file1&amp;gt; &amp;lt;file2&amp;gt; .. &amp;lt;fileN&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To make the stash retrieval easier, add a message with &lt;code&gt;-m &amp;lt;message&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&#34;diff-staged-changes&#34;&gt;Diff staged changes
  &lt;a class=&#34;header-link&#34; href=&#34;#diff-staged-changes&#34;
    aria-label=&#34;Link to this section: Diff staged changes&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git diff --staged
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&#34;remove-files-that-have-not-been-added-to-the-staging-area&#34;&gt;Remove files that have not been added to the staging area
  &lt;a class=&#34;header-link&#34; href=&#34;#remove-files-that-have-not-been-added-to-the-staging-area&#34;
    aria-label=&#34;Link to this section: Remove files that have not been added to the staging area&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git clean -df
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&#34;revert-changes-that-have-been-pushed-on-remote&#34;&gt;Revert changes that have been pushed on remote
  &lt;a class=&#34;header-link&#34; href=&#34;#revert-changes-that-have-been-pushed-on-remote&#34;
    aria-label=&#34;Link to this section: Revert changes that have been pushed on remote&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git diff master &amp;gt; branch.diff
git apply --reverse branch.diff
git rm branch.diff
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&#34;check-if-a-folder-changed&#34;&gt;Check if a folder changed
  &lt;a class=&#34;header-link&#34; href=&#34;#check-if-a-folder-changed&#34;
    aria-label=&#34;Link to this section: Check if a folder changed&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git diff --quiet HEAD &amp;lt;commit_to_compare&amp;gt; -- &amp;lt;dir_to_check&amp;gt; || &lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; changed
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that &lt;code&gt;git diff --quiet&lt;/code&gt; will &lt;strong&gt;exit 1&lt;/strong&gt; when there are changes.&lt;/p&gt;
&lt;p&gt;For example if you want to check if your current branch has changes in the directory
&lt;code&gt;dir1&lt;/code&gt; when compared to the previous commit:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git diff --quiet HEAD HEAD~1 -- dir1 || &lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; changed
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can do this even with the previous tag&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git diff --quiet HEAD &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#859900&#34;&gt;$(&lt;/span&gt;git describe --tags --abbrev=&lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;0&lt;/span&gt; HEAD&lt;span style=&#34;color:#859900&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt; -- dir1 || &lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; changed
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have used this command to help me automate my website release: 
&lt;a href=&#34;https://klaudjanpepaj.com/posts/how_to_deploy_automattically_hugo_site&#34; 
 &gt;How to
deploy automatically a Hugo
website
&lt;/a&gt;
.&lt;/p&gt;
</description>
</item>

<item>
<title>Access git remote with SSH</title>
<link>https://klaudjanpepaj.com/posts/git_with_ssh/</link>
<pubDate>Sat, 30 Sep 2023 06:31:03 +0000</pubDate>

<guid>https://klaudjanpepaj.com/posts/git_with_ssh/</guid>
<description>&lt;p&gt;When I started working, I found it challenging to work on my personal projects
and the work projects on the same machine. At that time I saved my
authentication data in the &lt;code&gt;.git-cretendials&lt;/code&gt; file, and I didn&amp;rsquo;t know how to
handle different credentials for different projects.&lt;/p&gt;
&lt;p&gt;After some researches I found out that &lt;strong&gt;you can access your projects with an
SSH key&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;But, what does that mean?&lt;br&gt;
At the beginning of my love-story with git, I learned
that to work with a remote server I had to use a private &lt;em&gt;password&lt;/em&gt; or &lt;em&gt;key&lt;/em&gt;.
For each push or pull, or more in general, for each command that had to interact
with &lt;em&gt;remote&lt;/em&gt;, I had to write the &lt;em&gt;password&lt;/em&gt;. Or better, I could save it
somewhere, ready to be used by git.&lt;/p&gt;
&lt;p&gt;With the SSH approach, you will not use a password, or at least, you will not
use a password like you are used to. You will use a pair of &lt;em&gt;SSH keys&lt;/em&gt;, one
&lt;em&gt;public&lt;/em&gt; and one &lt;em&gt;private&lt;/em&gt;, to authenticate with the remote server, like
&lt;em&gt;GitHub&lt;/em&gt; or &lt;em&gt;GitLab&lt;/em&gt;. Keeping the private half on your machine and installing
the public half on the remote server.&lt;br&gt;
This is how the authentication works:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Before setting up an SSH connection, the SSH client needs to generate its own
public-private key pair and store its public key on the remote server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The SSH client sends a login request to the remote server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The remote server searches for the client public key based on information
such as the username in the request, encrypts a random number using the
public key, and sends the encrypted random number to the client.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Upon receipt, the SSH client uses its own private key to decrypt the returned
information before sending the decrypted information to the remote server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The remote server checks whether the decrypted information sent by the SSH
client is correct; if the information is correct, authentication is
successful. &lt;img src=&#34;https://klaudjanpepaj.com/images/ssh_key_cycle.png&#34;alt=&#34;ssh_key_cycle&#34; title=&#34;ssh key cycle&#34; /&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There was another change that I had to make, given that I don&amp;rsquo;t use the same
name and email for all my projects I removed them from the global git
configuration (&lt;code&gt;~/.gitconfig&lt;/code&gt;). Instead of setting this data globally, as git
suggests, I set them locally for each project: &lt;code&gt;git config user.name &amp;quot;&amp;lt;Name&amp;gt;&amp;quot;&lt;/code&gt;.
For my private project I use my email, and for work-related projects I use the
work email.&lt;/p&gt;

&lt;h2 id=&#34;how-to-create-an-ssh-key&#34;&gt;How to create an SSH Key
  &lt;a class=&#34;header-link&#34; href=&#34;#how-to-create-an-ssh-key&#34;
    aria-label=&#34;Link to this section: How to create an SSH Key&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;To create the SSH keys, you can run the following command&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ ssh-keygen -t ed25519 -C &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&amp;lt;email&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The command will ask if you want to set a password for the key, omitting it will
allow you to use the key without entering the password each time you use it.&lt;/p&gt;
&lt;p&gt;The command will generate the keys in the current directory, so, I suggest
executing it in the &lt;code&gt;~/.ssh/&lt;/code&gt; directory. This directory is used to configure all
the SSH-related stuff.&lt;/p&gt;
&lt;p&gt;The command will generate two keys, one private and one public (&lt;code&gt;.pub&lt;/code&gt;). The
private key must remain private and must not be shared or used with more than
one device, for security reasons. The public key must be shared with all the
services that you want to interact with, in this case &lt;em&gt;GitHub&lt;/em&gt; or &lt;em&gt;GitLab&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;To make use of these keys easier, we can write a configuration file, named
&lt;code&gt;config&lt;/code&gt;, in the &lt;code&gt;~/.ssh/&lt;/code&gt; directory.&lt;/p&gt;
&lt;p&gt;This is an example of my configuration file&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;Host git-personal &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# name chosen by me&lt;/span&gt;
    Hostname github.com
    User git
    IdentityFile ~/.ssh/git_personal &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# private ssh-key&lt;/span&gt;

Host git-work &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# name chosen by me&lt;/span&gt;
    Hostname github.com
    User git
    IdentityFile ~/.ssh/git_work &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# private ssh-key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To use a key, you can enter the name you choose as the &lt;em&gt;Host&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;For example, to clone my own 
&lt;a href=&#34;https://github.com/Klodii/dotfiles&#34; 
  target=&#34;_blank&#34; &gt;dotfiles
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
 I
would write&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ git clone git-personal:Klodii/dotfiles.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Of course, I already associated my public key with my GitHub account; otherwise,
I would have gotten an error.&lt;/p&gt;
</description>
</item>

<item>
<title>How to deploy automatically a Hugo website</title>
<link>https://klaudjanpepaj.com/posts/how_to_deploy_automattically_hugo_site/</link>
<pubDate>Fri, 28 Jul 2023 15:28:35 +0000</pubDate>

<guid>https://klaudjanpepaj.com/posts/how_to_deploy_automattically_hugo_site/</guid>
<description>&lt;p&gt;I while ago I asked myself if there is a way to deploy automatically all the updates
of my website, which is written with 
&lt;a href=&#34;https://gohugo.io/&#34; 
  target=&#34;_blank&#34; &gt;Hugo framework
      
      &lt;svg width=&#34;16px&#34; height=&#34;16px&#34; viewBox=&#34;0 0 24 24&#34; style=&#34;cursor:pointer&#34;&gt;
          &lt;g stroke-width=&#34;2.1&#34; stroke=&#34;#666&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-linejoin=&#34;round&#34;&gt;
              &lt;polyline points=&#34;17 13.5 17 19.5 5 19.5 5 7.5 11 7.5&#34;&gt;&lt;/polyline&gt;
              &lt;path d=&#34;M14,4.5 L20,4.5 L20,10.5 M20,4.5 L11,13.5&#34;&gt;&lt;/path&gt;
          &lt;/g&gt;
      &lt;/svg&gt;
      
&lt;/a&gt;
.&lt;/p&gt;
&lt;p&gt;Before describing the automated procedure that I ended up using, I will describe
my workflow in order to make more clear my decisions.&lt;/p&gt;

&lt;h3 id=&#34;overview&#34;&gt;Overview
  &lt;a class=&#34;header-link&#34; href=&#34;#overview&#34;
    aria-label=&#34;Link to this section: Overview&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;The only thing we need to know, about how Hugo works, is that the static files that
will be used by Hugo to display the website, are located in the &lt;em&gt;public&lt;/em&gt; directory.
To generate these files we execute the &lt;code&gt;hugo&lt;/code&gt; command, which will check for
changes in the articles or the HTML templates, and if there are it will
create/edit the files in the &lt;em&gt;public&lt;/em&gt; directory.&lt;/p&gt;
&lt;p&gt;This is my workflow with git: I do all my changes as many times as I wish
and commit as many times as I want. Best if each commit as a single scope.&lt;br&gt;
When I feel that my work is ready to be released, I made sure that there are no
pending changes and execute the &lt;code&gt;hugo&lt;/code&gt; command. With the static files generated,
I commit them with a message that always begins with &lt;code&gt;release:&lt;/code&gt;, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ git commit -m &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;release: added &amp;#39;How to deploy automatically a Hugo website&amp;#39;&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;manual-procedure&#34;&gt;Manual procedure
  &lt;a class=&#34;header-link&#34; href=&#34;#manual-procedure&#34;
    aria-label=&#34;Link to this section: Manual procedure&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;To actually release the changes I have to SSH into the website server, go to the
project directory and &lt;code&gt;git pull&lt;/code&gt; all the changes, and finally restart the docker
container: which will apply all the new changes.&lt;/p&gt;

&lt;h3 id=&#34;automatic-procedure&#34;&gt;Automatic procedure
  &lt;a class=&#34;header-link&#34; href=&#34;#automatic-procedure&#34;
    aria-label=&#34;Link to this section: Automatic procedure&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;After some time that I have done this procedure, I started thinking if I can execute
all these steps automatically.&lt;br&gt;
The first part was easy, create a &lt;em&gt;cron job&lt;/em&gt; that will execute a bash script
every morning (which is shown at the end of this article).&lt;/p&gt;
&lt;p&gt;The second part was to create the script that will check if it is time to do a
new deployment and restart the container.&lt;/p&gt;
&lt;p&gt;Obviously, the script has to pull the latest changes, so I have to add a flag
to specify the project directory.&lt;br&gt;
But how to check if it is time to do a new deployment?
There were two solutions that came to my mind:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;check the commit messages, if there has been, through all the new commits,
a message that begins with &lt;em&gt;&amp;ldquo;release:&amp;quot;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;check if the &lt;em&gt;public&lt;/em&gt; directory has changed since the last time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first solution didn&amp;rsquo;t convince me, even if I have this convention at the moment
it could change at any time, and what if I do a typo while writing the commit message?
It was not reliable.&lt;/p&gt;
&lt;p&gt;Only one thing will remain the same over time until Hugo changes it:
when I&amp;rsquo;m ready to do a release I will update the &lt;em&gt;public&lt;/em&gt; directory. So it is
clear that a good solution is to check if this directory has changed since the last time.&lt;/p&gt;
&lt;p&gt;To check if the directory has changed I used the following git command&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git diff --quiet HEAD &amp;lt;commit_to_compare&amp;gt; -- &amp;lt;dir_to_check&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;em&gt;&amp;lt;commit_to_compare&amp;gt;&lt;/em&gt; is the hash of the HEAD before doing &lt;code&gt;git pull&lt;/code&gt; and &lt;em&gt;&amp;lt;dir_to_check&amp;gt;&lt;/em&gt;
is the &amp;ldquo;public&amp;rdquo; directory. This command returns 0 if there are no changes, and 1 otherwise.&lt;/p&gt;
&lt;p&gt;This is the bash script:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;#!/bin/bash
&lt;/span&gt;&lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#859900&#34;&gt;function&lt;/span&gt; exit_w_error {
    &lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;
    &lt;span style=&#34;color:#cb4b16&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;1&lt;/span&gt;
} &amp;gt;&amp;amp;&lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# redirect to STDERR&lt;/span&gt;
&lt;span style=&#34;color:#859900&#34;&gt;function&lt;/span&gt; is_installed {
    [ -z &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$1&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt; ] &amp;amp;&amp;amp; exit_w_error &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;Command name missing&amp;#34;&lt;/span&gt;
    &lt;span style=&#34;color:#268bd2&#34;&gt;COMMAND&lt;/span&gt;=&lt;span style=&#34;color:#268bd2&#34;&gt;$1&lt;/span&gt;
    &lt;span style=&#34;color:#268bd2&#34;&gt;FOUND&lt;/span&gt;=&lt;span style=&#34;color:#cb4b16&#34;&gt;false&lt;/span&gt;
    &lt;span style=&#34;color:#268bd2&#34;&gt;PATH_SPACED&lt;/span&gt;=&lt;span style=&#34;color:#2aa198&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;PATH&lt;/span&gt;//:/ &lt;span style=&#34;color:#2aa198&#34;&gt;}&lt;/span&gt; &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# separate each path by space instead of :&lt;/span&gt;
    &lt;span style=&#34;color:#859900&#34;&gt;for&lt;/span&gt; individual_path in &lt;span style=&#34;color:#2aa198&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;PATH_SPACED&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;}&lt;/span&gt;; &lt;span style=&#34;color:#859900&#34;&gt;do&lt;/span&gt;
        &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# true if file exist and is executable&lt;/span&gt;
        [ -x &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$individual_path&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$COMMAND&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt; ] &amp;amp;&amp;amp; &lt;span style=&#34;color:#268bd2&#34;&gt;FOUND&lt;/span&gt;=&lt;span style=&#34;color:#cb4b16&#34;&gt;true&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&#34;color:#cb4b16&#34;&gt;break&lt;/span&gt;
    &lt;span style=&#34;color:#859900&#34;&gt;done&lt;/span&gt;
}


&lt;span style=&#34;color:#268bd2&#34;&gt;SCRIPT_NAME&lt;/span&gt;=&lt;span style=&#34;color:#2aa198&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;0&lt;/span&gt;##*/&lt;span style=&#34;color:#2aa198&#34;&gt;}&lt;/span&gt;  &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# performed a string manipulation operation to get the script name&lt;/span&gt;
&lt;span style=&#34;color:#268bd2&#34;&gt;DIR_TO_MONITOR&lt;/span&gt;=&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;website/public&amp;#39;&lt;/span&gt;
&lt;span style=&#34;color:#859900&#34;&gt;function&lt;/span&gt; &lt;span style=&#34;color:#cb4b16&#34;&gt;help&lt;/span&gt; {
    &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# here-document used instead of echoing all lines&lt;/span&gt;
   cat &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;lt;&amp;lt;-HMESSAGE
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;Perform a git pull and check if the &amp;#39;$DIR_TO_MONITOR&amp;#39; directory has changed.
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;If this directory has changed, restart the production container to
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;release the new updates.
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;This is possible because the Hugo framework uses the &amp;#39;public&amp;#39; directory to
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;store the files that have to be published, and we update it only when
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;we are ready to publish.
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;So, if the directory is updated this means that we can publish the changes.
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;Syntax: $SCRIPT_NAME [-hvd]
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;Options:
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;    -h     Print this help and exit.
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;    -v     Make messages more verbose
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;    -d     Directory of the git project to check
&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;HMESSAGE&lt;/span&gt;
}


&lt;span style=&#34;color:#268bd2&#34;&gt;DIR&lt;/span&gt;=&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;
&lt;span style=&#34;color:#268bd2&#34;&gt;DEBUG&lt;/span&gt;=&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;:&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# no-op, do nothing command&lt;/span&gt;
&lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# Get the options&lt;/span&gt;
&lt;span style=&#34;color:#859900&#34;&gt;while&lt;/span&gt; &lt;span style=&#34;color:#cb4b16&#34;&gt;getopts&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;hvd:&amp;#34;&lt;/span&gt; option; &lt;span style=&#34;color:#859900&#34;&gt;do&lt;/span&gt;
    &lt;span style=&#34;color:#859900&#34;&gt;case&lt;/span&gt; &lt;span style=&#34;color:#268bd2&#34;&gt;$option&lt;/span&gt; in
        h )
            &lt;span style=&#34;color:#cb4b16&#34;&gt;help&lt;/span&gt;
            &lt;span style=&#34;color:#cb4b16&#34;&gt;exit&lt;/span&gt; 0;;
        v )
            &lt;span style=&#34;color:#268bd2&#34;&gt;DEBUG&lt;/span&gt;=&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;echo&amp;#39;&lt;/span&gt;;;
        d )
            &lt;span style=&#34;color:#268bd2&#34;&gt;DIR&lt;/span&gt;=&lt;span style=&#34;color:#268bd2&#34;&gt;$OPTARG&lt;/span&gt;;;
        &lt;span style=&#34;color:#2aa198&#34;&gt;\?&lt;/span&gt;)
            &lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;Error: Invalid option&amp;#34;&lt;/span&gt;
            &lt;span style=&#34;color:#cb4b16&#34;&gt;exit&lt;/span&gt; 1;;
    &lt;span style=&#34;color:#859900&#34;&gt;esac&lt;/span&gt;
&lt;span style=&#34;color:#859900&#34;&gt;done&lt;/span&gt;
&lt;span style=&#34;color:#cb4b16&#34;&gt;shift&lt;/span&gt; &lt;span style=&#34;color:#859900&#34;&gt;$((&lt;/span&gt;OPTIND -&lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#859900&#34;&gt;))&lt;/span&gt; &lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# remove all options from $#&lt;/span&gt;

&lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#859900&#34;&gt;$(&lt;/span&gt;date&lt;span style=&#34;color:#859900&#34;&gt;)&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt; - executing &amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$SCRIPT_NAME&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39; script&amp;#34;&lt;/span&gt;

is_installed git
is_installed docker

[ -d &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt; ] &amp;amp;&amp;amp; &lt;span style=&#34;color:#cb4b16&#34;&gt;cd&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&#34;color:#268bd2&#34;&gt;$DEBUG&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;Moved to &lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;

[ -d &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR_TO_MONITOR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt; ] || exit_w_error &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR_TO_MONITOR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39; does not exist in the current directory&amp;#34;&lt;/span&gt;

&lt;span style=&#34;color:#268bd2&#34;&gt;PRE_PULL_HASH&lt;/span&gt;=&lt;span style=&#34;color:#859900&#34;&gt;$(&lt;/span&gt;git rev-parse HEAD&lt;span style=&#34;color:#859900&#34;&gt;)&lt;/span&gt;

&lt;span style=&#34;color:#268bd2&#34;&gt;$DEBUG&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;Pulling from remote&amp;#39;&lt;/span&gt;
&lt;span style=&#34;color:#859900&#34;&gt;if&lt;/span&gt; [ &lt;span style=&#34;color:#268bd2&#34;&gt;$DEBUG&lt;/span&gt; = &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;:&amp;#39;&lt;/span&gt; ];&lt;span style=&#34;color:#859900&#34;&gt;then&lt;/span&gt;
    git pull --quiet
&lt;span style=&#34;color:#859900&#34;&gt;else&lt;/span&gt;
    git pull
&lt;span style=&#34;color:#859900&#34;&gt;fi&lt;/span&gt;

&lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# --quiet makes the command return 0 if there are no changes, 1 otherwise&lt;/span&gt;
&lt;span style=&#34;color:#859900&#34;&gt;$(&lt;/span&gt;git diff --quiet HEAD &lt;span style=&#34;color:#268bd2&#34;&gt;$PRE_PULL_HASH&lt;/span&gt; -- &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR_TO_MONITOR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#859900&#34;&gt;)&lt;/span&gt; &amp;amp;&amp;amp; { &lt;span style=&#34;color:#268bd2&#34;&gt;$DEBUG&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;The &amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR_TO_MONITOR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39; directory was not updated&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;NOT UPDATING the website&amp;#34;&lt;/span&gt;; &lt;span style=&#34;color:#cb4b16&#34;&gt;exit&lt;/span&gt; 0; }

&lt;span style=&#34;color:#268bd2&#34;&gt;$DEBUG&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;The &amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;$DIR_TO_MONITOR&lt;/span&gt;&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39; directory was updated, restarting the production container&amp;#34;&lt;/span&gt;
&lt;span style=&#34;color:#cb4b16&#34;&gt;echo&lt;/span&gt; &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;UPDATING the website&amp;#34;&lt;/span&gt;
docker compose restart
&lt;span style=&#34;color:#cb4b16&#34;&gt;exit&lt;/span&gt; &lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is how I set the cron job&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;color:#93a1a1;font-style:italic&#34;&gt;# every day at 6:00 AM, in the Rome timezone&lt;/span&gt;
&lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#2aa198;font-weight:bold&#34;&gt;3&lt;/span&gt; * * * &amp;lt;path to script&amp;gt; -d &amp;lt;path to website&amp;gt; &amp;gt;&amp;gt; &amp;lt;path to log file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
</item>

<item>
<title>Git worktree</title>
<link>https://klaudjanpepaj.com/posts/git_worktree/</link>
<pubDate>Mon, 17 Apr 2023 22:40:44 +0200</pubDate>

<guid>https://klaudjanpepaj.com/posts/git_worktree/</guid>
<description>&lt;p&gt;&lt;em&gt;Git worktree&lt;/em&gt; is not just a command; it&amp;rsquo;s the first step toward a
new way to work. It enables you to be in different branches at the same time.
Let me explain what I mean.&lt;/p&gt;

&lt;h2 id=&#34;what-it-is&#34;&gt;What it is
  &lt;a class=&#34;header-link&#34; href=&#34;#what-it-is&#34;
    aria-label=&#34;Link to this section: What it is&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;git worktree&lt;/strong&gt; allows you to have multiple working trees for a single Git
repository. This means you can have multiple instances of your repository on
your file system, each with its own working &lt;strong&gt;directory&lt;/strong&gt;, but all sharing the
same Git history. This makes it easier to work with multiple branches, as you
can have a separate working directory for each branch.&lt;/p&gt;

&lt;h2 id=&#34;why-i-use-it&#34;&gt;Why I use it
  &lt;a class=&#34;header-link&#34; href=&#34;#why-i-use-it&#34;
    aria-label=&#34;Link to this section: Why I use it&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Git worktrees are extremely useful when you work with different branches at the
same time. The main strength is the possibility to jump from one branch to
another, without the need to &lt;code&gt;stash&lt;/code&gt; or &lt;code&gt;commit&lt;/code&gt; the pending changes. This
avoids the creation of &lt;em&gt;temporary&lt;/em&gt;&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; commits, that in most cases will remain
in the commit history.&lt;/p&gt;
&lt;p&gt;How many times have you had to resolve an urgent bug in production while you
were developing something new? It can happen, in this case you &lt;em&gt;stash&lt;/em&gt; or
&lt;em&gt;commit&lt;/em&gt; all your unstaged code, &lt;em&gt;switch&lt;/em&gt; to your main branch, fix the bug,
commit it and then return to the previous branch and retrieve all your stashed
code. This procedure can be tedious and time-consuming operation.&lt;/p&gt;
&lt;p&gt;With git worktrees you can handle this case more easily. Each time you have to
abandon what you are doing and make some implementation to another branch, all
you have to do is change the directory. Make all the changes you have to do and
then return to the previous working directory. And you will find all your
unstaged changes still there.&lt;/p&gt;

&lt;h2 id=&#34;how-i-use-it&#34;&gt;How I use it
  &lt;a class=&#34;header-link&#34; href=&#34;#how-i-use-it&#34;
    aria-label=&#34;Link to this section: How I use it&#34;&gt;«&lt;/a&gt;
&lt;/h2&gt;

&lt;h3 id=&#34;create-work-tree&#34;&gt;Create work tree
  &lt;a class=&#34;header-link&#34; href=&#34;#create-work-tree&#34;
    aria-label=&#34;Link to this section: Create work tree&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;To create a worktree run:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;git worktree add &amp;lt;pat_to_directory&amp;gt; &amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Where &lt;code&gt;&amp;lt;path_to_directory&amp;gt;&lt;/code&gt; will be the new location of the work tree and
&lt;code&gt;&amp;lt;branch_name&amp;gt;&lt;/code&gt; is the initial branch of the worktree.&lt;/p&gt;
&lt;p&gt;I found it useful to put all my working directories in a directory named
&lt;em&gt;forest&lt;/em&gt;. Usually I use a custom script that creates the work tree in the
&lt;em&gt;forest&lt;/em&gt; directory and copies, from the main working directory, all the
env/secrets files needed for the project, to the newly created working
directory.&lt;/p&gt;

&lt;h3 id=&#34;hop-between-working-directories&#34;&gt;Hop between working directories
  &lt;a class=&#34;header-link&#34; href=&#34;#hop-between-working-directories&#34;
    aria-label=&#34;Link to this section: Hop between working directories&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;To hop from one working directory to another, quicker than
&lt;code&gt;cd /path/to/working_directory/&lt;/code&gt; into it, I wrote this useful alias&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#586e75;background-color:#eee8d5;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;color:#cb4b16&#34;&gt;cd&lt;/span&gt; &lt;span style=&#34;color:#268bd2&#34;&gt;$FDIR&lt;/span&gt;/&lt;span style=&#34;color:#859900&#34;&gt;$(&lt;/span&gt;ls &lt;span style=&#34;color:#268bd2&#34;&gt;$FDIR&lt;/span&gt; | fzf --height &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;25%&amp;#34;&lt;/span&gt; --header &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#34;Choose the workingtree&amp;#34;&lt;/span&gt; --reverse --border&lt;span style=&#34;color:#859900&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Where the &lt;code&gt;$FDIR&lt;/code&gt; contains the path to the forest directory. With the use of
&lt;code&gt;fzf&lt;/code&gt; we can list all the worktrees, and with a few characters, you can identify
the directory and change location.
&lt;img src=&#34;https://klaudjanpepaj.com/images/worktree_comand.png&#34;alt=&#34;worktree_comand&#34; title=&#34;worktree_comand in action&#34; /&gt;&lt;/p&gt;

&lt;h3 id=&#34;remove-a-work-tree&#34;&gt;Remove a work tree
  &lt;a class=&#34;header-link&#34; href=&#34;#remove-a-work-tree&#34;
    aria-label=&#34;Link to this section: Remove a work tree&#34;&gt;«&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Usually, before doing the removal I list all working trees/directories,
&lt;code&gt;git worktree list&lt;/code&gt;, and then I proceed with the removal, &lt;code&gt;git worktree remove&lt;/code&gt;.
This operation simply deletes the worktree directory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; you could delete the worktree directory with the &lt;code&gt;rm&lt;/code&gt; command, but by
doing this you could leave something pending. In this case, you can remove all
pending things by executing &lt;code&gt;git worktree prune&lt;/code&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;&amp;ldquo;There is nothing more permanent than a temporary solution&amp;rdquo; &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
</item>

</channel>
</rss>
