<?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: Haku B.</title>
    <description>The latest articles on DEV Community by Haku B. (@byhaku).</description>
    <link>https://dev.to/byhaku</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%2F388412%2Fa8fc4f08-3fd3-4c9e-8650-f0b95b980a77.jpg</url>
      <title>DEV Community: Haku B.</title>
      <link>https://dev.to/byhaku</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/byhaku"/>
    <language>en</language>
    <item>
      <title>NPM notes</title>
      <dc:creator>Haku B.</dc:creator>
      <pubDate>Mon, 15 Feb 2021 02:17:54 +0000</pubDate>
      <link>https://dev.to/byhaku/npm-notes-1m5h</link>
      <guid>https://dev.to/byhaku/npm-notes-1m5h</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;~version&lt;/code&gt; &lt;strong&gt;“Approximately equivalent to version”&lt;/strong&gt;, will update you to all future &lt;strong&gt;patch&lt;/strong&gt; versions, without incrementing the &lt;strong&gt;minor&lt;/strong&gt; version. &lt;code&gt;~1.2.3&lt;/code&gt; will use releases from 1.2.3 to &amp;lt;1.3.0.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;^version&lt;/code&gt; &lt;strong&gt;“Compatible with version”&lt;/strong&gt;, will update you to all future &lt;strong&gt;minor/patch&lt;/strong&gt; versions, without incrementing the &lt;strong&gt;major&lt;/strong&gt; version. &lt;code&gt;^2.3.4&lt;/code&gt; will use releases from 2.3.4 to &amp;lt;3.0.0.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Refs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.npmjs.com/cli/v7/configuring-npm/package-json"&gt;https://docs.npmjs.com/cli/v7/configuring-npm/package-json&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.npmjs.com/misc/semver"&gt;https://docs.npmjs.com/misc/semver&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/22343224/whats-the-difference-between-tilde-and-caret-in-package-json"&gt;https://stackoverflow.com/questions/22343224/whats-the-difference-between-tilde-and-caret-in-package-json&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>SQL Learning notes</title>
      <dc:creator>Haku B.</dc:creator>
      <pubDate>Thu, 28 Jan 2021 03:10:35 +0000</pubDate>
      <link>https://dev.to/byhaku/sql-learning-notes-ad0</link>
      <guid>https://dev.to/byhaku/sql-learning-notes-ad0</guid>
      <description>&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.tables&lt;/code&gt;, &lt;code&gt;sys.columns&lt;/code&gt;, add new column to a table after checking if it's existing cross 2 tables
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
        &lt;span class="k"&gt;FROM&lt;/span&gt;   &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tables&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;JOIN&lt;/span&gt;   &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
               &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;object_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;object_id&lt;/span&gt;
        &lt;span class="k"&gt;WHERE&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;].[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Table1'&lt;/span&gt;
        &lt;span class="k"&gt;AND&lt;/span&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;].[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Column1'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;BEGIN&lt;/span&gt;
    &lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;Table1&lt;/span&gt;
    &lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;Column1&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;

&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;Table1&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="n"&gt;Column1&lt;/span&gt; &lt;span class="n"&gt;nvarchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sys.tables&lt;/code&gt; returns a row for each user table in SQL Server.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sys.columns&lt;/code&gt; returns a row for each column of an object that has columns, such as views or tables. (Object types that have columns: Table-valued assembly functions, Inline table-valued SQL functions, Internal tables, System tables, Table-valued SQL functions, User tables, Views.)&lt;br&gt;
&lt;code&gt;object_id&lt;/code&gt; - int - ID of the object to which this column belongs.&lt;/p&gt;

&lt;p&gt;More reading: &lt;a href="https://www.sisense.com/blog/sql-cheat-sheet-retrieving-column-description-sql-server/"&gt;https://www.sisense.com/blog/sql-cheat-sheet-retrieving-column-description-sql-server/&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;COALESCE&lt;/code&gt;
Evaluates the arguments in order and returns the current value of the first expression that initially doesn't evaluate to &lt;code&gt;NULL&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'third_value'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'fourth_value'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;-- Above query returns the 3rd value because it is the first value isn't null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;SQL Operators &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arithmetic operators: &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;
&lt;/li&gt;
&lt;li&gt;Bitwise operators: &lt;code&gt;&amp;amp;&lt;/code&gt; (Bitwise AND), &lt;code&gt;|&lt;/code&gt; (Bitwise OR), &lt;code&gt;^&lt;/code&gt; (Bitwise exclusive OR)&lt;/li&gt;
&lt;li&gt;Comparison operators: &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;strong&gt;&lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; (Not equal to)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;[]&lt;/code&gt; : used to delimit identifiers.&lt;br&gt;&lt;br&gt;
From &lt;a href="https://msdn.microsoft.com/en-us/library/ms175874.aspx"&gt;MSDN&lt;/a&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;h4&gt;
  
  
  Delimited identifiers
&lt;/h4&gt;

&lt;p&gt;Are enclosed in double quotation marks (") or brackets ([ ]). Identifiers that comply with the rules for the format of identifiers may or may not be delimited.&lt;/p&gt;


&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;TableX&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;         &lt;span class="c1"&gt;--Delimiter is optional.&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;KeyCol&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;124&lt;/span&gt;  &lt;span class="c1"&gt;--Delimiter is optional.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Identifiers that do not comply with all of the rules for identifiers must be delimited in a Transact-SQL statement.&lt;/p&gt;


&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;My&lt;/span&gt; &lt;span class="k"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;      &lt;span class="c1"&gt;--Identifier contains a space and uses a reserved keyword.&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;order&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;   &lt;span class="c1"&gt;--Identifier is a reserved keyword.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GO&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;GO&lt;/code&gt; will execute the related sql commands &lt;code&gt;n&lt;/code&gt; times.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The GO command isn't a Transact-SQL statement, but a special command recognized by several MS utilities including SQL Server Management Studio code editor.&lt;/p&gt;

&lt;p&gt;The GO command is used to group SQL commands into batches which are sent to the server together. The commands included in the batch, that is, the set of commands since the last GO command or the start of the session, must be logically consistent. For example, you can't define a variable in one batch and then use it in another since the scope of the variable is limited to the batch in which it's defined.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For more information, see &lt;a href="http://msdn.microsoft.com/en-us/library/ms188037.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms188037.aspx&lt;/a&gt;.&lt;br&gt;
More reading: &lt;a href="https://stackoverflow.com/questions/2299249/what-is-the-use-of-go-in-sql-server-management-studio-transact-sql"&gt;https://stackoverflow.com/questions/2299249/what-is-the-use-of-go-in-sql-server-management-studio-transact-sql&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
    </item>
    <item>
      <title>.NET learning notes</title>
      <dc:creator>Haku B.</dc:creator>
      <pubDate>Thu, 07 Jan 2021 02:11:36 +0000</pubDate>
      <link>https://dev.to/byhaku/net-learning-notes-57lh</link>
      <guid>https://dev.to/byhaku/net-learning-notes-57lh</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TaskBase&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;TSummaryInfo&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ProcessorBase&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;TSummaryInfo&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="c1"&gt;// code &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An abstract class &lt;code&gt;TaskBase&lt;/code&gt; which declares &lt;code&gt;TSummaryInfo&lt;/code&gt; type and inherits &lt;code&gt;ProcessorBase&lt;/code&gt; class. &lt;br&gt;
&lt;code&gt;where TSummaryInfo : class&lt;/code&gt; means the &lt;code&gt;TSummaryInfo&lt;/code&gt; type needs to be a class. &lt;code&gt;new()&lt;/code&gt; means it has a parameter-less construction.&lt;/p&gt;




&lt;h1&gt;
  
  
  Lazy instantialization
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Project.Controllers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SomeController&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Controller&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// only instantialize when the instance is needed in the methods of this class&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;ISomeService&lt;/span&gt; &lt;span class="n"&gt;_someService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;ISomeService&lt;/span&gt; &lt;span class="n"&gt;SomeService&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_someService&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_someService&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SomeService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SomeRepository&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;


    &lt;span class="c1"&gt;// do not instantialize in constructor, so that the instances won't be created every time when the class is constructed, unless they are called as parameters from below method.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;someController&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;someClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SomeService&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="c1"&gt;//...code&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;Naming Convention:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;_someService&lt;/code&gt;: "back-end" variables&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SomeService&lt;/code&gt;: parameter of methods, or just the class&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>JS Edabit solution notebook</title>
      <dc:creator>Haku B.</dc:creator>
      <pubDate>Mon, 18 May 2020 06:08:06 +0000</pubDate>
      <link>https://dev.to/byhaku/js-edabit-solution-notebook-3976</link>
      <guid>https://dev.to/byhaku/js-edabit-solution-notebook-3976</guid>
      <description>&lt;p&gt;Return month long name based on number input&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function monthName(num) {
    return new Date(2000, num - 1).toLocaleString("en-us", {month: "long"});
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Return first &amp;amp; last item in an array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function firstLast(arr) {
    return [arr.shift(), arr.pop()]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  When comparing strings and characters, includes() is case-sensitive.
&lt;/h2&gt;




&lt;p&gt;Count matching char in a string (case-sensitive)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function charCount(myChar, str) {
    return [...str].filter(x =&amp;gt; x===myChar).length;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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