Language Selection

English French German Italian Portuguese Spanish

Programming Leftovers

Filed under
Development
  • Round a direction vector to an 8-way compass

    If you assume that the unit direction vector is in the first quadrant (both x and y are positive), then there is a direct way to compute the solution. Using 1/sqrt(2) or 0.7071 as the default solution, compare both x and y with cos(3*pi/8) and cos(pi/8), and only switch them to 1 or 0 if they are larger than cos(3*pi/8) or smaller than cos(pi/8). The full code looks as follows: [...]

  • Code review at the speed of email

    I’m a big proponent of the email workflow for patch submission and code review. I have previously published some content (How to use git.sr.ht’s send-email feature, Forks & pull requests vs email, git-send-email.io) which demonstrates the contributor side of this workflow, but it’s nice to illustrate the advantages of the maintainer workflow as well. For this purpose, I’ve recorded a short video demonstrating how I manage code review as an email-oriented maintainer.

  • Defensible Machine Learning Model Naming

    There's a curious case of a neural network for object recognition called YOLO – You Only Look Once. While many object detection models were two-pass (one for identifying bounding boxes, the other for classifying), YOLO was single-pass. This makes YOLO fast and small.

  • Leiningen Adds Support for nREPL's Unix Sockets

    The next release of Leiningen (likely 2.9.9) will include support for starting an nREPL server listening to an Unix domain socket. As a reminder - Unix domain sockets were one of the highlights of nREPL 0.9, which was released at the end of 2021.

  • What's the Most Portable Way to Include Binary Blobs in an Executable?

    I recently needed to include an arbitrary blob of data in an executable, in a manner that's easily ported across platforms. I soon discovered that there are various solutions to including blobs, but finding out what the trade-offs are has been a case of trial and error [1]. In this post I'm going to try and document the portability (or lack thereof...) of the solutions I've tried, give a rough idea of performance, and then explain why I'll probably use a combination of several solutions in the future.

  • When Should a Black Box Be Transparent?

    We have been working with a third-party vendor that supplies a critical component of one of our systems. Because of supply-chain issues, they are trying to "upgrade" us to a newer version of this component, and they say it is a drop-in replacement for the old one. They keep saying this component should be seen as a black box, but in our testing, we found many differences between the original and the updated part. These are not just simple bugs but significant technology changes that underlie the system. It would be nice to treat this component as a drop-in replacement and not worry about this, but what I have seen thus far does not inspire confidence. I do see their point that the API is the same, but I somehow do not think this is sufficient. When is a component truly drop-in and when should I be more paranoid?

  • Git with Multiple E-Mail Addresses: And How I Make Sure to Commit with the Right One

    Only using each Git server on a computer dedicated for some line of work (company, private, school) is impractical for different reasons. I keep personal notes on discoveries I make when working for my job or for school, which I store in a private repository. Changing laptops just to write down that command line I already googled seven times is not practical, and just would make me to google it for the eighth time.

    Furthermore, I prefer to work on my stationary PC running Arch Linux (which I use as a daily driver, by the way) for school-related work, especially when it comes to making up programming examples; I'm just less efficient working on my Windows laptop.

  • Locking Engineering Principles

    For various reasons I spent the last two years way too much looking at code with terrible locking design and trying to rectify it, instead of a lot more actual building cool things. Symptomatic that the last post here on my neglected blog is also a rant on lockdep abuse.

    I tried to distill all the lessons learned into some training slides, and this two part is the writeup of the same. There are some GPU specific rules, but I think the key points should apply to at least apply to kernel drivers in general.

    The first part here lays out some principles, the second part builds a locking engineering design pattern hierarchy from the most easiest to understand and maintain to the most nightmare inducing approaches.

    Also with locking engineering I mean the general problem of protecting data structures against concurrent access by multiple threads and trying to ensure that each sufficiently consistent view of the data it reads and that the updates it commits won’t result in confusion. Of course it highly depends upon the precise requirements what exactly sufficiently consistent means, but figuring out these kind of questions is out of scope for this little series here.

  • Picroscopy Turns your Raspberry Pi into a Digital Microscopy

    Picroscopy is a small Python web-application which is intended for usage with a Raspberry Pi as a microscopy solution.

    With the Raspberry Pi Camera mounted on a microscope, the Raspberry Pi provides a live video feed to its monitor via HDMI, while another machine can be used to control the setup via a web-based interface.

  • YYYY-MM-DD format date in a Shell Script

    The Linux date command is used to get the current date and time. You can easily customize the results by using the arguments. In this how-to tutorial, you will learn to format the date as YYYY-MM-DD in the bash shell.

  • Running command line tasks in Neovim

    My daily workflow often involves repeatedly running tasks, whether that be build commands, unit tests, or some other scripts. My ideal workflow is to have a terminal split on the right hand side, and then be able to send tasks to it.

  • How to Manipulate Strings in Bash on Linux

    The Linux ecosystem is packed with fantastic tools for working with text and strings. These include awk, grep, sed, and cut. For any heavyweight text wrangling, these should be your go-to choices.

    Sometimes though, it’s convenient to use the shell’s built-in capabilities, especially when you’re writing a short and simple script. If your script is going to be shared with other people and it is going to run on their computers, using the standard Bash functionality means you don’t have to wonder about the presence or version of any of the other utilities.

    If you need the power of the dedicated utilities, then by all means use them. That’s what they’re there for. But often your script and Bash can get the job done on their own.

    Because they’re Bash built-ins, you can use them in scripts or on the command line. Using them in a terminal window is a fast and convenient way to prototype your commands and perfect the syntax. It avoids the edit, save, run, and debug cycle.

  • The (Mostly) Complete Unicode Spiral

    I present to you, dear reader, a spiral containing every Unicode 14 character in the GNU Unifont. Starting at the centre with the control characters, spiralling clockwise through the remnants of ASCII, and out across the entirety of the Basic Multi Lingual Plane. Then beyond into the esoteric mysteries of the Higher Planes2.

