<?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: Daniel Mayovskiy</title>
    <description>The latest articles on DEV Community by Daniel Mayovskiy (@weirdmayo).</description>
    <link>https://dev.to/weirdmayo</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%2F92529%2F0ed4e8c9-daeb-44fe-891a-719adf75e967.jpg</url>
      <title>DEV Community: Daniel Mayovskiy</title>
      <link>https://dev.to/weirdmayo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/weirdmayo"/>
    <language>en</language>
    <item>
      <title>How to Use Your Personal Git SSH at Work</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Thu, 25 Aug 2022 01:53:31 +0000</pubDate>
      <link>https://dev.to/weirdmayo/how-to-use-your-personal-git-ssh-at-work-okj</link>
      <guid>https://dev.to/weirdmayo/how-to-use-your-personal-git-ssh-at-work-okj</guid>
      <description>&lt;h1&gt;
  
  
  Story
&lt;/h1&gt;

&lt;p&gt;Since I work from home on the company laptop, sometimes I want to make a quick commit to my personal repository, without starting up my personal computer. But Github blocked password authentication in August 2021. From now on you must either use SSH keys, or configure a PAT (Personal Access Token) from Github.&lt;/p&gt;

&lt;p&gt;I find SSH to be vastly more convenient, but my default SSH key is already taken by my workplace.&lt;/p&gt;

&lt;h1&gt;
  
  
  Problem
&lt;/h1&gt;

&lt;p&gt;When I push to my &lt;strong&gt;personal&lt;/strong&gt; git account with my &lt;strong&gt;work's&lt;/strong&gt; &lt;em&gt;(or default)&lt;/em&gt; SSH key, I get this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Wrong solutions
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Use the same SSH key for both personal and work computers. &lt;strong&gt;Do not do that.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is a security issue you do not want to deal with. Do not copy an SSH key from your home machine to your work laptop, and vice versa.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adding laptop's SSH key to your personal GitHub account.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Not recommended, because your work's SSH &lt;code&gt;.pub&lt;/code&gt; file contains your work email, and you don't want that associated with your personal GitHub account.&lt;/p&gt;

&lt;h1&gt;
  
  
  Solutions
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Configuring SSH and Git
&lt;/h2&gt;

&lt;p&gt;Create separate configuration files for SSH, and make Git use those separate SSH files.&lt;/p&gt;

&lt;p&gt;You must create two separate &lt;code&gt;.ssh/config&lt;/code&gt; files for each GitHub account you want to use. Each config file must specify a separate identity that you want SSH to use, for each account. You must &lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent" rel="noopener noreferrer"&gt;generate separate identity keys&lt;/a&gt; for your accounts beforehand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;host github.com
user git
identityfile ~/.ssh/id_ed25519 &lt;span class="c"&gt;# indentity key, without .pub ending&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, I created two separate config files: &lt;code&gt;~/.ssh/work_config&lt;/code&gt; and &lt;code&gt;~/.ssh/personal_config&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Each config has a different &lt;code&gt;identityfile&lt;/code&gt; being used.&lt;/p&gt;

&lt;h3&gt;
  
  
  the Git portion
&lt;/h3&gt;

&lt;p&gt;On your work laptop, you might prefer to have global git config to be your job's git config. And then configure your personal repositories locally (isolated to a single repository) with &lt;code&gt;git config --local&lt;/code&gt;. That's the strategy that I use.&lt;/p&gt;

&lt;p&gt;For your work/global git configuration, you can simply type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; core.sshCommand &lt;span class="s2"&gt;"ssh -F ~/.ssh/work_config"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after that, you can go to your personal repository and configure &lt;code&gt;git&lt;/code&gt; the way you'd configure it on your personal machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--local&lt;/span&gt; user.name &lt;span class="c"&gt;# your personal config&lt;/span&gt;
git config &lt;span class="nt"&gt;--local&lt;/span&gt; user.email &lt;span class="c"&gt;# that you use on your personal machine&lt;/span&gt;
git config &lt;span class="nt"&gt;--local&lt;/span&gt; core.sshCommand &lt;span class="s2"&gt;"ssh -F ~/.ssh/personal_config"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, git will use different &lt;code&gt;ssh&lt;/code&gt; commands, with different identity files for your personal and work-related projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Solution without the &lt;code&gt;core.sshCommand&lt;/code&gt; change
&lt;/h2&gt;

