The Developer's Tidbits

Helpful tips for random problems
The skyline of Sydney, Australia - used as a header image for aesthetics
The skyline of Sydney, Australia - used as a header image for aesthetics

Prev - Next 1 of 13 pages

hugo

Image optimization in Hugo

I will go through the easy process of optimizing images in Hugo to create <img> elements that represent good practice. It will cover recommended attributes, image compression, the automatic generation of alternative formats, and cache busting using fingerprint.

Continue reading

go

Create a Boolean Yes or No prompt in Go

Article preview image

In this post, I will create a simple function that will allow you to ask the user a question, receive a valid response, and return it as a Boolean type. And if needed, the user will be able to tap Ctrl+C at any time to exit the program. Also importantly, despite using the operating system input, we will create unit tests for os.stdin.

Continue reading

go

Center text in a terminal with Go

Article preview image

This guide will show how simple it is to center text in a terminal or a text file using the Go standard and external libraries. We will create two functions, NCenter, which provides for a width parameter, and a Center func that will determine the center placement based on the width of the terminal screen.

You can find the final code on GitHub or play with NCenter() in the Go Playground.

Continue reading

go

Go, create a Unicode random string generator

One of the great things about the Go standard library is how easy it is to create a sophisticated tool using a small amount of code. In this entry, I will explain how to make a variable-length random string generator that can support any Unicode character.

You can find the final result on GitHub or run it at Go Playground.

Continue reading

Prev - Next 1 of 13 pages