<?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: YC Yap</title>
    <description>The latest articles on DEV Community by YC Yap (@yowchun93).</description>
    <link>https://dev.to/yowchun93</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%2F303843%2F404cd14d-e694-4ceb-b6d7-c9471d0b70dc.jpeg</url>
      <title>DEV Community: YC Yap</title>
      <link>https://dev.to/yowchun93</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yowchun93"/>
    <language>en</language>
    <item>
      <title>Testing concerns in rails</title>
      <dc:creator>YC Yap</dc:creator>
      <pubDate>Tue, 15 Sep 2020 00:56:47 +0000</pubDate>
      <link>https://dev.to/yowchun93/testing-concerns-in-rails-91i</link>
      <guid>https://dev.to/yowchun93/testing-concerns-in-rails-91i</guid>
      <description>&lt;p&gt;Rails's ActiveSupport::Concern can be a useful place to put code that needs to be shared across classes. It is also a way to implement multiple inheritance.&lt;/p&gt;

&lt;p&gt;When it comes to testing a concern, we want to be testing the behaviour instead of the class which implements the concern, as it can be shared among multiple classes.&lt;/p&gt;

&lt;p&gt;One of my preferred way to test a concern is to use a dummy class which inherits from ActiveRecord,it gives me confidence that i am testing against my actual ActiveRecord models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Personable&lt;/span&gt;
  &lt;span class="kp"&gt;extend&lt;/span&gt; &lt;span class="no"&gt;ActiveSupport&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Concern&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;full_name&lt;/span&gt;
    &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'rails_helper'&lt;/span&gt;

&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Personable&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s1"&gt;'has a full name'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DummyPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;first_name: &lt;/span&gt;&lt;span class="s1"&gt;'yc'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;last_name: &lt;/span&gt;&lt;span class="s1"&gt;'yap'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;full_name&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;eq&lt;/span&gt; &lt;span class="s1"&gt;'yc yap'&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DummyPerson&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;table_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'users'&lt;/span&gt;

  &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;Personable&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>rails</category>
      <category>testing</category>
    </item>
    <item>
      <title>[TIL] Typescript index signatures</title>
      <dc:creator>YC Yap</dc:creator>
      <pubDate>Thu, 09 Apr 2020 01:46:04 +0000</pubDate>
      <link>https://dev.to/yowchun93/til-typescript-dynamic-keys-2703</link>
      <guid>https://dev.to/yowchun93/til-typescript-dynamic-keys-2703</guid>
      <description>&lt;p&gt;I have recently encountered a problem while porting my toy react application from Javascript to Typescript, this toy-application , fetches all the popular repos from Github and displays them on the page. &lt;/p&gt;

&lt;p&gt;The object looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;repos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setRepos&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&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="p"&gt;{&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;All&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ruby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Javascript: object
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Problem arises when you try to access the repos object, Typescript compiler throws a type mismatch error. ( Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;repos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;selectedLanguage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To solve this, i needed to define an interface in which any string can be as index for the object, it looks something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Repos&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Use the interface as the generic type for setState&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;repos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setRepos&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Repos&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And the problem goes away&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;repos&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;selectedLanguage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
    </item>
    <item>
      <title>[TIL]  Debugging external gem in Ruby </title>
      <dc:creator>YC Yap</dc:creator>
      <pubDate>Tue, 04 Feb 2020 09:12:31 +0000</pubDate>
      <link>https://dev.to/postco/til-debugging-external-gem-in-ruby-742</link>
      <guid>https://dev.to/postco/til-debugging-external-gem-in-ruby-742</guid>
      <description>&lt;p&gt;Sometimes there comes a time where an external gem that you installed is not behaving as expected. It was not until a week ago that i learned from my colleague that you can actually open the gems to inspect the code inside the gem and debugging it using a debugger. &lt;/p&gt;

&lt;p&gt;Firstly, you can open the gem by running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt; &lt;span class="n"&gt;countries&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Identify the part of the code which you wish to debug. For example i would like to understand why a method in the  gem 'countries' is not returning values as expected. &lt;/p&gt;

&lt;p&gt;Start inserting calls to debugger in places you expect it to call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'byebug'&lt;/span&gt;

&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;ISO3166&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Country&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;country_data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;byebug&lt;/span&gt;
      &lt;span class="vi"&gt;@country_data_or_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;country_data&lt;/span&gt;
      &lt;span class="n"&gt;reload&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using debugger allows you to better understand the code execution, so that variables which are causing the unexpected behaviours during the execution call be be inspected.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Running a book club in PostCo </title>
      <dc:creator>YC Yap</dc:creator>
      <pubDate>Mon, 30 Dec 2019 06:34:52 +0000</pubDate>
      <link>https://dev.to/postco/running-a-book-club-in-postco-1dbp</link>
      <guid>https://dev.to/postco/running-a-book-club-in-postco-1dbp</guid>
      <description>&lt;p&gt;This article will be about our learnings running a tech book club in PostCo for the past 3 months. &lt;/p&gt;

&lt;p&gt;Our motivation&lt;br&gt;
We want to try to cultivate a strong learning culture in PostCo, book clubs are a fast way to encourage cross learning and healthy discussion among team members.  We decided to start with a book that is simple enough and is on everybody’s reading list, Pragmatic Programmer by Dave Thomas and Andy Hunt.&lt;/p&gt;

&lt;p&gt;Running the book club &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setup a recurring calendar invite &lt;/li&gt;
&lt;li&gt;A Github wiki to keep track of the discussions.&lt;/li&gt;
&lt;li&gt;Inform ahead to the participants which chapter will be in discussion.&lt;/li&gt;
&lt;li&gt;We encourage everyone to go through the chapters, so that everyone is in line with the topics that will be discussed in the book club sessions. This allows conversation and discussion to flow more smoothly. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Learnings: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We would encourage active participation by encouraging questions in the middle of the session.&lt;/li&gt;
&lt;li&gt;Create a page, in which participants can propose new books for the book club. &lt;/li&gt;
&lt;li&gt;One person leading the talk normally does not work,  participants will rely too much on the lead to delivery book’s content rather than reading the content themselves.&lt;/li&gt;
&lt;li&gt;Active participation, where participants should bring up topics they found interesting in the chapter. &lt;/li&gt;
&lt;li&gt;Generate follow-up discussion in Slack channel participants can post interesting blogs, videos, papars that related to the day.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some of the books which are currently in our list. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Seven Databases in Seven weeks&lt;/li&gt;
&lt;li&gt;99 Bottles by Sandi Metz&lt;/li&gt;
&lt;li&gt;Structure and Interpretation of Computer Programs &lt;/li&gt;
&lt;li&gt;Design patterns in Ruby &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Book clubs are a great way to level up your team, and encourage healthy discussion between members. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