&lt;p&gt;As suggested by a comment, here is an alternative solution that I've read through. Very clever approach as well: &lt;br&gt;
&lt;a href="https://dev.to/jimzandueta/setup-your-ssh-configuration-file-1m9e"&gt;https://dev.to/jimzandueta/setup-your-ssh-configuration-file-1m9e&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You're welcome to ask questions in the comments, and I'll make appropriate edits.&lt;/p&gt;

</description>
      <category>git</category>
      <category>ssh</category>
    </item>
    <item>
      <title>Split keyboard is awesome!</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Fri, 13 Nov 2020 01:40:47 +0000</pubDate>
      <link>https://dev.to/weirdmayo/split-keyboard-is-awesome-3c5l</link>
      <guid>https://dev.to/weirdmayo/split-keyboard-is-awesome-3c5l</guid>
      <description>&lt;p&gt;Two weeks ago I have assembled my first split keyboard, and I am documenting my transition process here. If you want to read my initial post, here's the link:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/weirdmayo/moving-to-split-keyboard-and-new-layout-5lm"&gt;Initial post&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Transition complete?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3f7lmrhqmr1jze4t49ea.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3f7lmrhqmr1jze4t49ea.jpg" alt="Image of my current setup" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To keep my productivity at work, I would use my regular qwerty keyboard. I would use this keyboard when I didn't have to deal with any deadlines and would just go through a regular routine of &lt;a href="//colemak.academy"&gt;colemak.academy&lt;/a&gt; every time I would plug this keyboard in. Not anymore though!&lt;/p&gt;

&lt;p&gt;Now that I have learned the colemak layout and reached about 30wpm on this keyboard, I decided to just use this keyboard at work as well. I have now unplugged the qwerty keyboard until emergency's, and have dedicated myself to the split keyboard full-time.&lt;/p&gt;

&lt;h1&gt;
  
  
  What about Vim?
&lt;/h1&gt;

&lt;p&gt;This is where it gets hard. My Vim muscle memory is completely messed up and I reckon that might affect my productivity for a few days. Despite the challenge I am still committed to using this keyboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigation solution
&lt;/h3&gt;

&lt;p&gt;Vim uses hjkl for movement. I decided not to remap those keys in vim and keep them genuine, since if I did, I'd have to remap n e i and o as well, and that sucks.&lt;/p&gt;

&lt;p&gt;What I decided to do was to create a second layer in qmk and while I am holding the layer button, I can use arrows for navigation, but those arrows are at the regular hjkl location, so I get the best of both worlds: familiar Vim position and the I can use that same position to operate other apps, like scrolling in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scrolling? What about the knob?
&lt;/h2&gt;

&lt;p&gt;Yes this keyboard has a knob, and you can map it to scroll. The problem is... I broke it during installation. I held my solder next to it for too long and it seems that I have damaged the mechanism, so I will have to purchase a new knob.&lt;/p&gt;

&lt;h2&gt;
  
  
  Have you figured out the keyboard mapping?
&lt;/h2&gt;

&lt;p&gt;I am still fiddling around with where to put the special symbols, but for the most part, I have not changed the layout on this thing in a while now.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;I will be improving my Colemak typing speed and trying to rewire my brains in Vim, and I will keep you posted!&lt;/p&gt;

