<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: crazyoptimist</title>
    <description>The latest articles on DEV Community by crazyoptimist (@crazyoptimist).</description>
    <link>https://dev.to/crazyoptimist</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F300468%2F79d6eb6a-666f-40b9-b122-6d53644d0994.png</url>
      <title>DEV Community: crazyoptimist</title>
      <link>https://dev.to/crazyoptimist</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/crazyoptimist"/>
    <language>en</language>
    <item>
      <title>How to clean up disk space on Ubuntu server</title>
      <dc:creator>crazyoptimist</dc:creator>
      <pubDate>Sat, 29 May 2021 05:44:00 +0000</pubDate>
      <link>https://dev.to/crazyoptimist/how-to-clean-up-disk-space-on-ubuntu-server-40gp</link>
      <guid>https://dev.to/crazyoptimist/how-to-clean-up-disk-space-on-ubuntu-server-40gp</guid>
      <description>&lt;p&gt;If you are running your own cloud instances and use them for development purposes, their capacities would probably be limited and sometimes you might notice that the disk space is too low.&lt;/p&gt;

&lt;p&gt;TL;DR&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove unnecessary system packages and package caches
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nt"&gt;--purge&lt;/span&gt; autoremove
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get autoclean
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get clean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Remove system log except for the last 3 days
&lt;/h2&gt;

&lt;p&gt;Check it first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;journalctl &lt;span class="nt"&gt;--disk-usage&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;journalctl &lt;span class="nt"&gt;--vacuum-time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actually it grows day by day, so you can create a cron script to clean up journal logs once a month for example, or can configure it to use limited amount of disk space by setting &lt;code&gt;SystemMaxUse=50M&lt;/code&gt; in &lt;code&gt;/etc/systemd/journald.conf&lt;/code&gt;. Then reload conf:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart systemd-journald
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Clean up snap
&lt;/h2&gt;

&lt;p&gt;Check it first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;du&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt; /var/lib/snapd/snaps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a bash script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Removes old revisions of snaps&lt;/span&gt;
&lt;span class="c"&gt;# CLOSE ALL SNAPS BEFORE RUNNING THIS&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-eu&lt;/span&gt;
snap list &lt;span class="nt"&gt;--all&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'/disabled/{print $1, $3}'&lt;/span&gt; |
    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read &lt;/span&gt;snapname revision&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
        &lt;/span&gt;snap remove &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$snapname&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--revision&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$revision&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please add more in the comment section if you have another ones.&lt;/p&gt;

&lt;p&gt;Happy coding! :)&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>linux</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to Use Git Rebase in a Practical Situation</title>
      <dc:creator>crazyoptimist</dc:creator>
      <pubDate>Wed, 14 Oct 2020 20:15:55 +0000</pubDate>
      <link>https://dev.to/crazyoptimist/how-to-use-git-rebase-in-a-practical-situation-2fge</link>
      <guid>https://dev.to/crazyoptimist/how-to-use-git-rebase-in-a-practical-situation-2fge</guid>
      <description>&lt;p&gt;Imagine that there are two pull requests open on a project repository.&lt;br&gt;
Each change has its own branch like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;master&lt;/li&gt;
&lt;li&gt;feature/add-base64-endpoint&lt;/li&gt;
&lt;li&gt;feature/add-user-agent-endpoint&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The challenge is to use git rebase to add both changes to master. When you finished, your master branch should have three commits in the following order:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;feat: add user-agent endpoint&lt;/li&gt;
&lt;li&gt;feat: add base64 endpoint&lt;/li&gt;
&lt;li&gt;init&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Okay, let’s go!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone repo_url
git status
git checkout feature/add-base64-endpoint
git rebase master
git status
git checkout master
git merge feature/add-base64-endpoint
git status
git checkout feature/add-user-agent-endpoint
git rebase master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oops! You should see &lt;code&gt;rebase conflict&lt;/code&gt;!&lt;br&gt;
You need to check the conflicted parts and fix it. Fortunately VS Code provides some great hints for you to do that.&lt;br&gt;
I personally use Vim as my IDE because I'm a huge fan of Vim!&lt;br&gt;
Do not forget to check if the code base is functionable even after you resolve the conflicts, i.e. all the tests should be green, app should be functional eventually.&lt;br&gt;
Once you finish resolving conflicts, follow these steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git rebase &lt;span class="nt"&gt;--continue&lt;/span&gt;
git checkout master
git status
git checkout master
git merge feature/add-user-agent-endpoint
git status
git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom! You must be done!&lt;br&gt;
Happy gitting! 😉&lt;/p&gt;

