<?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 ashok bakthavathsalam on Medium]]></title>
        <description><![CDATA[Stories by ashok bakthavathsalam on Medium]]></description>
        <link>https://medium.com/@lifebalance_67922?source=rss-c5973c17f576------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*P4YqHhC3frezgZO5ApUwYg.jpeg</url>
            <title>Stories by ashok bakthavathsalam on Medium</title>
            <link>https://medium.com/@lifebalance_67922?source=rss-c5973c17f576------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 05 Nov 2026 05:18:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lifebalance_67922/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[Improving Elm project in Glitch]]></title>
            <link>https://medium.com/professional-pirates/improving-elm-project-in-glitch-3fec286c9699?source=rss-c5973c17f576------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fec286c9699</guid>
            <category><![CDATA[glitch]]></category>
            <category><![CDATA[elm]]></category>
            <category><![CDATA[projects]]></category>
            <dc:creator><![CDATA[ashok bakthavathsalam]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 04:50:55 GMT</pubDate>
            <atom:updated>2024-02-03T05:49:38.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>Improving an Elm project in Glitch</h3><p><em>What seemed like a straightforward “itch to fetch”, ended up as a six hour coding marathon.</em></p><p>Suddenly, I had this itch to fetch the date information of the <a href="https://bit.ly/"><strong>bit.ly</strong></a> shorteners that I was displaying in my Elm App. So, I went about my urge, fully knowing that it is a very straightforward ask, and this time, I would document my progress as I go along.I have been using Glitch to modify my Elm Apps for some time now, and I kind of like it. Although, it is not as intuitive as doing it on Cloud9 or on your local laptop, it has the advantage of being hosted and deployed immediately on the glitch platform itself.</p><ol><li>First, I fire up my existing version of the App by typing <a href="http://bitly-elm.glitch.me/">http://bitly-elm.glitch.me/</a> which brings up the app as shown below:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HhVJAgKSz-Yfv8Gm.jpg" /></figure><p>2. Then I start reviewing my code on Glitch and immediately notice that I have this data type which is the basis of the entire app:</p><pre>{-| Link is the basic data type that is used to implement the logic<br>for this program. Link is converted to HayString for some reason.<br>I used HayString during the testing phase, and will need to refactor it.<br>Alternatively, by leaving that in, we can convert some other type<br>and search on that as well. Something to ponder...<br>-}<br>type alias Link =<br>    { title : String<br>    , keyword_link : Maybe String<br>    , long_url : String<br>    , tags : List String<br>    }</pre><p>and it needs date information to be captured, before I can even think of displaying it. Now, where to get this information?</p><p>3. Then I bring up the test data which is available at <a href="https://api.myjson.com/bins/skw8e">https://api.myjson.com/bins/skw8e</a> which immediately shows me two extra fields:</p><ul><li>Created date — always has a valid timestamp value</li><li>Modified date — by default it is 0</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*Bc9YseMwANQuuBIV" /></figure><ul><li>Since I have done this so many times in the past, I know I have to go and modify my JSON decoders which is were these two pieces of data can be obtained.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/0*u-dh0eA9ql0yf4Ro" /></figure><ul><li>Now comes the Googling part for deciding what it takes to convert a timestamp to a date string which is worth displaying.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DGTnROYwWMGEHXKc" /></figure><h3>Incremental approach</h3><p>While I am tempted to get to the date string and displaying it, I decide, let me take some baby steps. It has been a while, so let me just display the timestamp as a string, before I go back and figure out how to display a Date information.</p><p>So, I went ahead and edited in the two additional fields into the <strong>linkDecoder</strong> function :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/0*EX22lueHi_1IyhUi.jpg" /></figure><h3>Fixing an error</h3><p>Immediately, from the Log, I noticed that the Elm compiler (which runs automatically whenever a change is made)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*Pu_n9k8D8EMZpe6W.png" /></figure><h3>Second Error</h3><p>Immediately, the compiler gives me another error, which is almost guiding me to fix things in a progressive manner?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/0*Vmz022yJ9vV7Lx_F.jpg" /></figure><p>This means, I have to go and edit things in the Link datatype, which now looks as follows:</p><pre>type alias Link =<br>    { title : String<br>    , keyword_link : Maybe String<br>    , long_url : String<br>    , tags : List String<br>    , created_at : String<br>    , modified_at : String<br>    }</pre><p>And viola! No compile errors in the Log Console.</p><h3>Invoking the elm-format tool</h3><p>Now, I launch the full Console log within Glitch so that I can use the elm-format to make sure my edits conform to the coding convention in Elm. I am a big stickler for properly formatted code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/0*DZXK8gmc_NPNGjPD.jpg" /></figure><p>And then I run the optimize.sh script, which actually now updates the files which are actually used to control the app:</p><pre>public/elm.js<br>public/elm.min.js</pre><h3>Fixing the View Part</h3><p>Now, things are available to be displayed, the fun part begins. The view part of the Elm project now needs to be tinkered with.</p><h3>Backup, backup</h3><p>I now realized that I must have first started with raising an Issue for this in Github. Better late than never.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/0*k7nBNmGBLiwANCpM.jpg" /></figure><p>So, there you go. Now that I have an issue, I can do a commit to <strong>github</strong> back with the modified code, so far.</p><h3>Did I check the run-time?</h3><p>No, I did not — and so I am in for a surprise. The app does not show any links. But thankfully, because I am displaying an error in the display, I have this to go from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r-zDnF3_NS-nRZUP.png" /></figure><p>The fix is rather elementary: the JSON data contains an integer, whereas my decoder is expecting a string. So, that has been taken care of as follows:</p><pre>type alias Link =<br>    { title : String<br>    , keyword_link : Maybe String<br>    , long_url : String<br>    , tags : List String<br>    , created_at : Int<br>    , modified_at : Int<br>    }</pre><h3>Meanwhile, the issues gets updated</h3><p>By using the issue number (<strong>#57</strong>) in the comments related to the interim exports from glitch to github, the issue on github gets updated, automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HoiyENwW8zvgOsOX.png" /></figure><h3>Detour done, back to View</h3><p>Now, I hone in on the right area where I need to plug in the created_at data that is now available in HayString’s created field.</p><p>Now, comes the decision, where do I hang this timestamp information? I went to the bit.ly site and saw it is separate and on top of the link. Probably the right place for now. I can always come and change it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/0*pbk_KIm9CNmD93o5.png" /></figure><h3>The Real Work</h3><p>displayURL is where the real action is. This is what decides what displayed and how. For now, I am happy with displaying the integer as an integer. And then come back do something fanciful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/0*KqR8ql0YbrU8ECzG.png" /></figure><h3>Initial Success!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/0*5eVoDHTTDEYA7K7F.png" /></figure><h3>Some CSS styling</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*TSSOPASIS4lmdeyH.png" /></figure><h3>Let’s get some Date Information</h3><p>First step, is to convert the integer into milliseconds. And then use a formatter to get data information.</p><h3>Breakthrough at 3.30am</h3><p>Thanks to the Iso8601 elm-package and the <a href="https://stackoverflow.com/a/36203937/307454">SO answer</a>, my night was saved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/0*BWvwcRjKwQ9eb6pA.jpg" /></figure><p>and it resulted in this <a href="https://github.com/kgashok/elm-for-bitly/commit/f3096954f78d315114e6f65ef76fa32a36853220#r35434532">edit</a> which finally resolved the bug fix.</p><h3>Need to refactor</h3><p>My displayURL function has gotten hairy because of the need to convert and display Posix values to Human readable tokens. That is not acceptable. It needs to be refactored. But that can be done later.</p><h3>The final capture</h3><p><em>At 4.08am</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/0*NYAeBuhdXqjpSwu2.jpg" /></figure><h3>Closing the issue on Github</h3><p>And this is the most satisfying part of documenting an incremental improvement to a side project. To use Resolved #XX (XX being the issue number), and in this case, <strong>Resolved #57</strong> was a big high.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/0*W92B0cSiHdSLP4bs.jpg" /></figure><h3>The Refactor code</h3><p>It required the creation of a separate function <strong>displayDate</strong> which did all the grunt work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*kzsuGqitXzB8W893kLUdoQ.jpeg" /></figure><h3>Some more enhancements</h3><p>These are self-documented in the issue area itself.</p><ul><li><a href="https://github.com/kgashok/elm-for-bitly/issues/60">Issue 60</a></li><li><a href="https://github.com/kgashok/elm-for-bitly/issues/61">Issue 61</a></li><li><a href="https://github.com/kgashok/elm-for-bitly/issues/58">Issue 58</a></li><li><a href="https://github.com/kgashok/elm-for-bitly/issues/62">Issue 62</a></li></ul><p>are all well documented and easy to follow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fec286c9699" width="1" height="1" alt=""><hr><p><a href="https://medium.com/professional-pirates/improving-elm-project-in-glitch-3fec286c9699">Improving Elm project in Glitch</a> was originally published in <a href="https://medium.com/professional-pirates">Professional Pirates</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>