</description>
      <category>keyboard</category>
      <category>ergonomics</category>
      <category>colemak</category>
      <category>qwerty</category>
    </item>
    <item>
      <title>Moving to Split Keyboard AND new layout!</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Thu, 29 Oct 2020 07:38:10 +0000</pubDate>
      <link>https://dev.to/weirdmayo/moving-to-split-keyboard-and-new-layout-5lm</link>
      <guid>https://dev.to/weirdmayo/moving-to-split-keyboard-and-new-layout-5lm</guid>
      <description>&lt;p&gt;This is a series now:&lt;br&gt;
&lt;a href="https://dev.to/weirdmayo/split-keyboard-is-awesome-3c5l"&gt;this is the next post&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  As a quick backstory
&lt;/h1&gt;

&lt;p&gt;As a quick backstory, I've been touch-typing on a regular keyboard for about 7 years now (since 13), and managed to reach what most people find to be really fast speeds (120wpm). I enjoy the notion of typing on a keyboard. Typing fast and hitting keys accurately. I find it to be extremely satisfying.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why not QWERTY?
&lt;/h3&gt;

&lt;p&gt;I &lt;em&gt;never&lt;/em&gt; had a problem with QWERTY and the row-staggered (regular) keyboard layout. I had RSI once, on my left hand. That was because I was reaching for Ctrl button a lot, and that required bending my left hand backwards. Remapping Caps Lock to Ctrl fixed the issue permanently, and I never experienced any finger fatigue/RSI ever since.&lt;/p&gt;

&lt;p&gt;Now with this new keyboard, certain bigrams are harder to type: NU, EC, SW and others would have to be typed with one finger and there is no stagger that would allow you to use a different finger. I am concerned with speed to a significant extent, and typing faster on this than on row stagger while using qwerty is basically impossible.&lt;/p&gt;

&lt;p&gt;That is all to say that this project is purely &lt;strong&gt;intrinsically motivated&lt;/strong&gt; and more so as an experiment in search of something better, rather than something done out of ergonomic necessity, like a good amount of people who do &lt;br&gt;
this stuff do. &lt;/p&gt;

&lt;h1&gt;
  
  
  Split keyboard
&lt;/h1&gt;

&lt;p&gt;After some developers in the &lt;a href="https://discord.gg/mechkeys" rel="noopener noreferrer"&gt;mechanical keyboards community&lt;/a&gt; spent their time to try to convince me to assemble a split keyboard, I have decided to go all the way and assemble a split, column-staggered keyboard for myself. The keyboard I decided to go with is Lily58 Pro, because it still has the number row, has four thumb keys and supports a rotary encoder.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F91yilhqviwdfaloqyl8q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F91yilhqviwdfaloqyl8q.jpg" alt="Lily58 pair" width="800" height="600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F32xbvlkmya6vqa1jeele.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F32xbvlkmya6vqa1jeele.jpg" alt="Lily58 keycap profile closeup" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Concerns?
&lt;/h1&gt;

&lt;p&gt;Yes indeed I have quite a bit of concerns, about whether switching to this will indefinitely hurt my productivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting unused from qwerty
&lt;/h3&gt;

&lt;p&gt;That's one of the things that, in my opinion, can be avoided. First of all, because I am learning Colemak exclusively on my Lily58, my performance on the row stagger keyboard didn't suffer a single bit, although it's only been 5 days of training, so it might change later. Also I am still actively training my QWERTY speed on my regular keyboard, for this specific reason.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vim
&lt;/h3&gt;

&lt;p&gt;Now &lt;strong&gt;this&lt;/strong&gt; is my actual concern. I am a huge proponent of Vim. I will not give it up at any price. If after 5 months of using this layout my Vim performance is going to be slow and miserable, I will have to abandon this layout and go back to my normal qwerty layout. That being said, I will still keep using the ortholinear keyboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  I will keep you posted
&lt;/h3&gt;

&lt;p&gt;I am quite excited to log this process from my baby steps to 130 wpm on this layout, so you can follow me if you want.&lt;/p&gt;

&lt;h5&gt;
  
  
  This article was typed entirely on the Colemak layout on the Lily58 keyboard :)
