<?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: Ngari Ndung'u</title>
    <description>The latest articles on DEV Community by Ngari Ndung'u (@ngarindungu).</description>
    <link>https://dev.to/ngarindungu</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%2F262318%2Fc276d914-1118-4609-a27f-27298479a99b.png</url>
      <title>DEV Community: Ngari Ndung'u</title>
      <link>https://dev.to/ngarindungu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ngarindungu"/>
    <language>en</language>
    <item>
      <title>Last month I learnt - cpanel hosting isn't so bad</title>
      <dc:creator>Ngari Ndung'u</dc:creator>
      <pubDate>Sun, 07 Mar 2021 10:00:00 +0000</pubDate>
      <link>https://dev.to/ngarindungu/last-month-i-learnt-cpanel-hosting-isn-t-so-bad-2bni</link>
      <guid>https://dev.to/ngarindungu/last-month-i-learnt-cpanel-hosting-isn-t-so-bad-2bni</guid>
      <description>&lt;p&gt;Yes I know. I’ve been living under a rock! Or maybe, just maybe… I’m a control freak. I remember using the cpanel interface to configure I don’t remember what for a friend’s site. That one hour or so was all the experience I had of cpanel and shared hosting in general. To be fair, my tech stack(rails and python before that) doesn’t get much love from shared hosting providers. At least not the ones in Kenya.&lt;/p&gt;

&lt;p&gt;The site I’m working on is static and I could easily have reached for firebase, or even github pages, but, email! 5$ a month is a lot to pay for email(when you’ve only ever used Gmail). Especially when there are limits on mailboxes or users. As am writing this, I realize maybe I should just have used the email hosting feature and stuck the site on firebase hosting. But hey, we never pass up an opportunity to learn. And, I’d be wasting that 30gb of storage.&lt;/p&gt;

&lt;p&gt;When selecting the provider to use, I was comparing the value proposition for the base hosting package. Storage, egress, email accounts, SSL and shell access. That last bit is where they got me. I ended up convincing my client to go for the provider with slightly higher pricing but that promised ssh access. Turns out that tick on the checkbox wasn’t accurate! So no shell. Bummer, yes, but people do still manage to host stuff so maybe I could too.&lt;/p&gt;

&lt;p&gt;I started by setting up the email and there really isn’t much to setup. There was no DNS setup to perform, since the MX, DMARC and SPIF records are auto provisioned. All I had to do was add the mailboxes, set up a default mail client and add a redirect so all mail logins use the default client. Why the default isn’t automatically set, I have no idea. If you’ve used the roundcube interface, you’ll understand that it wasn’t that difficult to convince my users to setup their mobile clients. Luckily IMAP/POP3 is available out of the box and works reliably.&lt;/p&gt;

&lt;p&gt;With email out of the way, it was time to figure out how to deploy the site. I was kinda resigned to the &lt;em&gt;fact&lt;/em&gt; that I’d have to be using ftp to push updates manually. But then I started exploring the cpanel interface and got excited when I saw &lt;em&gt;GIT Version Control&lt;/em&gt;. A little look at the documentation, and my hope was solidified. With push deploys, all I needed to deploy updates was a… &lt;code&gt;git push&lt;/code&gt;. Just like normal!&lt;/p&gt;

&lt;p&gt;Well, almost. There’s a &lt;a href="https://docs.cpanel.net/knowledge-base/web-services/guide-to-git-how-to-set-up-deployment/"&gt;dance&lt;/a&gt; that cpanel requires you to do to setup push deploys. For one, the repo must be created on cpanel. Remember my missing shell? That meant I couldn’t setup git via ssh, and yeah, typing a 16 character password becomes fun real quick! That I was willing to live with. Would have, if the deploy worked reliably. Whether it was the cheap package I subscribed to or my two left feet, the auto deploy never worked.&lt;/p&gt;

&lt;p&gt;I created the empty repo, cloned, added the site’s files and pushed. Then, nothing! The repo showed up on the dash, showed the proper last commit but the folder on the file manager was empty. Ok, so I had forgotten to add the &lt;code&gt;.cpanel.yml&lt;/code&gt;. I added that just in case, but still nothing. After quite a bit of googling and SO posts, changes to my &lt;code&gt;.git/config&lt;/code&gt; file that didn’t work, I ended up adding a few dance steps. To get my first successful deploy, I created a new branch, checked it out from the git dashboard, then checked out the main branch. This got the files to show up in the manager, but I still had to click on &lt;code&gt;deploy&lt;/code&gt; on the interface to deploy. Which effectively meant, I was stuck using &lt;code&gt;pull&lt;/code&gt; rather than &lt;code&gt;push&lt;/code&gt; deployment. This was a bit too convoluted for me, so I turned to my trusty hammer, &lt;code&gt;gitlab CI&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .gitlab-ci.yml
--------
deploy:
  stage: deploy
  only:
    - master
  variables:
    LFTP_PASSWORD: $FTP_PASS
  before_script:
    - apt-get update
    - apt-get install lftp
  script:
    - . ./deploy.sh

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

&lt;/div&gt;



&lt;p&gt;And the &lt;code&gt;deploy.sh&lt;/code&gt; file;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env sh

