<?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: Ding Fan</title>
    <description>The latest articles on DEV Community by Ding Fan (@dingfan).</description>
    <link>https://dev.to/dingfan</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%2F33032%2F7a69c1ad-309e-41c4-b1bd-4f8979fc5259.png</url>
      <title>DEV Community: Ding Fan</title>
      <link>https://dev.to/dingfan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dingfan"/>
    <language>en</language>
    <item>
      <title>yarn link when develop cli project</title>
      <dc:creator>Ding Fan</dc:creator>
      <pubDate>Mon, 25 Oct 2021 08:41:57 +0000</pubDate>
      <link>https://dev.to/dingfan/yarn-link-when-develop-cli-project-22a2</link>
      <guid>https://dev.to/dingfan/yarn-link-when-develop-cli-project-22a2</guid>
      <description>&lt;p&gt;It's difficult to make &lt;code&gt;yarn link&lt;/code&gt; work as intended when developing a command line project. The easiest way is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yarn link&lt;/code&gt; in your cli project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;assume your cli project is &lt;code&gt;cli-project&lt;/code&gt;, assume the name is cliProject&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;# in cli-project&lt;/span&gt;
yarn &lt;span class="nb"&gt;link&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;create a demo project and init with yarn
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;demo-project
&lt;span class="nb"&gt;cd &lt;/span&gt;demo-project
yarn init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;add your cli project as dependency in &lt;code&gt;package.json&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;yarn link cliProject&lt;/code&gt; in &lt;code&gt;demo-project&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# in demo-project&lt;/span&gt;
yarn &lt;span class="nb"&gt;link &lt;/span&gt;cliProject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now you can use &lt;code&gt;yarn cliProject&lt;/code&gt; here. In my situation, I would&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;# in demo-project&lt;/span&gt;
yarn cliProject &lt;span class="nt"&gt;--version&lt;/span&gt; &lt;span class="c"&gt;# to check if yarn link succeeded&lt;/span&gt;
yarn cliProject new haha-project &lt;span class="c"&gt;# to test my new command&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>yarn</category>
      <category>cli</category>
    </item>
    <item>
      <title>Thoughts on solving basic algorithm problems</title>
      <dc:creator>Ding Fan</dc:creator>
      <pubDate>Tue, 17 Aug 2021 20:41:55 +0000</pubDate>
      <link>https://dev.to/dingfan/thoughts-on-solving-basic-algorithm-problems-123h</link>
      <guid>https://dev.to/dingfan/thoughts-on-solving-basic-algorithm-problems-123h</guid>
      <description>&lt;p&gt;I relized that while solving basic algorithm problems like &lt;br&gt;
&lt;a href="https://www.hackerrank.com/challenges/birthday-cake-candles/problem"&gt;https://www.hackerrank.com/challenges/birthday-cake-candles/problem&lt;/a&gt;&lt;br&gt;
I should use basic logic/process like for/while/recursion. It's helpful to analyze my solution in view of complexity.&lt;/p&gt;

&lt;p&gt;The last time I solving problems in an interview, I carelessly use built-in methods like map/sort, I was used to the habit of writing business code, "get things done whatever it takes, optimize later". Which left a bad impression to the interviewer, he might think that I'm suck at handling complixity.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Vim Tips</title>
      <dc:creator>Ding Fan</dc:creator>
      <pubDate>Tue, 17 Aug 2021 04:21:00 +0000</pubDate>
      <link>https://dev.to/dingfan/vim-tips-1ifj</link>
      <guid>https://dev.to/dingfan/vim-tips-1ifj</guid>
      <description>&lt;p&gt;If you know nothing about vim, you can also read this and feel the power.&lt;/p&gt;

&lt;p&gt;Remember, there is a tutor at your service anytime in your terminal. Just summon the tutor with &lt;code&gt;vimtutor&lt;/code&gt; . What? You haven't install vim? Never mind.&lt;/p&gt;

&lt;p&gt;The first thing you need to know about vim is &lt;strong&gt;HOW TO QUIT&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  quit
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;:q!&lt;/code&gt;&lt;br&gt;
quit a vim editor &lt;strong&gt;without saving&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are using VSCode extension Vim, you don't need to "quit" ;)&lt;/p&gt;




&lt;p&gt;&lt;code&gt;aCharacter&lt;/code&gt; should be replaced with character you want&lt;br&gt;
&lt;code&gt;aString&lt;/code&gt; should be replaced with string you want&lt;/p&gt;

&lt;h3&gt;
  
  
  motion
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;j&lt;/code&gt; / &lt;code&gt;k&lt;/code&gt; / &lt;code&gt;h&lt;/code&gt; / &lt;code&gt;l&lt;/code&gt;&lt;br&gt;
down, up, left, right&lt;br&gt;
I think &lt;code&gt;j&lt;/code&gt; is down because usually we read a file from top to bottom&lt;br&gt;
so we can press &lt;code&gt;j&lt;/code&gt; with index finger&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gg&lt;/code&gt; / &lt;code&gt;G&lt;/code&gt;&lt;br&gt;
move to start / end of this file&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0&lt;/code&gt; / &lt;code&gt;$&lt;/code&gt;&lt;br&gt;
move to start / end of this line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;^&lt;/code&gt;&lt;br&gt;
move to first character of this line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl + o&lt;/code&gt; / &lt;code&gt;ctrl + i&lt;/code&gt;&lt;br&gt;
move cursor to previous / next position&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#&lt;/code&gt; / &lt;code&gt;*&lt;/code&gt;&lt;br&gt;
move cursor to previous / next occurrence of current word under cursor&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl + w&lt;/code&gt;&lt;br&gt;
switch between panels&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl + b&lt;/code&gt; / &lt;code&gt;ctrl + f&lt;/code&gt;&lt;br&gt;
move backward / forward a page&lt;br&gt;
In VSCode: If you check fold fix, this might not work&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl + u&lt;/code&gt; / &lt;code&gt;ctrl + d&lt;/code&gt;&lt;br&gt;
move up / down half page&lt;br&gt;
In VSCode: If you check fold fix, this might not work&lt;/p&gt;