&lt;/h5&gt;

</description>
      <category>keyboard</category>
      <category>colemak</category>
      <category>ergonomics</category>
      <category>qwerty</category>
    </item>
    <item>
      <title>Does Fullstack developer experience count?</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Wed, 06 Nov 2019 00:21:08 +0000</pubDate>
      <link>https://dev.to/weirdmayo/does-full-stack-developer-experience-count-20jj</link>
      <guid>https://dev.to/weirdmayo/does-full-stack-developer-experience-count-20jj</guid>
      <description>&lt;p&gt;I can provide more context in &lt;code&gt;EDIT&lt;/code&gt; if requested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;I am currently working as a Fullstack developer in United States. I love JavaScript and creative development (interactive content, web applications), and my current stack is Laravel Php + Vue.js.&lt;/p&gt;

&lt;p&gt;I am 19 years old, been to college for 3 quarters. Dropped out after got a pretty good job for my age and experience.&lt;/p&gt;

&lt;p&gt;I want to have a successful career as a Software Engineer. Going up to a salary that could sustain a household of multiple kids on a single paycheck. Aka around $110k+ a year in WA.&lt;/p&gt;

&lt;h2&gt;
  
  
  Question
&lt;/h2&gt;

&lt;p&gt;Question is: &lt;strong&gt;Does fullstack developer experience count as valid Software Engineer experience&lt;/strong&gt; that can help me in getting a higher-paying job with the years of experience that I am getting.&lt;/p&gt;

&lt;p&gt;And if it doesn't, should I drop the job after a major project is complete, and get a loan, a degree, and then get a Software Engineer and build a career from somewhat of a clear sheet?&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Local Aliases in Bash</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Wed, 25 Sep 2019 19:58:40 +0000</pubDate>
      <link>https://dev.to/weirdmayo/local-aliases-in-bash-3ej9</link>
      <guid>https://dev.to/weirdmayo/local-aliases-in-bash-3ej9</guid>
      <description>&lt;p&gt;&lt;strong&gt;Quick story&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Recently, I started learning Rust. So I was running a lot of &lt;code&gt;cargo check&lt;/code&gt; and &lt;code&gt;cargo run&lt;/code&gt; and &lt;code&gt;cargo build&lt;/code&gt; commands. I wanted to shorten that to &lt;code&gt;ccheck&lt;/code&gt; and &lt;code&gt;crun&lt;/code&gt; and stuff like that.&lt;/p&gt;

&lt;p&gt;Except, commands like that already exist on my machine. I never need them in the Rust project, so I would like to reassing those commands to just these little aliases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this article exists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's no way to setup a "local alias" command. If alias is defined in my bash profile, it will be used everywhere. So I created a little hack that works for me, and will probably work for you&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, the way to do that, is through Bash functions. In the bash function we can check in which directory we currently are, and take action accordingly.&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="k"&gt;function &lt;/span&gt;ccheck&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$PWD&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"/home/daniel/rust-projects/"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="c"&gt;# if you are in this folder, execute this command&lt;/span&gt;
        cargo check&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c"&gt;# return stops the function, and it won't reach the ccheck call later in this function&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;fi
    &lt;/span&gt;ccheck&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the problem that you face immediately, is that the later &lt;code&gt;ccheck&lt;/code&gt;, the "actual one", is going to Halt your bash session, because it will be stuck in recursion.&lt;/p&gt;

&lt;p&gt;To stop that from happening you just have to prepend &lt;code&gt;command&lt;/code&gt; before the command that you want to execute. That way, you won't call the function, but the actual command.&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="k"&gt;function &lt;/span&gt;ccheck&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="c"&gt;# stuff...&lt;/span&gt;

    &lt;span class="nb"&gt;command &lt;/span&gt;ccheck&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now what?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A better way of comparing a directory is against a regex. But since our little directory is not that complicated (or &lt;code&gt;cargo&lt;/code&gt; runs anywhere in the project, hehe), we can replace regex with simple wildcard comparison&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="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$PWD&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="s2"&gt;"rust-projects"&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="c"&gt;# ...&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will make this alias work anywhere within that directory.&lt;/p&gt;

