diamond's blog

just a blog!

silverblue and a btrfs swapfile

quick guide on having a swapfile inside a LUKS-encrypted btrfs partition on Fedora Silverblue.

Read more...

silverblue lessons

some lessons during my first few hours on Fedora Silverblue as a long-time Nix user.

Read more...

rangefunc in sourcegraph/conc? I sure hope this answers your question.

I tried adding rangefunc into sourcegraph/conc. The answer may or may not shock you!!!

Read more...

Using lowdb

This article is written for Fullyhacks 2024. It is a guide to using lowdb, a simple JSON database for small projects.

Read more...

The Fediverse/Meta Drama

If you have an irrational hate for companies and despise Meta, don’t read this article! You’ll get irrationally mad! You have been warned!

Note: This article is mostly a copy-paste of my Mastodon thread, so it’s not really well written. You can follow the thread at https://hachyderm.io/@diamond/110567418571811538.

Read more...

This article is a reply to @robpike@hachyderm.io’s toot.

I’m sorry, but this post screams “boomer take” to me. As much as I am a huge fan of Go and their creators, I don’t think this take makes sense. (1/4)

Read more...

TitanCodes 2023 Walkthrough (spoilers!)

Note: this article contains spoilers!.

I’ll be using this article to brain-dump my thought process while doing TitanCodes 2023. A lot of the solutions here assume you already know some Linux and will heavily utilize Linux tools.

Read more...

Nix Cheat Sheet

This document describes a few useful Nix functionalities that you’ll want to use often.

Note that only use this document to get the gist of things; it is not meant to be a detailed explanation. As usual, heed for the man pages for more information. It is also written with the intention that you’re using Nix within a non-NixOS distribution.

Read more...

Cgo rambling: sacrificing performance or tricking the runtime?

This following comment is extracted from a file in gotk4.

Holy moly. This is unbelievable. It truly is unbelievable. I can’t even believe myself.

Check this out. C.gpointer is resolved to an unsafe.Pointer. That… sounds fine? I mean, a gpointer is a void*, so that checks out with the C specs.

Read more...

What uses are Go interfaces, and why should I care?

Let’s go down a shallow rabbit hole and talk about the importance of interfaces and how it impacts your code not just for unit testing but also to neatly separate and organize your services.

Read more...

Go’s http.Handler is a lot more flexible than some people would expect. Here are some of my preferred ways of using them.

The article will assume that the router library is chi, because it’s a great library to use. It will also assume that the application being made is named bookstore.

Read more...

Using Go contexts as “magical value vaults” can be hard to understand. This article is written to quickly introduce a way to easily grasp it.

(This blog article was rewritten from a previous chat message.)

Read more...

fmt.Scan, fmt.Scanf and fmt.Scanln are harmful.

Every time I want to use those APIs, I always find myself having to look up the documentation for their exact behaviors.

The only times I’ve wanted to use those functions were when my inputs were verified and constant. For example, this was extremely useful for parsing files during Advent of Code.

Read more...

Go doesn’t have unions, but there’s a hack to do it.

Assume we want to create a union type of a node that may be a text node or a container node that holds text nodes. The following code (playground) demonstrates this:

Read more...

Profiling in Go is dead easy. You should do it.

It is always better to have actual empirical evidence showing that your code is slow rather than blindly taking a guess at where it might be slow, or even worse, rewriting a chunk of code to use the fast* libraries without understanding how it works (I’m looking at you, fiber, fasthttp and fastjson).

Read more...

Image uploader/browser with only Caddy

Read more...