<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title><![CDATA[airton.dev]]></title>
    <link href="https://airton.dev/til-feed.xml" rel="self"/>
    <link href="https://airton.dev/"/>
    <updated>2024-08-28T09:54:31+00:00</updated>
    <id>https://airton.dev/</id>
            <author>
            <name><![CDATA[Airton Zanon]]></name>            <email><![CDATA[me@airton.dev]]></email>        </author>
                                                                                                <generator uri="http://sculpin.io/">Sculpin</generator>
            <entry>
            <title type="html"><![CDATA[Creating a directory in VIM&#039;s explorer (Netrw)]]></title>
            <link href="https://airton.dev/til/creating-a-directory-in-vims-explorer-netrw/"/>
            <updated>2024-08-28T00:00:00+00:00</updated>
            <id>https://airton.dev/til/creating-a-directory-in-vims-explorer-netrw/</id>
            <content type="html"><![CDATA[<p>By just pressing the key <code>d</code>, you will be presented with the prompt to add the directory name. (PS: don't do <code>:d</code>, just press the key d)</p>

<p>If you want to know how to <a href="https://airton.dev/til/creating-a-file-in-vims-explorer-netrw/" title="Create a file in VIM's explorer (same website)">Create a file in VIM's explorer</a>, I have a TIL from some time ago.</p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[VIM - Make spaces and tabs visible]]></title>
            <link href="https://airton.dev/til/vim-make-spaces-and-tabs-visible/"/>
            <updated>2023-07-12T00:00:00+00:00</updated>
            <id>https://airton.dev/til/vim-make-spaces-and-tabs-visible/</id>
            <content type="html"><![CDATA[<p>I usually use <strong>VIM</strong> to code, and sometimes I have problems finding indentation or some random spaces in the end of a line.</p>

<p>Googled a bit today and found out about <code>list</code> in VIM. In which enables the strings to use in 'list' mode and for the <code>:list</code> command. So, instead of shows just an empty space, it will show a character instead (this is configurable, and below I show how to do it).</p>

<p>For you to configure this, you need to set <code>listchars</code> and add some parameters.</p>

<p>Parameters that I'm using:</p>

<table>
<thead>
<tr>
  <th></th>
  <th></th>
</tr>
</thead>
<tbody>
<tr>
  <td><code>eol:$</code></td>
  <td><strong>End of line</strong>, the end of the line will show <code>$</code></td>
</tr>
<tr>
  <td><code>space:-</code></td>
  <td>Each <strong>space</strong> will be a dash <code>-</code> instead of whitespace</td>
</tr>
<tr>
  <td><code>tab:&gt;#</code></td>
  <td>Each <strong>tab</strong> will show <code>&gt;######</code> instead of a big whitespace</td>
</tr>
<tr>
  <td><code>trail:~</code></td>
  <td><strong>Trailing spaces</strong>, it will show <code>~</code> instead of the amount of spaces given</td>
</tr>
</tbody>
</table>

<p>So if we go inside vim and do the following:</p>

<pre><code>:set listchars=eol:$,space:-,tab:&gt;#,trail:~
:set list
</code></pre>

<p>A normal text like the first two paragraphs will be:</p>

<pre><code>I-usually-use-VIM-to-code,-and-sometimes-I-have-problems-finding-indentation-or-some-random-spaces-in-the-end-of-a-line.$
$
Googled-a-bit-today-and-found-out-about-`list`-in-VIM.-In-which-enables-the-strings-to-use-in-'list'-mode-and-for-the-`:list`-command.-So,-instead-of-shows-just-an-empty-space,-it-will-show-a-character-instead-(this-is-configurable,-and-below-I-show-how-to-do-it)$
~~~~~~~~~~$
The-line-above-has-10-spaces$
The-line-below-has-two-tabs$
&gt;######&gt;######$
</code></pre>

<p>It might be a little bit too noisy, so I created an alias to enable and disable that on <code>~/.config/nvim/init.vim</code> (I use neo vim).</p>

<p>You can find how to do that here: <a href="https://gist.github.com/airtonzanon/fae437d4b0808d5b9946a25945e9fc07#file-init-vim-L22">https://gist.github.com/airtonzanon/fae437d4b0808d5b9946a25945e9fc07#file-init-vim-L22</a></p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[Linux Screen - The Basics]]></title>
            <link href="https://airton.dev/til/linux-screen-the-basics/"/>
            <updated>2023-01-24T00:00:00+00:00</updated>
            <id>https://airton.dev/til/linux-screen-the-basics/</id>
            <content type="html"><![CDATA[<p>I always need to Google how to use a screen in Linux, every time I need to run parallel scripts or whenever I need to leave a process running for a long time, that's why I decided to add here what I always use and then I won't need to Google it again.</p>

<p>A simple explanation about Linux Screen:</p>

<blockquote>
  <p>Screen or GNU Screen is a terminal multiplexer. In other words, it means that you can start a screen session and then open any number of windows (virtual terminals) inside that session
  (this is a quote from Linuxize, in <a href="https://linuxize.com/post/how-to-use-linux-screen/">this link</a> you can see how to install and so many other commands, tricks and so on, I'll only state here the commands that I use)</p>
</blockquote>

<p><code>screen -ls</code> - List all screens</p>

<p><code>screen -S name_of_the_screen</code> - Create a new Screen with the given name</p>

<p><code>CTRL A + D</code> - Detach from a screen</p>

<p><code>screen -r 123.name_of_the_screen</code> - Reattach to the given screen (the screen needs to be detached)</p>

<p><code>screen -D 123.name_of_the_screen</code> - Detach an attached screen</p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[QMK - How to flash Arduino Pro Micro or Elite-C]]></title>
            <link href="https://airton.dev/til/qmk-how-to-flash-arduino-pro-micro-or-elite-c/"/>
            <updated>2022-08-09T00:00:00+00:00</updated>
            <id>https://airton.dev/til/qmk-how-to-flash-arduino-pro-micro-or-elite-c/</id>
            <content type="html"><![CDATA[<p>If you want to flash a microcontroller to be your keyboard you can use <strong>QMK</strong> for that. You can even use the <strong>QMK toolbox</strong> to do it, which is a UI that helps you to flash/compile your keyboard mapping and even to already select the kind of bootloader that you use to flash your microcontroller.</p>

<p>If you want to flash a recently edited or something that you changed recently on the configuration file, you might need to use the command line for that. There was when I questioned <em>"How will I do it for the Elite-C?"</em>.</p>

<p>I use <strong>Arduino Pro Micro</strong> for almost all <strong>keyboards</strong> that I built, but because of micro usb not being the best when it comes to durability, I choose <strong>Elite-C</strong> to be the microcontroller for one of the keyboards that I created.</p>

<p>So here's how you <strong>flash</strong> it:</p>

<h3 id="arduino-pro-micro%3A">Arduino Pro Micro:</h3>

<p><img src="//images.ctfassets.net/4cjvqtuc6fhd/2WIR3VxqtV8pLK4LOcQSs4/03d2c0cfb2505244df3740f59355089e/Screenshot_2022-08-09_at_18.59.22.png" alt="Arduino Pro Micro" style="display: block; margin-left: auto; margin-right: auto; width: 50%;"/></p>

<pre><code>qmk flash -kb sofle -km default -bl avrdude
</code></pre>

<p><em>or stay in the root of qmk_firmware folder and run the command below</em></p>

<pre><code>make sofle:default:avrdude
</code></pre>

<p>With that, the keymap will compile and it will ask flash the Arduino, if you connect reset to ground, it will accept the flash.</p>

<p><img src="//images.ctfassets.net/4cjvqtuc6fhd/1soiGFJ4ckJWokzhZEZx5Y/86102e9134d7fabf3a3b6efdd60c569a/Screenshot_2022-08-09_at_18.54.23.png" alt="Arduino Pro Micro - Reset" style="display: block; margin-left: auto; margin-right: auto; width: 30%;"/></p>

<h3 id="elite-c%3A">Elite-C:</h3>

<p><img src="//images.ctfassets.net/4cjvqtuc6fhd/6Ql87PwhCyOQ9QbVQP7nu4/c8619b36d3253b82bbb850e66060d302/Screenshot_2022-08-09_at_19.02.06.png" alt="Elite C" style="display: block; margin-left: auto; margin-right: auto; width: 50%;"/></p>

<pre><code>qmk flash -kb sofle -km default -bl dfu
</code></pre>

<p><em>or stay in the root of qmk_firmware folder and run the command below</em></p>

<pre><code>make sofle:default:dfu
</code></pre>

<p>With that, the bootloader used will be DFU instead of avrdudes (used for Arduino Pro Micro). You don't need to do anything in the board to flash it.</p>

<hr />

<p>This is simple and easy, but I took a while to find this info, so here it is :D</p>

<p>For more info about QMK and flashing, go to their wiki page <a href="https://github.com/qmk/qmk_firmware/blob/master/docs/flashing.md">https://github.com/qmk/qmk_firmware/blob/master/docs/flashing.md</a></p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[Vim Macros]]></title>
            <link href="https://airton.dev/til/vim-macros/"/>
            <updated>2022-07-06T00:00:00+00:00</updated>
            <id>https://airton.dev/til/vim-macros/</id>
            <content type="html"><![CDATA[<p>It has been a long time since I created a TIL entry here, but yesterday I wanted to move some PHP doc properties types to the proper property type that we already have for a while in <strong>PHP</strong> 7.4.</p>

<p>I tried to find a <strong>PHPStorm</strong> plugin for that, but couldn't, so I thought, macros in <strong>VIM</strong> is something that I've seen the power watching some twitch developers programming, but I never did it.</p>

<p>I got really happy with how easy it is to set up and run the macros, so here we go:</p>

<p>Press <code>q</code> <em>this will start the macro recording</em></p>

<p>Give a name to it, for example <code>m</code> <em>it only accepts one character</em></p>

<p>Make all the movements that you want to record and reproduce in the future.</p>

<p>In my example above, for typed properties in PHP from the PHP Docblock, I put the cursor in the beginning of the line of the one line docblock and <code>wwwwvwhyjhhpkddjj0</code>. This will pick the type from the docblock, add it after the property visibility but before the property and goes to the next line of docblock.</p>

<p>Press <code>q</code> again.</p>

<p>With that, you got yourself a recorded macro.</p>

<p>To run, type <code>@m</code>, if you want to do it multiple times (5 for example), type <code>5@m</code>, this will run the macro 5 times.</p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[Spell checker on Vim]]></title>
            <link href="https://airton.dev/til/spell-checker-on-vim/"/>
            <updated>2020-07-08T00:00:00+00:00</updated>
            <id>https://airton.dev/til/spell-checker-on-vim/</id>
            <content type="html"><![CDATA[<p>As I've writing some TIL posts lately, and I'm doing that using <strong>VIM</strong> as my main editor for it.</p>

<p>Sometimes I get a little bit worried about typos / wrong spelling as I'm not a native English speaker sometimes I do some silly errors (also on grammar, but that's another post for here hehe)</p>

<p>Vim already have a spell checker that we can set the language like that:</p>

<pre><code>set spelllang=en
</code></pre>

<p>And enable it with <code>set spell</code>, if we want to have this enabled every time that we open VIM, we need to add the "<code>set spell</code>" on our <code>.vimrc</code> or <code>.config/nvim/init.vim</code> for neo Vim</p>

<p>As now we have it enabled, we should be able to use it, so here are some commands that I've been using:</p>

<table>
<thead>
<tr>
  <th>Command</th>
  <th>What does it do</th>
</tr>
</thead>
<tbody>
<tr>
  <td><code>z=</code></td>
  <td>It'll open another page with a numbered list of alternatives to that wrong word, you can choose one number of this list and press enter, it'll change the word for the one chosen</td>
</tr>
<tr>
  <td><code>]s</code></td>
  <td>It moves to the next misspelled word after the cursor</td>
</tr>
<tr>
  <td><code>[s</code></td>
  <td>It moves to the misspelled word before the cursor</td>
</tr>
<tr>
  <td><code>zg</code></td>
  <td>Adds the word under the cursor to the dictionary as a "correct word", so it'll not warn next time that you have that word</td>
</tr>
<tr>
  <td><code>zw</code></td>
  <td>Like <code>zg</code> but adds the word to the dictionary as a "wrong word"</td>
</tr>
<tr>
  <td><code>zug</code>/<code>zuw</code></td>
  <td>Undo what <code>zg</code> and <code>zw</code> did</td>
</tr>
</tbody>
</table>

<hr />

<h2 id="adding-spell-check-per-file-type">Adding spell check per file type</h2>

<p>If you want to enable the spell checker automatically based on the type of the file you can add the code below on your <code>.vimrc</code> or <code>.config/nvim/init.vim</code> for neo Vim.</p>

<pre><code>autocmd BufRead,BufNewFile *.md setlocal spell
</code></pre>

<p>This will enable the spell checker only for markdown files, so you won't get errors on some code stuff that it's not really wrong.</p>

<hr />

<p>If you want to take a deeper look on the spell checker, take a look on the documentation here <a href="http://vimdoc.sourceforge.net/htmldoc/spell.html">http://vimdoc.sourceforge.net/htmldoc/spell.html</a></p>

<p>Hope it helped someone, if you have suggestions or if I did something wrong here, just ping me on <a href="https://twitter.com/airtonzanon">Twitter</a></p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[Multiple paragraphs on &quot;git commit -m&quot; command]]></title>
            <link href="https://airton.dev/til/multiple-paragraphs-on-git-commit-m-command/"/>
            <updated>2020-07-07T00:00:00+00:00</updated>
            <id>https://airton.dev/til/multiple-paragraphs-on-git-commit-m-command/</id>
            <content type="html"><![CDATA[<p>Sometimes I go to commit something and I don't want to open the editor (vim in this case) to add my thoughts, that's because sometimes we're able to explain what we're doing in some couple of words.</p>

<p>But sometimes we feel that we should add something more to really explain what we're doing on that commit, as we need to keep 72 (50 preferable) characters on the title, it's not possible to leave that on the commit title, and sometimes we shouldn't, as it isn't on the context of the title.</p>

<p>So I go and open vim, even if It's "a simple commit", because I need to add more paragraphs to explain my changes.</p>

<p>The thing is, I was going around Twitter and I saw a tweet from <a href="https://twitter.com/stefanjudis">@stefanjudis</a> saying that we can use multiple <em>"-m"</em> when doing a <code>git commit</code></p>

<p>So next time that you want to do a commit on the command line, and not open a editor, you can do something like:</p>

<pre><code>$ git commit -m "This is the title" -m "This is the second paragraph"
</code></pre>

<p>Another way, that I already knew but I keep forgetting it, is leaving the quote open:</p>

<pre><code>$ git commit -m "This is a title
$ dquote&gt;
$ dquote&gt;This is the second paragraph
$ dquote&gt;
$ dquote&gt;This is the third paragraph"
</code></pre>

<p>Either way, thanks for <a href="https://twitter.com/stefanjudis">@stefanjudis</a> for raising up this, if you want to check this TIL post click <a href="https://www.stefanjudis.com/today-i-learned/git-commit-accepts-several-message-flags-m-to-allow-multiline-commits/">here</a>.</p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[Named Constructor in Python]]></title>
            <link href="https://airton.dev/til/named-constructor-in-python/"/>
            <updated>2020-07-01T00:00:00+00:00</updated>
            <id>https://airton.dev/til/named-constructor-in-python/</id>
            <content type="html"><![CDATA[<p>Sometime ago I had a need of creating a named constructor in Python, I looked up on some stuff and I did something like this:</p>

<pre><code>class NamedConstructor:
    def __init__(self, name: str, age: int):
        self.name = name
        self.age = age

    def create_person_from_dict(person_data: dict):
        return NamedConstructor(
            name = person_data['name'],
            age = person_data['age']
        )

test = NamedConstructor.create_person_from_dict({'name': 'Airton', 'age': 24})

print(test.name)
## output: Airton
</code></pre>

<p>As I'm a noob Pythonist I accepted this solution, because this is pretty much what we do in PHP, as we can't create multiple constructors or multiple methods with same name and different signatures.</p>

<p>Something that I didn't know in the time is that Python has a decorator called <code>@classmethod</code>, this, instead of accepting the argument <code>self</code> - that points to the object instance - on the method, accepts <code>cls</code> that points to the class.</p>

<p>Knowing that, we can rewrite this class as:</p>

<pre><code>class NamedConstructor:
    def __init__(self, name: str, age: int):
        self.name = name
        self.age = age

    @classmethod
    def create_person_from_dict(cls, person_data: dict):
        return cls(
            name = person_data['name'],
            age = person_data['age']
        )

test = NamedConstructor.create_person_from_dict({'name': 'Airton', 'age': 24})

print(test.name)
## output: Airton
</code></pre>

<p>There are some other usages for the <code>@classmethod</code>, but used this decorator for it.</p>

<p>If you know some better way for do that or wants to talk more about this, send me a DM on <a href="https://twitter.com/airtonzanon">twitter</a></p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[VIM - Creating multiple files at once]]></title>
            <link href="https://airton.dev/til/vim-creating-multiple-files-at-once/"/>
            <updated>2020-06-30T00:00:00+00:00</updated>
            <id>https://airton.dev/til/vim-creating-multiple-files-at-once/</id>
            <content type="html"><![CDATA[<p>It was really fun discovering this, I was watching @beginbot's live on twitch.tv and he got to read the vim documentation.</p>

<p>As I already knew, creating a file with vim is kinda easy, like: <code>vim file.txt</code></p>

<p>But something that I didn't know it's that on <strong>vim</strong> we can create multiple files at once, so we can do it:</p>

<pre><code>vim file1.txt file2.txt file3.txt
</code></pre>

<p>Inside vim we only need to press <strong>esc</strong> and write: <code>:next</code>, doing that, you can take a look on the bottom that the name of the file will change, so for each <code>:next</code> that you do, it will go to the next file.</p>
]]></content>
        </entry>
            <entry>
            <title type="html"><![CDATA[Creating a file in VIM&#039;s explorer (Netrw)]]></title>
            <link href="https://airton.dev/til/creating-a-file-in-vims-explorer-netrw/"/>
            <updated>2020-06-11T00:00:00+00:00</updated>
            <id>https://airton.dev/til/creating-a-file-in-vims-explorer-netrw/</id>
            <content type="html"><![CDATA[<p>Every time that I'll browse my files when using <strong>VIM</strong> I use <code>:e .</code> it'll open the default explorer of VIM: Netrw</p>

<p>One thing that I was struggling was creating new files there, because I always needed to put VIM in background, then create the file, and then editing it on VIM. That was making me madness.</p>

<p>So I started searching and some TIL articles or even the documentation says, use <code>%</code> when on Netrw and it'll ask the filename. Noob as I'm I was trying to do <code>:%</code>.</p>

<p>But it's just pressing the character <code>%</code>, so: <code>shift + 5</code> (at least in my keyboard hehe).</p>

<p>I hope it also helps some people that doesn't pay attention as myself.</p>
]]></content>
        </entry>
    </feed>