&lt;p&gt;Hope that helped you :)&lt;/p&gt;

</description>
      <category>bash</category>
      <category>linux</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Multiple functions for single eventListener</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Mon, 08 Jul 2019 22:57:39 +0000</pubDate>
      <link>https://dev.to/weirdmayo/multiple-functions-for-single-eventlistener-1ckg</link>
      <guid>https://dev.to/weirdmayo/multiple-functions-for-single-eventlistener-1ckg</guid>
      <description>&lt;p&gt;So, recently I ran into a challenge of managing my &lt;code&gt;keydown&lt;/code&gt; listening functions. One of my components needs a straight connection/hook with the original &lt;code&gt;window.keyDown&lt;/code&gt; event. &lt;/p&gt;

&lt;p&gt;At first I had something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//... other component stuff&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;firstUpdate&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keydown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;//... function stuff&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will only bind the function once the module has been updated once (one from render, Mithril.js).&lt;/p&gt;

&lt;p&gt;The problem is that as soon as this component appears later, without reloading the page, it will bind the function again, and it will either rewrite, or fire both.&lt;/p&gt;

&lt;p&gt;so I found a better solution to this, by putting all the &lt;code&gt;window.keyDown&lt;/code&gt; events into one module, and then exporting the &lt;code&gt;array&lt;/code&gt; of functions that have to be fired.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// initiating the array&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;keyDown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keydown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="nx"&gt;keyDown&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;func&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;keyDown&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function above will just run the functions in the array, and pass the event data into them. At the end of the file, i just export the array to be modified later by my components.&lt;/p&gt;

&lt;p&gt;Example Mithril.js component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;keyDown&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;WindowEvents.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;oninit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyDownFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="c1"&gt;// add function to the array&lt;/span&gt;
        &lt;span class="nx"&gt;keyDown&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyDownFunction&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;onremove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="c1"&gt;// remove function from the array&lt;/span&gt;
        &lt;span class="nx"&gt;keyDown&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;keyDown&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyDownFunction&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see I can remove the function from the array, to not make it fire twice when I have rendered the component again later.&lt;/p&gt;

&lt;p&gt;It's not a good idea to use window events if you have an MVC library, just use their events. But in certain cases you have to access the window, and this was a solution for me.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>babel</category>
      <category>webpack</category>
      <category>mithriljs</category>
    </item>
    <item>
      <title>Bash Script for meme lords of Linux</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Sun, 02 Dec 2018 21:08:21 +0000</pubDate>
      <link>https://dev.to/weirdmayo/bash-script-for-meme-lords-of-linux-5c6</link>
      <guid>https://dev.to/weirdmayo/bash-script-for-meme-lords-of-linux-5c6</guid>
      <description>&lt;p&gt;Maybe I am slightly late to the meme, but its still worth a laugh here and there. Its a "commit sudoku" meme. Sudoku, as a misspell of Sepuku (hara-kiri, suicide, etc.). So I wrote a little script for meme and someone to type more but have a little BATMN* while doing that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;commit&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"sepuku"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;logout
    &lt;/span&gt;&lt;span class="k"&gt;fi
    if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"sudoku"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;suspend
    &lt;/span&gt;&lt;span class="k"&gt;fi
    if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"lifent"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;shutdown &lt;span class="nt"&gt;-P&lt;/span&gt; now
    &lt;span class="k"&gt;fi
    fi&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"tensei"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;shutdown &lt;span class="nt"&gt;-r&lt;/span&gt; now
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now you can logout of your SSH like a boss &lt;code&gt;commit sepuku&lt;/code&gt;&lt;br&gt;
or shut down your computer &lt;code&gt;commit lifent&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you're new to Linux/bash, to use this code, you have to paste the function I wrote above to the end of your &lt;code&gt;~/.bashrc&lt;/code&gt; file. And activate the change to the rc file just do &lt;code&gt;source ~/.bashrc&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BATMN - Blow Air Through My Nose, since most of the time people do exactly this, not laughing out loud.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Update
&lt;/h2&gt;

