Generating Random Numbers, Strings, and more in Hugo
If you’ve ever needed a random number, string, or slice index from your Hugo website, this post has you covered. This article will cover selecting seeds, generating random numbers, and then how to use the random number to create random strings and select random items from slices.
Random numbers in Hugo (at least with the methods outlined in this tutorial) won’t generate a cryptographically secure value. I don’t see much worth generating cryptographically secure values for a static site.
Automatically Start Docker Container
Docker’s restart policy is the best way to have containers automatically start when you boot your server or computer. That should be the end of this post, but I’ll provide more details, examples, and reasons why you want to avoid other methods.
Docker’s restart policy is a flag you set when you first create a container from an image. The restart policy dictates whether the container should restart when it exits. The behavior is determined by which policy you choose. The container can automatically start again on erroneous exits or with all exit codes. The flag also affects the behavior of what happens if you manually stop a container.
Local Mercurial Hosting
I needed a local mercurial hosting option. The following is what I came up with. Hopefully, you will find it useful or the post at least gives you some ideas. My requirements were basic.
- Web browsable repositories
- Minimal and maintenance-free
- Support for pushing new changesets
- Accessible through a URL to easily pull dependencies
- Needed access from a single computer (which let me omit authentication)
I didn’t need bug tracking, code review, or anything fancy. Essentially, all I needed was to run hg serve
all the time, which is what I did. The repositories are hosted on the same computer I develop on, which allowed me to skip adding authentication. The mercurial server is bound to a loopback IP address making it only available to my pc. Adding authentication wouldn’t have added any additional security compared to having the local files on my computer.
How to Train SpamAssassin
SpamAssassin won’t do much if it hasn’t been trained. While it does come with a few plugins enabled for DKIM, SPF, RBL, and content checks, SpamAssassin is limited unless you train its Bayesian filter. The Bayesian filter will compare past content from known spam and ham emails to determine the likelihood of spam.
Bayes’ theorem, named after 18th-century British mathematician Thomas Bayes, is a mathematical formula for determining conditional probability. Conditional probability is the likelihood of an outcome occurring, based on a previous outcome occurring.
SpamAssassin SA-Update Tool
Are you curious about SpamAssasin’s sa-update tool and what it does? As with many other programs geared towards servers, there are additional tools that are run inside of cron jobs and used by administrators. Knowing what these tools do and how they work can help you better understand your server and fix issues down the line.
The sa-update tool is used to pull new configuration files and rules from channels. These new files are used by SpamAssassin to classify emails as spam in addition to the Naive Bayes filtering. Among these files, there are definitions of free email providers, regex checks on subjects and body of messages, and more.