Refactored Telegram

It’s all just ones and zeros under the cover

A Brief Look at Stimulus

Over the last several months, I’ve been doing a bit of development using Buffalo, which is a rapid web development framework in Go, similar to Ruby on Rails. Like Ruby on Rails, the front-end layer is very simple: server-side rendered HTML with a bit of jQuery augmenting the otherwise static web-pages.

After a bit of time, I wanted to add a bit of dynamic flare to the frontend, like automatically fetch and update elements on the page. These projects were more or less small personal things that I didn’t want to spend a lot of time maintaining, so doing something dramatic like rewriting the UI in React or Vue would have been overkill. jQuery was available to me but using it always required a bit of boilerplate to setup the bindings between the HTML and the JavaScript. Also, since Buffalo uses Webpack to produce a single, minified JavaScript file that is included on every page, it would also be nice to have a mechanism to selectively apply the JavaScript logic based on the attributes on the HTML itself.

I since came across Stimulus, which looks to provide what I was looking for.

Read more →

Setting Go Variables During Build

Like many others, there are occasions when and I want to store the value from the environment, like the current build number or Git commit hash, in the source code of a software package so that I can display it on startup or when invoked with a command line switch. This information is only available during the build phase of the application, so something will need to be added to the build process to inject this value once it is known. This is relatively easy to do in C by using the -D switch to the compiler to declare the value as a macro. Even in Java this can be done using Maven resource filtering.

However, I was unaware of how this was done in Go. To date, I have been using a simple form of code generation that involved passing sed over a source file with a dummy string constant. sed would be configured to replace that constant with the version number or Git hash prior to the Go application being built. This worked, but it was a little bit inelegant.

I have since learnt, via this Stack Overflow answer, that it’s possible to set the initial value of a Go variable directly from the build command. The process is not as nice as it could be, as it involves actually setting flags to the linker, but it works reasonably well and is much nicer than doing things with sed .

Read more →

Posts Only RSS Feed in Hugo

This blog is a static website generated using Hugo. Like most other static website generators, Hugo provides a lot of features out of the box, one of them being the generation of RSS feeds. I wanted to add a link to an RSS feed of the blog posts to the nav-bar. After trying the /index.xml, I noticed that it included entries for the static pages that are not themselves posts, like the About page.

I wanted to exclude these static pages them from the RSS feed. Here is how I did it.

Read more →

Hello World

Hello, and welcome to Refactored Telegram, a blog about my adventures in software development.

I have been meaning to start a blog dedicated to working in software for a while. As a professional developer and someone who builds side projects in his spare time, I occasionally write on the topic in my personal blog. But it felt a little strange interleaving my thoughts on the subject alongside my day to day blog entries. I felt it was necessary to put together a separate blog for posts that relates to my professional and personal work, which is the reason for the existence of this blog.

Read more →