&lt;p&gt;You can install this script to your &lt;code&gt;~/.bashrc&lt;/code&gt; by copy-pasting this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://gitlab.com/snippets/1787198/raw | &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>linux</category>
      <category>bash</category>
      <category>script</category>
      <category>meme</category>
    </item>
    <item>
      <title>Anchor links in Mithril.js</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Tue, 27 Nov 2018 19:21:54 +0000</pubDate>
      <link>https://dev.to/weirdmayo/anchor-links-in-mithriljs-277l</link>
      <guid>https://dev.to/weirdmayo/anchor-links-in-mithriljs-277l</guid>
      <description>

&lt;p&gt;Recently, during the process of making a small website for my friend, I decided to use Mithril.js MVC framework, since it is my favorite and I got to know it by heart. Give me time, and I can do basically everything with that framework at this point. But, recently, I encountered the issue with it's routing technique implementation. I can't link to anchors and make my page teleport/scroll to them, but I fixed it.&lt;/p&gt;

&lt;h3&gt;
  
  
  How the problem appeared/works.
&lt;/h3&gt;

&lt;p&gt;When you are using links to route to different pages of your app, you hard-wire a component to each route: &lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;rootElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"/home"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HomeComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"/settings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SettingsComponent&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can specify your own routing strategy, but by default the end result with make your url look like this: &lt;code&gt;https://website.com/#!/home&lt;/code&gt;. The hashbang in the beginning isolates to routes exclusively to a single Mithril applicatoin, in case your website will have more than one Mithril application/use-case of some sort.&lt;/p&gt;

&lt;p&gt;Mithril knows that you don't want to bother to write out every &lt;code&gt;a&lt;/code&gt; link in your application to &lt;code&gt;/#!/whatever&lt;/code&gt; link, so they allow you to do the &lt;code&gt;&amp;lt;a href='/home'&amp;gt;&lt;/code&gt; and Mithril will take care of safely routing a user to the route you specify if you pass the &lt;code&gt;oncreate&lt;/code&gt; method with a &lt;code&gt;m.route.link&lt;/code&gt; function to be called.&lt;/p&gt;

&lt;p&gt;The code for the &lt;code&gt;a&lt;/code&gt; element will look something like this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"a[href='/home']"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;oncreate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;link&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="s2"&gt;"Home"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  The problem itself
&lt;/h3&gt;

&lt;p&gt;Now, with that being said, if you have not hardwired a component to a certain route, it will just omit the route call and keep you on the same page you were or teleport you to the default route (the one specified as a second argument in the &lt;code&gt;m.route&lt;/code&gt; call).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do you set up anchors then?&lt;br&gt;
With &lt;em&gt;route parameters&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That looks something like this: &lt;code&gt;https://website.com/home?filter=all&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To pass a route parameter, you have to call the &lt;code&gt;m.route.set()&lt;/code&gt; function, not do it through the &lt;code&gt;a[href]&lt;/code&gt; link. An example of such function would be:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//button component&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;view&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"button"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;//your parameters here&lt;/span&gt;
                &lt;span class="s2"&gt;"filter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="s2"&gt;"Go Home"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//app component&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;view&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"div.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So, as you might have guessed already, you can pass the anchor name into a route parameter.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* ...button component script... */&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"contact-me"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// a for Anchor&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;   
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But just passing the anchor name won't do anything. You have to actually scroll to the anchor. For that we make a function called &lt;code&gt;scrollToAnchor( anchorName )&lt;/code&gt;, which we can call during the &lt;code&gt;onclick&lt;/code&gt; event;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;scrollToAnchor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;anchorName&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="c1"&gt;//if you pass an undefined anchor it will scroll to the top of the body&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;targetEl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anchor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"a[name="&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;anchor&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s2"&gt;"]"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;scrollTop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pageYOffset&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scrollTop&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;targetEl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;targetEl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scroll&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;scrollTop&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;behavior&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"smooth"&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and now just add a function to an &lt;code&gt;onclick&lt;/code&gt; call on the button we made&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;anchor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"contact-me"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"/home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;anchor&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;scrollToAnchor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;anchor&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it. We solved it.&lt;/p&gt;

