Golang Project Structure

Tutorials, tips and tricks for writing and structuring code in Go (with additional content for other programming languages)

algorithms

Tag

Introducing the P Versus NP Problem

Text written on a chalkboard referencing the "P versus NP" problem, which remains an open question in computer science.

The P vs NP problem is a major unresolved issue in theoretical computer science. It challenges our fundamental understanding of computation, efficiency and the nature of problem-solving itself. This question doesn’t just examine what computers can do today. It probes the limits of what machines can achieve, and what they may never be able to […]

How to Write a Rate Limiter in Go

A tortoise from the Galapagos Islands in South America. It is a famously slow-moving animal.

Web applications are used by more of us than ever before. With this growth comes a significant challenge: how can a web developer or administrator manage user traffic effectively and ensure that services remain stable, responsive and secure? Rate limiting serves as a crucial technique in addressing this challenge, allowing developers to control how frequently […]

Understanding Huffman Coding and Its Implementation in Go

David Huffman depicted around the time that he developed the algorithm for Huffman coding as a young man.

Huffman coding is a widely-used algorithm for lossless data compression. By assigning variable-length codes to an input string’s characters, it ensures that the most frequently seen characters have shorter codes, while less frequently seen characters have longer codes. This technique minimizes the overall size of the data to be transmitted or stored. In this blog […]

Let’s Do the Knuth Shuffle

A croupier in a casino shuffling a deck of cards by hard.

I know it sounds like a funky dance move, but the Knuth shuffle is actually an elegant method for randomly rearranging the elements in an array — or, as we Gophers tend to prefer, a slice. The algorithm is very easy to understand and implement, which means that you should be able to use it […]

Hash Functions in Go

This post will explain what hash functions are and how they’re used. We will then go on to look at some examples of hashing algorithms in Go code. Finally, we will look at importing external packages that export hash functions, including from the standard library. What Is a Hash Function? A hash function takes data […]

How to Pixelate Images in Go

When an image is pixelated, it has a visual effect applied to reduce its level of detail through the use of many same-sized blocks, each painted with a single colour. Each of those blocks can be thought of as a large pixel (since a pixel is the smallest unit that can contain a colour in […]

Ways to Work Out the Average Colour of an Image

It’s reasonable to look at a picture and to wonder how it might look if it were distilled down into a single colour, which somehow still encapsulates a sense of the original. In this post, we will look at various methods that can be used to calculate the average colour of an image in Go, […]

A Super Speed-up With Binary Search

In any programming language, there are two main algorithms used for finding a given value in an array: linear search and binary search. (Just to note: in Go, we generally use slices rather than arrays, but I’ll use those two terms interchangeably in this post, just for the sake of simplicity, since everything that I […]