More in Tux Machines

today's howtos

  • How to Change Comment Color in Vim – Fix Unreadable Blue Color

    Are you annoyed about the comment color in vim? The dark blue color of the comment is often hard to read. In this tutorial, we learn how to change the comment color in Vim. There are few methods we can use to look vim comment very readable.

  • How to Add Repository to Debian

    APT checks the health of all the packages, and dependencies of the package before installing it. APT fetches packages from one or more repositories. A repository (package source) is basically a network server. The term "package" refers to an individual file with a .deb extension that contains either all or part of an application. The normal installation comes with default repositories configured, but these contain only a few packages out of an ocean of free software available. In this tutorial, we learn how to add the package repository to Debian.

  • Making a Video of a Single Window

    I recently wanted to send someone a video of a program doing some interesting things in a single X11 window. Recording the whole desktop is easy (some readers may remember my post on Aeschylus which does just that) but it will include irrelevant (and possibly unwanted) parts of the screen, leading to unnecessarily large files. I couldn't immediately find a tool which did what I wanted on OpenBSD [1] but through a combination of xwininfo, FFmpeg, and hk I was able to put together exactly what I needed in short order. Even better, I was able to easily post-process the video to shrink its file size, speed it up, and contort it to the dimension requirements of various platforms. Here's a video straight out of the little script I put together: [...]

  • Things You Can And Can’t Do

    And it got me thinking about what you can and can’t do — what you do and don’t have control over.

  • allow-new-zones in BIND 9.16 on CentOS 8 Stream under SELinux

    We run these training systems with SELinux enabled (I wouldn’t, but my colleague likes it :-), and that’s the reason I aborted the lab: I couldn’t tell students how to solve the cause other than by disabling SELinux entirely, but there wasn’t enough time for that.

  • Will the IndieWeb Ever Become Mainstream?

    This is an interesting question, thanks for asking it, Jeremy. I do have some history with the IndieWeb, and some opinions, so let’s dive in.

    The short answer to the question is a resounding no, and it all boils down to the fact that the IndieWeb is really complicated to implement, so it will only ever appeal to developers.

  • How to Install CUPS Print Server on Ubuntu 22.04

    If your business has multiple personal computers in the network which need to print, then we need a device called a print server. Print server act intermediate between PC and printers which accept print jobs from PC and send them to respective printers. CUPS is the primary mechanism in the Unix-like operating system for printing and print services. It can allow a computer to act as a Print server. In this tutorial, we learn how to set up CUPS print server on Ubuntu 22.04.

Open Hardware: XON/XOFF and Raspberry Pi Pico

  • From XON/XOFF to Forward Incremental Search

    In the olden days of computing, software flow control with control codes XON and XOFF was a necessary feature that dumb terminals needed to support. When a terminal received more data than it could display, there needed to be a way for the terminal to tell the remote host to pause sending more data. The control code 19 was chosen for this. The control code 17 was chosen to tell the remote host to resume transmission of data.

  • Raspberry Pi Pico Used in Plug and Play System Monitor | Tom's Hardware

    Dmytro Panin is at it again, creating a teeny system monitor for his MacBook from scratch with help from our favorite microcontroller, the Raspberry Pi Pico. This plug-and-play system monitor (opens in new tab) lets him keep a close eye on resource usage without having to close any windows or launch any third-party programs. The device is Pico-powered and plugs right into the MacBook to function. It has a display screen that showcases a custom GUI featuring four bar graphs that update in real-time to show the performance of different components, including the CPU, GPU, memory, and SSD usage. It makes it possible to see how hard your PC is running at a glance.

Security Leftovers

How to Apply Accent Colour in Ubuntu Desktop

A step-by-step tutorial on how to apply accent colour in Ubuntu desktop (GNOME) with tips for Kubuntu and others. Read more