&lt;p&gt;If you want to keep the same route, but just teleport to anchor, can pass the &lt;code&gt;m.route.get()&lt;/code&gt; as a first argument of the &lt;code&gt;m.route.set&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want to be &lt;em&gt;fancy&lt;/em&gt;, you can make a Button component better with the functionality automated integrated:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;oninit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ctrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;route&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;anchorName&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anchorName&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
                    &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;anchorName&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
                    &lt;span class="nx"&gt;scrollToAnchor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;anchorName&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;view&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"button"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;onclick&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ctrl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;anchor&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attrs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;view&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"div.app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;route&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;anchor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"contact-me"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Contact Me"&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;It might seem like too much work to do to just make an anchor link work on this framework. But, frankly speaking, most of the frameworks have a similar routing strategy. Since anchor links are mostly used in blogs and tutorial posts, these are static websites that don't need MVC frameworks to be built, so MVC framework routing strategies barely ever include an anchor solution. This kind of "fix" can be implemented anywhere, not just Mithril.js&lt;/p&gt;


</description>
      <category>mithriljs</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>snippet</category>
    </item>
    <item>
      <title>I am a JavaScript's biggest fan, Ask Me Anything!</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Fri, 17 Aug 2018 06:08:41 +0000</pubDate>
      <link>https://dev.to/weirdmayo/i-am-a-javascripts-biggest-fan-ask-me-anything-cdh</link>
      <guid>https://dev.to/weirdmayo/i-am-a-javascripts-biggest-fan-ask-me-anything-cdh</guid>
      <description>&lt;p&gt;I am not an expert, but I love this language and anything that is about it. I also love doing some HTML5 Canvas experiments! Ask me anything!&lt;/p&gt;

</description>
      <category>ama</category>
    </item>
    <item>
      <title>js13kGames competition started!</title>
      <dc:creator>Daniel Mayovskiy</dc:creator>
      <pubDate>Mon, 13 Aug 2018 21:41:11 +0000</pubDate>
      <link>https://dev.to/weirdmayo/js13kgames-competition-started-50ef</link>
      <guid>https://dev.to/weirdmayo/js13kgames-competition-started-50ef</guid>
      <description>&lt;h3&gt;
  
  
  Just a little reminder :)
&lt;/h3&gt;

&lt;p&gt;There is a wonderful competition out there called &lt;a href="http://2018.js13kgames.com" rel="noopener noreferrer"&gt;js13kGames&lt;/a&gt;. The name explains its objective very clearly. You have to create a game that weighs 13kb in JS. The game has to fit the theme that the author of the competition appointed.&lt;/p&gt;

&lt;p&gt;This year's the theme is: &lt;strong&gt;Offline&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I tagged this post #beginners for a reason. It is a great opportunity to learn how to design and make a game. Their website has a wonderful "Resources" page that links to many tiny libraries and frameworks that you can use to create your game.&lt;/p&gt;

&lt;p&gt;To encourage people to participate in a competition, there are many valuable &lt;a href="http://2018.js13kgames.com/#prizes" rel="noopener noreferrer"&gt;prizes&lt;/a&gt;, like a year of GitHub subscription, CodePen Pro plans, and more!&lt;/p&gt;

&lt;p&gt;You don't have to rush! Competition ends at September 13th, so you have enough time to think, create and test your game.&lt;/p&gt;

&lt;p&gt;Good luck!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>gamedev</category>
    </item>
  </channel>
</rss>
