Configuring Wireguard using systemd-networkd on NixOS

Wireguard can be configured manually using systemd-networkd. This setup connects the Wireguard tunnel and sets up the necessary IP routes and firewall rules to send and accept all traffic over the Wireguard interface.

NixOS is my preferred system, so I’ve specified the configuration using NixOS here. Translation to a non-NixOS system should be straightforward.

Read more β†’

xmonad Per-Layout Keybindings

In xmonad it can be useful to have different keybindings for different layouts, or respond to other events differently depending on the active layout. This can be accomplished by looking up the active layout in the hook. For this we define a utility function:

import XMonad
import qualified XMonad.StackSet as S

-- Get the name of the active layout.
getActiveLayoutDescription :: X String
getActiveLayoutDescription = do
    workspaces <- gets windowset
    return $ description . S.layout . S.workspace . S.current $ workspaces
Read more β†’

Granting Capabilities Using capsh

On Linux it sometimes is useful to grant privileged capabilities to binaries without running them as root. Usually this is achieved by setting capabilities on the file through setcap. However, this has some complications with environment variables and capabilities inheritance of child processes. We can use capsh instead of setcap to achieve what we want using ambient capabilities.

Using setcap, we might add a capability to a file as follows:

$ sudo setcap cap_net_raw+epi /path/to/wine 
Read more β†’

Using Nix to create R virtual environments

Previously we saw how to use Nix to create virtual environments for Python. We can do the same for R. This means we can have different simultaneous R installations for different projects and keep the installed packages for each project separated. An important benefit of this is the ability to have different (incompatible) versions of the same packages for different projects.

The logos of Nix and R with a plus symbol

The straightforward approach is to let Nix handle all R package management. However, sometimes it is useful to manage packages through the various R tools such as the built-in install.packages or install utilities provided by the devtools package.

Read more β†’

Using Nix to create Python virtual environments

Nix is a great tool to set up development environments. It allows us to have simultaneous installations of various versions of tools—such as Python—required for our projects. This means Nix makes it easy to have Python 2.7 installed for one project, and Python 3.6 for another. Projects using the same Python version can have different Python packages.

The logos of Nix and Python with a plus symbol

Of course, Python’s VirtualEnv also enables us to do this. Nix, however, is more powerful. It can handle all our system’s packages; not just Python’s. This means it enables us to hold different versions of any dependency. For example, if one project requires a specific version of OpenCL and another project requires an incompatible version, VirtualEnv won’t help us. Nix will.

Read more β†’

Rust Debug with Breakpoint Support in Visual Studio Code on Windows

You can debug Rust programs in Visual Studio Code on Windows using LLDB. On Windows, LLDB only works reliably with 32-bit binaries. As such, this guide will outline how to get debugging working for 32-bit targets. To get this working: Install LLDB. You can get it by installing the LLVM tools, but the current official LLVM installer for Windows does not include LLDB. You can get an installer including 32-bit LLDB here.
Read more β†’

Closed-Form Rocket Fuel Requirements

Previously we calculated the fuel requirements of rockets to reach escape velocity. In that calculation, we did not take into account the effect of gravity during the fuel burn and underestimated the fuel requirements. We improved on this through a simulation better approximating reality. This simulation takes into account the force of gravity during the burn, as well as that force weakening as the rocket increases its distance from Earth, and takes into account the necessary escape velocity decreasing as the rocket’s distance to Earth grows.
Read more β†’

&SPL – Creating a simple imperative programming language

&SPL is an acronym for Simple Programming Language, and is a C-like imperative programming language, with classes, lists, and tuples. For example, the following code produces the Fibonacci sequence. #include "stdlib/std.spl" // Output the Fibonacci sequence main () { var t1 = 0; var t2 = 1; while(True) { println(t2); var h = t1 + t2; t1 = t2; t2 = h; } } The language is formally defined with a context-free grammar and typing rules.
Read more β†’

Creating Multiple Custom User Types Through Inheritance in Django

When developing applications in Django, the need might arise to customize the user model. Specifically, you might want to create different types of users. In my case, I’m interested in creating a person user and a kit user. A person user can own multiple kit users, and both need to be able to authenticate to access an API. Luckily, Django’s authentication system is very flexible, and there are multiple ways to achieve this goal.

Read more β†’