lftp -f "
set ftp:use-feat false
set ssl:verify-certificate false
open -u $FTP_USER --env-password $FTP_HOST
mirror -R --verbose dist public_html
bye
"

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

&lt;/div&gt;



&lt;p&gt;I ended up relying on ftp, specifically &lt;code&gt;lftp&lt;/code&gt; to push changes for the site. Gitlab allows me to keep my deployment down to a single &lt;code&gt;git push&lt;/code&gt;. Well, mostly. I adapted the above &lt;code&gt;deploy.sh&lt;/code&gt; script to sync images directly from my local. Part of the site content is a 3D tour with ~3k images which I can’t exactly commit to git. Largest lesson learnt from all this? 3D video tours aren’t videos!&lt;/p&gt;

</description>
      <category>cpanel</category>
      <category>lftp</category>
      <category>ci</category>
      <category>gitlabci</category>
    </item>
    <item>
      <title>Last month I learnt - ruby can be weird</title>
      <dc:creator>Ngari Ndung'u</dc:creator>
      <pubDate>Sun, 18 Oct 2020 20:06:00 +0000</pubDate>
      <link>https://dev.to/ngarindungu/last-month-i-learnt-ruby-can-be-weird-1n9a</link>
      <guid>https://dev.to/ngarindungu/last-month-i-learnt-ruby-can-be-weird-1n9a</guid>
      <description>&lt;p&gt;I was working on a task that involved parsing data from CSV files and saving it into rails models when I noticed something that didn’t look right. On calling &lt;code&gt;to_json&lt;/code&gt; on one of the parsed csv rows, I got;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "": null,
  "name": "John"
}

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

&lt;/div&gt;



&lt;p&gt;For context, I was parsing the CSV using the &lt;code&gt;headers: true&lt;/code&gt; option, and for some reason, I had an empty header. Since we all know that developers don’t make mistakes, it had to be an issue with the data. So, I went hunting.&lt;/p&gt;

&lt;p&gt;Another lesson, if you’re looking for an issue with data, open it in it’s raw form. Opening the csv with LibreOffice Calc and choosing the helpful defaults, opened a perfectly good sheet, and surprise, no missing header! Just as I was about to concede that it might be me, I opened the file in my editor(vim) and despite the ugliness, the trailing comma on each line was hard to miss.&lt;/p&gt;

&lt;p&gt;With a possible culprit found, it was back to the code to try and get rid of that entry. Q; which ruby type would result in an empty string in json? Now, if you use ruby I’d assume there’s literally no time you’ve wanted to use an empty string as a key in your hash, right? But still it get’s weirder, on calling &lt;code&gt;to_h&lt;/code&gt; on the row;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  nil =&amp;gt; nil,
  "name" =&amp;gt; "John"
}

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

&lt;/div&gt;



&lt;p&gt;What?! Yes, &lt;code&gt;nil&lt;/code&gt; is a valid key in a ruby hash. I had to fire up plain irb to make sure it wasn’t rails messsing with me. And just to be sure, I confirmed that it’s also possible to retrieve the value normally with &lt;code&gt;hsh[nil]&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;P.S If you ever find yourself needing to read json exported from mongo, &lt;code&gt;BSON::ExtJSON.parse&lt;/code&gt; is your friend.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>tech</category>
      <category>ruby</category>
      <category>rails</category>
      <category>csv</category>
    </item>
    <item>
      <title>How not to file your returns</title>
      <dc:creator>Ngari Ndung'u</dc:creator>
      <pubDate>Tue, 31 Mar 2020 20:20:11 +0000</pubDate>
      <link>https://dev.to/ngarindungu/how-not-to-file-your-returns-2n7l</link>
      <guid>https://dev.to/ngarindungu/how-not-to-file-your-returns-2n7l</guid>
      <description>&lt;p&gt;Think tonight I ran into one of those cases when being a developer worked against me. Long story short, I took about 3hrs before giving up on filing my tax returns. Reason? Macros on the &lt;code&gt;.ods&lt;/code&gt; version of the returns worksheet were failing. Bigger reason? &lt;code&gt;LibreOffice&lt;/code&gt; opened the debugger when those macros failed.&lt;/p&gt;

&lt;p&gt;I mean, a debugger! Couldn't help but &lt;code&gt;step into&lt;/code&gt; it. Leave alone the fact that I have never written a single line of &lt;code&gt;LibreOffice BASIC&lt;/code&gt;. The language looked weird, with &lt;code&gt;Dim&lt;/code&gt;, &lt;code&gt;REM&lt;/code&gt; and &lt;code&gt;'&lt;/code&gt;. Yes, that's a single quote. That's how you comment out stuff.&lt;/p&gt;

&lt;p&gt;I did finally get the macro to run by commenting out a few lines. Happily zipped my generated file and uploaded it to be greeted by &lt;code&gt;ERROR!&lt;/code&gt;. Total waste of my time. Tomorrow, I'll be a normal person, look for an excel installation(do they still have those?) and hopefully finish filing my returns.&lt;/p&gt;

&lt;p&gt;P.S. it was totally worth it&lt;/p&gt;

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