<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 1MÃyzÅ on Medium]]></title>
        <description><![CDATA[Stories by 1MÃyzÅ on Medium]]></description>
        <link>https://medium.com/@1MAyzA?source=rss-b867727683da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6xYnnl2Ve0aGRhchHEgCrA@2x.jpeg</url>
            <title>Stories by 1MÃyzÅ on Medium</title>
            <link>https://medium.com/@1MAyzA?source=rss-b867727683da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 23:59:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@1MAyzA/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Table-driven tests in Go]]></title>
            <link>https://medium.com/@1MAyzA/table-driven-tests-in-go-747fe30506c1?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/747fe30506c1</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[table-driven-test]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 08:04:21 GMT</pubDate>
            <atom:updated>2018-06-15T08:19:21.906Z</atom:updated>
            <content:encoded><![CDATA[<p>I used table-driven tests to refactor my code. I found this technique in Andrew Gerrand slide while he was talking at Testing Technique in Google I/O 2014. I want to share this technique because it makes my code look better.</p><p>For example, I want to truncate a string to 20 characters in Go, which have 3 cases as shown below:</p><p>First is “abcdefghi” (length is shorter than 20 characters)<br>Second is “abcdefghijklmnopqrst” (length is equal 20 characters)<br>Last is “abcdefghijklmnopqrstuvwxyz” (length is longer than 20 characters)</p><p>Here is my “Truncate” function:</p><pre>func Truncate(str string, limit int) string { <br>     originalString := str  <br>     rs := []rune(originalString) <br>     <br>     if len(rs) &gt; limit {  <br>           originalString = string(rs[0:limit]) <br>     }  <br>     <br>     return originalString<br>}</pre><p>Below is my old test before refactoring.</p><pre>func TestTruncate_LengthLessThan20(t *testing.T) {<br>        result := Truncate(&quot;abcdefghi&quot;)<br>        require.Equal(t, &quot;abcdefghi&quot;, result)<br>}</pre><pre>func TestTruncate_LengthEqual20(t *testing.T) {<br>        result := Truncate(&quot;abcdefghijklmnopqrst&quot;)<br>        require.Equal(t, &quot;abcdefghijklmnopqrst&quot;, result)<br>}</pre><pre>func TestTruncate_LengthMoreThan20(t *testing.T) {<br>        result := Truncate(&quot;abcdefghijklmnopqrstuvwxyz&quot;)<br>        require.Equal(t, &quot;abcdefghijklmnopqrst&quot;, result)<br>}</pre><p>We can refactor it by using go struct to create table-driven tests like this:</p><pre>func TestTruncateString(t *testing.T) { <br>     var flagtests = []struct {  <br>         input  string  <br>         output string <br>     }{  // input                         output<br>         {  &quot;abcdefghi&quot;,                  &quot;abcdefghi&quot;},  <br>         {  &quot;abcdefghijklmnopqrst&quot;,       &quot;abcdefghijklmnopqrst&quot;}, <br>         {  &quot;abcdefghijklmnopqrstuvwxyz&quot;, &quot;abcdefghijklmnopqrst&quot;},<br>     }</pre><pre>     for _, tt := range flagtests {  <br>         require.Equal(t, tt.output, Truncate(tt.input, 20)) <br>     }<br>}</pre><p>See! Our test is now easier to add more test cases without having to create a new test case. We only need to add input and output. Also easier to read.</p><p>Play truncate here: <a href="https://play.golang.org/p/Ld0ErosWhd2">https://play.golang.org/p/Ld0ErosWhd2</a></p><p>That’s all for today. I hope you like my post. I would be glad to hear your opinions about the content. Don’t forget to 👏.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=747fe30506c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[รวมคำสั่งใน Emacs ที่ใช้บ่อยๆ]]></title>
            <link>https://medium.com/@1MAyzA/%E0%B8%A3%E0%B8%A7%E0%B8%A1%E0%B8%84%E0%B8%B3%E0%B8%AA%E0%B8%B1%E0%B9%88%E0%B8%87%E0%B9%83%E0%B8%99-emacs-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%9A%E0%B9%88%E0%B8%AD%E0%B8%A2%E0%B9%86-1026b012e0f8?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/1026b012e0f8</guid>
            <category><![CDATA[emacs]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Tue, 20 Sep 2016 10:21:33 GMT</pubDate>
            <atom:updated>2016-09-20T10:29:19.779Z</atom:updated>
            <content:encoded><![CDATA[<p>C-x C-f = Visit a file</p><p>C-x k = exit</p><p>C-x C-s = save</p><p>C-_ = undo</p><p>C-g = ยกเลิก sequence key ที่กดค้างไว้อยู่</p><p>C-s = search ถ้าจะไปตัวถัดไปก็กด C-s ต่อไปเรื่อยๆ</p><p>C-space = เข้าโหมด select</p><p>C-w = cut ของที่เลือก</p><p>C-y = paste ของที่ cut มา</p><p>C-x 2 = split pane</p><p>C-x o = สลับ pane</p><p>M-w = copy ของที่เลือก</p><p>M-&lt; ไปบนสุด</p><p>M-&gt; ไปล่างสุด</p><p>M-g-g = Go to line</p><p>M-/ = Auto complete</p><p>(C = control และ M = alt)</p><p>เพิ่มเติม <a href="https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf">https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1026b012e0f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Package time in golang]]></title>
            <link>https://medium.com/@1MAyzA/package-time-in-golang-4139202bb78c?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/4139202bb78c</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Tue, 20 Sep 2016 05:01:41 GMT</pubDate>
            <atom:updated>2016-09-20T05:03:13.144Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีค่ะ วันก่อนได้ลองทำโจทย์เล็กๆ โจทย์คือถ้าเวลาอยู่ในช่วงหลังเที่ยงคืนถึงก่อนเที่ยงวันจะ say “Hello, Good morning” ถ้าเวลาจากเที่ยงวันไปถึงหกโมงเย็นจะ say “Hello, Good afternoon” และถ้าเวลาหลังหกโมงเย็นไปถึงเที่ยงคืนจะ say “Hello, Good evening” เลยขอหยิบเรื่องเล็กๆที่เจอและขอบันทึกไว้เผื่อจะเป็นประโยชน์สำหรับคนที่เขียน Go กันอยู่นะคะ</p><ol><li>แปลงเวลาให้อยู่ใน format AM/PM</li></ol><pre>package main</pre><pre>import (<br>      &quot;fmt&quot;<br>      &quot;time&quot;<br>)</pre><pre>func main() {<br>      now := time.Now()<br>      fmt.Println(now.Format(&quot;03:04 PM&quot;))<br>}</pre><p>เราสามารถใช้ function Format แล้วใส่ string pattern นี้เข้าไป ผลลัพธ์ที่ได้จะเป็น</p><pre>11:00 PM</pre><p>2. การใช้ After และ Before</p><pre>if now.After(midday) &amp;&amp; now.Before(sunset) {  <br>      fmt.Fprint(w, &quot;Hello, Good afternoon.&quot;) <br>}</pre><p><strong>After</strong> ใช้เช็คว่า now อยู่หลังจาก midday หรือเปล่า <br><strong>Before</strong> ก็เช่นกันใช้ เช็คว่า now อยู่ก่อน sunset หรือเปล่า <br><strong>Equal</strong> ใช้เช็คว่าเท่ากันมั้ย return</p><blockquote>ทั้งสาม function นี้ ค่าที่ return จะเป็น true หรือ false ค่ะ</blockquote><p>3. การสร้าง Date ใน Go</p><pre>midday := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, time.Local)</pre><p>ใช้ package time แล้วเรียกใช้ function Date ส่ง parameters ไป 8 ตัว ได้แก่ ปี เดือน วัน ชั่วโมง นาที วินาที นาโนวินาที และตัวกำหนด Time Zone</p><blockquote>time.Local หมายถึง เอาเวลาของเครื่องที่รัน</blockquote><p>โจทย์ที่ลองทำดูไปดูที่นี่นะคะ <a href="https://github.com/Kanokorn/english-greetings">https://github.com/Kanokorn/english-greetings</a><br>ใครได้ลองใช้อะไรใน package time บ้างเอามาแชร์กันหน่อยนะคะ ขอบคุณที่อ่านค่ะ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4139202bb78c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tic Tac Toe Game With Golang]]></title>
            <link>https://medium.com/@1MAyzA/tic-tac-toe-game-with-golang-9a8479d6fe27?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a8479d6fe27</guid>
            <category><![CDATA[tic-tac-toe]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Sat, 17 Sep 2016 05:41:02 GMT</pubDate>
            <atom:updated>2016-09-17T05:41:02.444Z</atom:updated>
            <content:encoded><![CDATA[<p>วันหยุดแบบนี้ มาลับสมอง ด้วยโจทย์สนุกๆกัน</p><p>วันนี้ไฟที่บ้านดับเพราะมีการซ่อมบำรุงไฟฟ้า ต้องออกจากบ้านมาสิงที่ร้านกาแฟตั้งแต่แปดโมงเช้า สามีเลยชวนให้ฝึก Go ด้วยโจทย์สนุกๆคือ ทำเกม Tic Tac Toe</p><p>โค้ดที่เขียนมันยังไม่สวยนะ นั่งทำไปประมาณ 2 ชั่วโมง ได้มาแบบนี้ ใครอยากทำอะไรเพิ่ม fork ไปแล้ว pull request มาได้เลยค่ะ</p><p>โดยเกมที่ทำจะให้ Player 1 เล่นก่อนเสมอ และ Player จะแสดงเป็น ‘X’ ส่วน Player 2 ก็จะเป็น ‘O’</p><p>หน้าตาเกมประมาณนี้ค่ะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*AhpcP8LD19LE676-jIgQTw.png" /></figure><p>โค้ดอยู่ที่นี่ <a href="https://github.com/Kanokorn/tic-tac-toe">https://github.com/Kanokorn/tic-tac-toe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a8479d6fe27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type String In Golang]]></title>
            <link>https://medium.com/@1MAyzA/type-string-in-golang-70d1b2f9413c?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/70d1b2f9413c</guid>
            <category><![CDATA[string]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Mon, 12 Sep 2016 05:11:16 GMT</pubDate>
            <atom:updated>2016-09-12T05:11:16.887Z</atom:updated>
            <content:encoded><![CDATA[<p>Zero value ของ type นี้คือ empty string<br>ประเภทข้อมูล string ใน Go สามารถประกาศได้สองแบบ ดังนี้</p><ol><li>ใช้ “”</li></ol><pre>package main</pre><pre>import (<br>    &quot;fmt&quot;<br>)</pre><pre>func main() {<br>    var myInfo string = &quot;{\t\n\t\&quot;firstName\&quot;: \&quot;Kanokorn\&quot;\n}&quot;<br>    fmt.Println(myInfo)<br>}</pre><p>ผลลัทธ์แบบที่ 1 จะได้แบบนี้</p><pre>{	<br>	&quot;firstName&quot;: &quot;Kanokorn&quot;<br>}</pre><p>การกำหนดค่าให้ตัวแปร myInfo โดยใช้ “-” ของที่อยู่ข้างในจะสามารถใส่พวก Escape sequence (\n ขึ้นบรรทัดใหม่), (\t tab) ได้</p><p>2. ใช้ ``</p><pre>package main</pre><pre>import (<br>    &quot;fmt&quot;<br>)</pre><pre>func main() {<br>    var myInfo string = `{<br>    &quot;firstName&quot;: &quot;Kanokorn&quot;,<br>    &quot;lastName&quot;: &quot;Chongnguluam&quot;,<br>    &quot;nickName&quot;: &quot;May&quot;<br>}`<br>    fmt.Println(myInfo)<br>}</pre><p>ผลลัพธ์แบบที่2 จะได้แบบนี้</p><pre>{<br>    &quot;firstName&quot;: &quot;Kanokorn&quot;,<br>    &quot;lastName&quot;: &quot;Chongnguluam&quot;,<br>    &quot;nickName&quot;: &quot;May&quot;<br>}</pre><p>เหมาะกับข้อมูลที่เราต้องการพิมพ์ออกมาตรงๆ เช่นข้อมูลที่เป็น json ของที่อยู่ข้างใน `` จะสามารถแสดง tab, new line และ “” ได้เลย</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70d1b2f9413c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get the last day of month in Golang]]></title>
            <link>https://medium.com/@1MAyzA/get-the-last-day-of-month-in-golang-293806699def?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/293806699def</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Fri, 09 Sep 2016 07:51:15 GMT</pubDate>
            <atom:updated>2016-09-09T07:51:15.668Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีค่ะ วันนี้แอบมาโน้ตไว้หน่อย</p><p>โจทย์: อยากได้วันสุดท้ายของเดือนกุมภาพันธ์ 2559 <br>วิธีคือ: ให้เอาวันที่ศูนย์ของเดือนถัดไป</p><p>ง่ายมั้ยละ</p><pre>package main</pre><pre>import (<br>      &quot;fmt&quot;<br>      &quot;time&quot;<br>)</pre><pre>func main() {<br>     fmt.Println(time.Date(2016, 3, 0, 10, 0, 0, 0, time.Local))<br>}</pre><p>ลองไปเล่นกันดู <a href="https://play.golang.org/p/PgA-tJRdJp">https://play.golang.org/p/PgA-tJRdJp</a><br>จบแล้วจร้า :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=293806699def" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to check if there is a special character in string in GoLang]]></title>
            <link>https://medium.com/@1MAyzA/how-to-check-if-there-is-a-special-character-in-string-in-golang-8787733b6b12?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/8787733b6b12</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Wed, 07 Sep 2016 06:44:49 GMT</pubDate>
            <atom:updated>2016-09-07T06:44:49.614Z</atom:updated>
            <content:encoded><![CDATA[<p>ขอบันทึกไว้อีก โจทย์นี้ได้ใช้บ่อยมากๆ เวลาที่ทำ api ให้คนอื่นเรียกมา ก็จะมีบางระบบที่ไม่ได้กรอง special charactor ออกก่อนจะบันทึกข้อมูล ทำให้เราต้องมีการเช็คเอง</p><p>Special Character ที่ระบบเราไม่ต้องการให้มีในตัวข้อมูลคือ</p><pre>{“|”, “#”, “’”, “\””, “\\”, “%”, “?”, “\n”, “&lt;”, “Ø”, “ð”, “&gt;”, “ï”, “û”}</pre><p>มาดูโค้ดภาษา go กัน</p><pre>package main</pre><pre>import (<br>        &quot;fmt&quot;<br>        &quot;strings&quot;<br>)</pre><pre>var (<br>        listSpecialCharacter = []string{&quot;|&quot;, &quot;#&quot;, &quot;&#39;&quot;, &quot;\&quot;&quot;, &quot;\\&quot;, &quot;%&quot;, &quot;?&quot;, &quot;\n&quot;, &quot;&lt;&quot;, &quot;Ø&quot;, &quot;ð&quot;, &quot;&gt;&quot;, &quot;ï&quot;, &quot;û&quot;}<br>)</pre><pre>func main() {<br>        var info = map[string]string{<br>                &quot;firstName&quot;:  &quot;#Kanokorn&quot;,<br>                &quot;lastName&quot;:   &quot;Chongnguluam&quot;,<br>                &quot;occupation&quot;: &quot;Web&#39;Developer&quot;,<br>        }</pre><pre>        for field, e := range info {<br>            if containSpecialCharacter(e, listSpecialCharacter) {<br>               fmt.Printf(&quot;%s field has special character\n&quot;, field)<br>            }<br>        }<br>}</pre><pre>func containSpecialCharacter(str string, specialCharacter []string) bool {<br>       for _, sc := range specialCharacter {<br>                if strings.Contains(str, sc) {<br>                   return true<br>                }<br>       }<br>       <br>       return false<br>}</pre><p>ลองไปกดเล่นได้ที่นี่ <a href="https://play.golang.org/p/Qb33F5z2kx">https://play.golang.org/p/Qb33F5z2kx</a><br>ใครสนใจก็เอาโจทย์นี้ไปลองทำหรือเขียนด้วยภาษาอื่นๆ แล้วเอามาแชร์กันได้ค่ะ เผื่อจะได้หยิบเอาไปปรับปรุงโค้ดเดิมที่มีอยู่ :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8787733b6b12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactor Duplicate Control Flow To Data Structure (JavaScript)]]></title>
            <link>https://medium.com/@1MAyzA/refactor-duplicate-control-flow-to-data-structure-javascript-cccb65efb897?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/cccb65efb897</guid>
            <category><![CDATA[logical-assignment]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[control-flow]]></category>
            <category><![CDATA[operator-or]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Tue, 06 Sep 2016 09:57:57 GMT</pubDate>
            <atom:updated>2016-09-07T04:12:29.495Z</atom:updated>
            <content:encoded><![CDATA[<p>ตัวอย่างโค้ดที่ยกมา เป็นโค้ดที่ต้องการเลือก Html Template โดยดูเงื่อนไขการเลือกจากค่าของ Group และ Status โดยการเรียกใช้ฟังก์ชัน getTemplateUrl</p><p>หน้าตาของข้อมูลเป็นแบบนี้</p><pre>var item = {<br>    group: &quot;Normal&quot;,<br>    status: &quot;Active&quot; <br>};</pre><p>และมีฟังก์ชันแบบนี้</p><pre>function getTemplateUrl(item) {<br>    if ((item.group === &#39;Normal&#39;) &amp;&amp; (item.status === &#39;Active&#39;)) {<br>        return &#39;active.html&#39;;<br>    }</pre><pre>    if ((item.group === &#39;Normal&#39;) &amp;&amp; (item.status === &#39;Inactive&#39;)) {<br>        return &#39;inactive.html&#39;;<br>    }</pre><pre>    if (item.group === &#39;Silver&#39;) {<br>        return &#39;silver.html&#39;;<br>    }</pre><pre>    if (item.group === &#39;Gold&#39;) {<br>        return &#39;gold.html&#39;;<br>    }</pre><pre>    if (item.group === &#39;Platinum&#39;) {<br>        return &#39;platinum.html&#39;;<br>    }<br>    <br>    return &#39;default.html&#39;;</pre><pre>}</pre><p>ผลลัพธ์ที่คาดหวังคือค่าที่ return มาจะเป็น active.html</p><p>แต่จากโค้ดข้างบน จะเห็นว่ามันก็ทำงานได้แหละ แต่อ่านยากมากๆ มีเงื่อนไขที่รูปแบบซ้ำๆกันเต็มไปหมด มองไม่เห็นตัวข้อมูลที่สะท้อน Business เลย</p><p>ทำการปรับปรุงได้ใหม่เป็นแบบนี้</p><pre>function getTemplateUrl(item) {<br>    var groups = {<br>        &#39;Silver&#39;  : &#39;silver.html&#39;,<br>        &#39;Gold&#39;    : &#39;gold.html&#39;,<br>        &#39;Platinum&#39;: &#39;platinum.html&#39;<br>    };</pre><pre>    var status = {<br>        &#39;Active&#39;  : &#39;active.html&#39;,<br>        &#39;Inactive&#39;: &#39;inactive.html&#39;<br>    };</pre><pre> return groups[item.group] || status[item.status] || &#39;default.html&#39;;<br>}</pre><p>ซึ่งจะเห็นว่า เมื่อปรับจากเงื่อนไขไปเป็นข้อมูลที่เข้าถึงในลักษณะ Key/Value (แม้ว่ามันจะเป็น Object JavaScript ก็เถอะ แต่เราใช้พฤติกรรมแบบ Key/Value ของมัน) การทำงานจะเลือกจาก Object Groups ก่อน ถ้าไม่มีค่าที่ต้องการ จะไปพยายามเลือกจาก Object Status ต่อ และถ้าไม่มีอีกจะเป็นค่า default ‘default.html’ แทน ซึ่งใช้เทคนิค Logical Assignment (OR) มาช่วย ทำให้โค้ดสั้นและอ่านเข้าใจง่ายขึ้น</p><p>ปล. ลองกลับไปนั่งดูโค้ดตัวเองว่ามีอะไรบ้างที่เริ่มทำให้ลำบาก เช่นอ่านยาก แก้ไข เพิ่มเติมสิ่งใหม่ยาก ฯลฯ แล้วค่อยๆลองปรับดู และที่สำคัญอย่าลืมทดสอบดูด้วยนะว่ายังทำงานเหมือนเดิมมั้ย :)</p><p>ปล. ที่กล้าปรับปรุงขนาดนี้เพราะเรามี Unit Test ที่ครอบคลุมกรณีต่างๆ ทำให้มั่นใจได้ว่าไม่ทำของพัง :)</p><p>Update: ลองปรับจากที่มีพี่ๆมา comment ลองเป็นอีกแบบ</p><pre>function getTemplateUrl(item) {<br>    var specialGroupTemplate, normalGroupTemplate;</pre><pre>    specialGroupTemplate = {<br>        &#39;Silver&#39;  : &#39;silver.html&#39;,<br>        &#39;Gold&#39;    : &#39;gold.html&#39;,<br>        &#39;Platinum&#39;: &#39;platinum.html&#39;<br>    };</pre><pre>    normalGroupTemplate = {<br>        &#39;Active&#39;  : &#39;active.html&#39;,<br>        &#39;Inactive&#39;: &#39;inactive.html&#39;<br>    };</pre><pre>    if (isSpecialGroup(item.group)) {<br>        return specialGroupTemplate[item.group];<br>    }</pre><pre>    return normalGroupTemplate[item.status];<br>}</pre><pre>function isSpecialGroup(group) {<br>    return group !== &#39;Normal&#39;;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cccb65efb897" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[มารู้จัก ${SPACE} ใน Robot Framework กัน]]></title>
            <link>https://medium.com/@1MAyzA/%E0%B8%A1%E0%B8%B2%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-space-%E0%B9%83%E0%B8%99-robot-framework-%E0%B8%81%E0%B8%B1%E0%B8%99-7340ae80bf4b?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/7340ae80bf4b</guid>
            <category><![CDATA[robot-framework]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Fri, 02 Sep 2016 05:16:04 GMT</pubDate>
            <atom:updated>2016-09-02T05:20:13.236Z</atom:updated>
            <content:encoded><![CDATA[<p>ขอโน้ตไว้หน่อย วันนี้ในทีมเจอปัญหาจะเปรียบเทียบคำที่ได้มาจาก API กับคำที่ต้องการให้เป็น แต่ข้อมูลมันมี SPACE ติดกันสองตัว ทำให้ Robot มันเข้าใจว่าเป็น Arguments และทำให้ Robot เรารันไม่ผ่านสักที</p><p>ก็เอาปัญหาไปปรึกษาทีมอื่นๆว่าเคยเจอแบบนี้มั้ย โชคเข้าข้างเรา มีเพื่อนในทีมเคยเจอปัญหานี้เหมือนกัน และบอกวิธีแก้ด้วย โดยการใช้ ${SPACE}</p><pre>Should Be Equal  ${fullName}  กนกอร${SPACE}${SPACE}ช่องงูเหลือม</pre><p>หรือแบบนี้ก็ได้</p><pre>Should Be Equal  ${fullName}  กนกอร${SPACE * 2}ช่องงูเหลือม</pre><p>แค่นี้เราก็สามารถเปรียบเทียบค่าที่มี SPACE ปนอยู่ในคำได้แล้ว อ่านข้อมูลเพิ่มเติมเกี่ยวกับ ${SPACE} ได้ที่นี่ <a href="http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html">http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7340ae80bf4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Format JSON ด้วยคำสั่งใน Mac OSX]]></title>
            <link>https://medium.com/@1MAyzA/format-json-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%84%E0%B8%B3%E0%B8%AA%E0%B8%B1%E0%B9%88%E0%B8%87%E0%B9%83%E0%B8%99-mac-osx-8a819f40a2d8?source=rss-b867727683da------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a819f40a2d8</guid>
            <category><![CDATA[json-format]]></category>
            <dc:creator><![CDATA[1MÃyzÅ]]></dc:creator>
            <pubDate>Fri, 02 Sep 2016 04:50:21 GMT</pubDate>
            <atom:updated>2016-09-02T04:50:21.856Z</atom:updated>
            <content:encoded><![CDATA[<p>ปกติในเวลาทำงานอยากจะดูข้อมูล Json สวยๆจะเข้าเว็บนี้เสมอ <a href="https://jsonformatter.curiousconcept.com/">https://jsonformatter.curiousconcept.com/</a> เป็นเว็บที่เราวางก้อน JSON ลงไป แล้วมันจะแปลงให้อยู่ในรูปแบบที่อ่านง่าย และถ้าผิด format มันก็จะมี error บอกด้วย เรียกได้ว่าเป็น tool ตัวนึงที่ใช้บ่อยมากๆ</p><p>อยู่มาวันนึง Internet ใช้งานไม่ได้ แต่ต้องการ Format JSON เลยมีไอเดียอยากจะเขียน Tool ไว้ใช้เองด้วยภาษา Go จึงได้ปรึกษากับ Weerasak แต่สุดท้ายก็ไม่ได้ทำ เพราะๆๆๆ มันมีคำสั่งใน OSX ให้เราเรียกใช้ได้เลย ดีใจสุดๆ มันคือคำสั่งนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*YstaWfA1V6bo6kJ6QSeMFA.png" /></figure><p>ใช้คำสั่ง json_pp แล้วตามด้วยไฟล์ที่ต้องการจะ format มันจะปริ้นผลลัพธ์ออกที่หน้าจอ แต่ถ้าอยากให้ผลลัพธ์เก็บลงไฟล์ จะใช้แบบนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*wzh7RqSnpCzqPfmQ2ikIKQ.png" /></figure><p>ผลลัพธ์จากการ format จะถูกเก็บลงไฟล์ result.txt และเราต้องการจะดูผลลัพธ์แบบไม่อยากเผลอไปแก้ไขไฟล์ เราจะใช้คำสั่ง view แทนการเปิดไฟล์ด้วย vim ขึ้นมาดู</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a819f40a2d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>