</description>
      <category>git</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to Make a Swap Space Using a Swap File in Linux</title>
      <dc:creator>crazyoptimist</dc:creator>
      <pubDate>Wed, 07 Oct 2020 04:13:32 +0000</pubDate>
      <link>https://dev.to/crazyoptimist/how-to-make-a-swap-space-using-a-swap-file-in-linux-2gd7</link>
      <guid>https://dev.to/crazyoptimist/how-to-make-a-swap-space-using-a-swap-file-in-linux-2gd7</guid>
      <description>&lt;p&gt;This article has been ported from &lt;a href="https://crazyoptimist.net/posts/2020/how-to-make-a-swap-space-using-a-swap-file-in-linux" rel="noopener noreferrer"&gt;my personal blog&lt;/a&gt;&lt;br&gt;
You might have been stuck in memory leak when building some kinda javascript-heavy frontend apps like Vue or React on a cloud server itself.  Just for serving built artifacts, we do not need large instances, but still the building process is always hungry for more memory you know.&lt;br&gt;
Below is how to resolve such specific problem.&lt;br&gt;
Oh, this is not the case if you already have a dedicated(partitioned) swap space, it's a better option in any case but in most cases, we will be playing with servers without a swap patition.&lt;br&gt;
Okay, let's get started.&lt;br&gt;
As a general rule, calculate swap space according to the following:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Amount of physical RAM&lt;/th&gt;
&lt;th&gt;Recommended swap space&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2 GB or &lt;strong&gt;less&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;2 * &lt;code&gt;Amount of physical RAM&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;More&lt;/strong&gt; than 2 GB, &lt;strong&gt;less&lt;/strong&gt; than 32 GB&lt;/td&gt;
&lt;td&gt;4 GB + (&lt;code&gt;Amount of physical RAM&lt;/code&gt; – 2 GB)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32 GB or &lt;strong&gt;more&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;1 *  &lt;code&gt;Amount of physical RAM&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Important Note: Swap sapce should never be less than 32 MB!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Create a swap file
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/swapfile &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;128M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_COUNT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the above command, &lt;strong&gt;bs&lt;/strong&gt; is &lt;em&gt;block size&lt;/em&gt; which should be less than the available memory at that moment.&lt;br&gt;
&lt;code&gt;bs * YOUR_COUNT&lt;/code&gt; will be your swap file size, for example, &lt;code&gt;bs=128M count=32&lt;/code&gt; means your swap file will be 4096 MB in size.&lt;/p&gt;
&lt;h4&gt;
  
  
  Update the read and write permissions for the swap file
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chmod &lt;/span&gt;600 /swapfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Set up a Linux swap area
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;mkswap /swapfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Make the swap file available for immediate use by adding the swap file to swap space
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;swapon /swapfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Verify that the procedure was successful:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;swapon &lt;span class="nt"&gt;-s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Enable the swap file at boot time by editing the &lt;code&gt;/etc/fstab&lt;/code&gt; file
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;vim /etc/fstab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Add the following line at the end of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="err"&gt;/swapfile&lt;/span&gt; &lt;span class="err"&gt;swap&lt;/span&gt; &lt;span class="err"&gt;swap&lt;/span&gt; &lt;span class="err"&gt;defaults&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it.&lt;br&gt;
Happy coding!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devops</category>
      <category>aws</category>
      <category>googlecloud</category>
    </item>
    <item>
      <title>DEPLOY YOUR WEB APPLICATIONS IN A MINUTE - MADE WITH 💖 FOR DOCKERISTS</title>
      <dc:creator>crazyoptimist</dc:creator>
      <pubDate>Tue, 08 Sep 2020 01:29:40 +0000</pubDate>
      <link>https://dev.to/crazyoptimist/deploy-your-web-applications-in-a-minute-made-with-for-dockerists-1mab</link>
      <guid>https://dev.to/crazyoptimist/deploy-your-web-applications-in-a-minute-made-with-for-dockerists-1mab</guid>
      <description>&lt;p&gt;As a software engineer or a DevOps engineer, you may come up with boring tasks frequently, one of which is setting up a new cloud environment for deployment of your awesome web apps/micro services.&lt;/p&gt;

&lt;p&gt;Using the following script, you will lose the dull pain. Just grab the script and run it with bash, then you will get the complete environment with docker/docker-compose and nginx which are all on the latest stable version.&lt;/p&gt;

&lt;p&gt;Note: This is just for Ubuntu Bionic/Focal. Buzz me anytime in case you want to get the same one for any other distro, I'd love to help!&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Happy containerizing! 🐋&lt;/p&gt;

&lt;p&gt;Originally posted on my blog &lt;a href="https://crazyoptimist.net/posts/2020/deploy-your-web-apps-in-just-a-minute-made-with-love-for-dockerists" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