&lt;h3&gt;
  
  
  editing
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ciw&lt;/code&gt;&lt;br&gt;
change in word&lt;/p&gt;

&lt;p&gt;&lt;code&gt;diw&lt;/code&gt;&lt;br&gt;
delete in word&lt;/p&gt;

&lt;p&gt;&lt;code&gt;d&lt;/code&gt;/ &lt;code&gt;c&lt;/code&gt; / &lt;code&gt;y&lt;/code&gt; + &lt;code&gt;i&lt;/code&gt; + &lt;code&gt;({["'&lt;/code&gt;&lt;br&gt;
delete / change / yank in &lt;code&gt;()&lt;/code&gt; &lt;code&gt;{}&lt;/code&gt; &lt;code&gt;[]&lt;/code&gt; &lt;code&gt;""&lt;/code&gt; &lt;code&gt;''&lt;/code&gt; and etc&lt;br&gt;
you will love this&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dt aCharacter&lt;/code&gt;&lt;br&gt;
delete to aCharacter&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; / &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;&lt;br&gt;
increase / decrease indentation&lt;/p&gt;

&lt;p&gt;&lt;code&gt;A&lt;/code&gt;&lt;br&gt;
append to the end of this line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;I&lt;/code&gt;&lt;br&gt;
insert at the start of this line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;J&lt;/code&gt;&lt;br&gt;
join current line with next line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;r + enter&lt;/code&gt;&lt;br&gt;
replace character under cursor with enter&lt;/p&gt;

&lt;p&gt;&lt;code&gt;D&lt;/code&gt;&lt;br&gt;
delete to the end of this line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dd&lt;/code&gt;&lt;br&gt;
delete this line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;~&lt;/code&gt;&lt;br&gt;
toggle letter case&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.&lt;/code&gt;&lt;br&gt;
repeat last text change&lt;/p&gt;

&lt;p&gt;&lt;code&gt;u&lt;/code&gt; / &lt;code&gt;ctrl + r&lt;/code&gt;&lt;br&gt;
undo / redo&lt;br&gt;
In VSCode: this might be unreliable, enter insert mode and use &lt;code&gt;ctrl + z&lt;/code&gt; for the rescue&lt;/p&gt;

&lt;h3&gt;
  
  
  function
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;za&lt;/code&gt;&lt;br&gt;
toggle folding&lt;br&gt;
In VSCode: If you ran into trouble with motion, &lt;code&gt;ctrl + ,&lt;/code&gt; open settings, search &lt;code&gt;vim fold&lt;/code&gt; , check fold fix.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:%s/foo/bar/g&lt;/code&gt;&lt;br&gt;
&lt;code&gt;%&lt;/code&gt; in all lines &lt;code&gt;s&lt;/code&gt; substitute foo with bar &lt;code&gt;g&lt;/code&gt; every occurrence in corresponding line&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/ aString&lt;/code&gt;&lt;br&gt;
search aString&lt;br&gt;
press &lt;code&gt;enter&lt;/code&gt; move cursor to the occurrence of aString&lt;br&gt;
press &lt;code&gt;n&lt;/code&gt; move cursor to next occurrence of aString&lt;br&gt;
press &lt;code&gt;N&lt;/code&gt; move cursor to previous occurrence of aString&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl + ,&lt;/code&gt; open settings, search &lt;code&gt;vim clip&lt;/code&gt; , check use system clipboard to use system clipboard&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl + ,&lt;/code&gt; open settings, search &lt;code&gt;vim easy&lt;/code&gt; , check enable easymotion plugin, now you can use &lt;code&gt;\\&lt;/code&gt; with &lt;code&gt;hjkl&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>An interesting JS question</title>
      <dc:creator>Ding Fan</dc:creator>
      <pubDate>Wed, 11 Aug 2021 19:54:43 +0000</pubDate>
      <link>https://dev.to/dingfan/an-interesting-js-question-k6g</link>
      <guid>https://dev.to/dingfan/an-interesting-js-question-k6g</guid>
      <description>&lt;p&gt;You are refactoring a function &lt;code&gt;renderView&lt;/code&gt; which takes an item as parameter. In &lt;code&gt;renderView&lt;/code&gt; there is a &lt;code&gt;setState&lt;/code&gt; function which will trigger a render process.&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;renderView&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&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="c1"&gt;// some logic play with item&lt;/span&gt;
    &lt;span class="nx"&gt;setState&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;Currently, function &lt;code&gt;renderView&lt;/code&gt; was called too many times in a business action, thus &lt;code&gt;setState&lt;/code&gt; was triggered again and again. You want to reduce the trigger counts to improve the performance. You are trying to make function &lt;code&gt;renderView&lt;/code&gt; takes an array of items, so you can call &lt;code&gt;setState&lt;/code&gt; only once after deal with all the objects.&lt;/p&gt;

&lt;p&gt;After some attempts, you found that the &lt;code&gt;renderView&lt;/code&gt; was appeared every where in the code base, it's error-prone to change the parameter of &lt;code&gt;renderView&lt;/code&gt; and every logic called it, you shouldn't touch those legacy code and of course you will never want to do it. &lt;/p&gt;

&lt;p&gt;You decide to hack &lt;code&gt;renderView&lt;/code&gt; to make it trigger only once while called several times in a row. But how?&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>question</category>
    </item>
  </channel>
</rss>
