I was looking at a proposal for adding value-semantic dynamically-allocated types to C++. You can find it here . This proposal adds two class templates, indirect and polymorphic . The primary use case for this is to make it easier to write correct composite classes. A motivating example can be found through existential types. Suppose you want a type T which owns (ownership is key) some objects…
I went to a talk recently about C++ coroutines, and I don't think it was very good. The talk went through some examples of C++ coroutines and had a surface-level handwavy explanation of what "really happens" when compilers see a coroutine. But a non handwavy explanation is really easy - you can just look at what the compiler does to coroutine code to see what's really happening. No analogy, no…
I recently read Children of Memory by Adrian Tchaikovsky. It's the third in the Children of Time series. Each book in the series shares a common backstory and general template: Humanity sends out terraforming missions to the stars. Earth collapses into war and disaster over hundreds of years. Survivors send out ark ships to find and hopefully colonise the Edens waiting for them. It doesn't go as…
I was running something in WSL, as you do, then I thought about it for a second. When I'm doing this in WSL: $ clip.exe < file.txt How does that actually work? It turns out this is done using /init which is two things: PID 1, it's the init system, the parent of all processes in WSL. An "interpreter" for Windows executables. When you run clip.exe , that's the actual Windows binary you're running…
Why is the following change to a Rust struct backwards incompatible? struct S + y : i8 , x : i32 , And why is the following change to a C++ struct backwards incompatible? struct S + char y ; int x ; ; The answers are different and may surprise you. Rust provides fewer compile guarantees about structs by default and more guarantees in code interacting with structs than C++. C++ is batshit crazy as…
I just noticed that we're now past the 10th anniversary of my first blog post, which I made on 2013-08-11! Maybe I'll write a retrospective. Moving on. Recently, a friend suggested I'd be interested in EVE Online. For those not familiar, it's an MMO with lots of stuff but in particular, it has a player driven market economy. Prices are driven by market forces. Players place buy and sell orders for…
(or: How I learnt to stop worrying and love opportunity cost) I'm a fan of the board game Sidereal Confluence . It's a game where: There are resources: small cubes, large cubes, ultratech (octagons) You have converters that change sets of cubes into others (e.g. 2 white and one blue cube into 3 black cubes) Your goal at the end of the game is to have the most victory points (VPs). Some converters…
alloca is a function provided by several C libraries (e.g. glibc) that lets you allocate a block of memory that will be freed when the calling function exits. It's usually done by allocating memory on the stack. But here are a couple of questions: No C standard or POSIX standard mentions alloca , so what "should" it really do? Given that no C standard mentions the stack, is it even possible to…
386BSD 1.0 was released in 1994 on a CD in an issue of Dr Dobb's Journal. There are guides on the internet on how to boot 386BSD 1.0 in QEMU, like http://gunkies.org/wiki/Talk:Installing_386BSD_1.0_on_Qemu but I don't think there are any guides on how to boot it like someone in 1994 would've booted it, from a real MS-DOS installation. Rather funnily, 386BSD is listed as "theoretically bootable"…
Java is a language missing a lot of features. One of those missing features is keyword arguments. By that, I mean something that lets you call functions like this: my_function ( x = 1 , y = 2 , z = 3 ) Or even: my_function ( z = 3 , x = 1 , y = 2 ) That is, arguments that are named, can be reordered, and are non-optional at compile time. You might quibble: Python doesn't have compile time. But you…
A few weeks ago, I was reading a Hacker News post about a clipboard manager. I can't remember which one exactly, but an example is gpaste - they let you have a clipboard history, view that history, persist things to disk if you want, and so on. One comment caught my eye: it asked why clipboard managers didn't use the splice(2) syscall . After all, splice allows copying the contents of a file…
A few weeks ago, I played the board game "The Search for Planet X". The premise is that you have a circular board divided into 12 sectors, each containing one object. That object could be an asteroid, a gas cloud, and so on, but most importantly, it could be Planet X. Which object is in each space is hidden at the start of the game and you're racing your opponents to discover Planet X by scanning…
Mockito is a pretty popular Java mocking library. It lets you write code like this: MyClass mockObject = mock ( MyClass . class ); when ( mockObject . myMethod ( 1 )). thenReturn ( "one" ); Which is pretty cool, even if it's a bit magic. It's not really that magical, conceptually - Mockito simply intercepts method calls and keeps track of which methods have been called globally, and with what…
This is a post from the perspective of a new Java programmer, so it is 100% likely that the concerns here are well-known and already addressed. Or at least discussed. Java, as a language, doesn't get (understand) immutability and "delivers" it in a way that grants almost none of the benefits of immutability in other languages, like C++ or Rust. I picked those examples to show that the lesson was…
People write code that relies on all sorts of implicit or obfuscated knowledge. In the worst case, people write code that requires any caller to read through the entire source to work out how to use it or what it does. What confuses me is that people often seem to do this intentionally, it's like they want to require omniscient knowledge of the codebase for anyone wanting to call or write tests…
While in Venice, I picked up a book, If Venice Dies by Salvatore Settis. The main thrust of the book is that tourism is bad, Venice has died or is on the cusp of death, and changes need to be made to remedy the situation. This is the kind of book that only works if you already agree with its premise, and read it as outrage porn rather than as a well-motivated, well-explained argument. That might…
There are many mistakes we made when halfheartedly trying to get funding for our startup. The worst was that we didn't actually have a business at all - we had no users yet due to not having regulatory approval for our financial product, and no practical plan to get that other than sending applications and hoping. The second worst was that our funding applications were really bad in many ways. Not…
I recently read a couple of blog posts about deserving success, and I found them very interesting, mostly because of what they tell me about the people writing them. I have some thoughts on these posts but reading them back, I think they're nonsense. I'll post them anyway. Here are the posts: One from someone who hates the word "deserve" because they believe luck plays a much larger part in…
No-one reads this blog, so this is a safe place to make a public announcement I don't really want anyone to see. I'll be moving to New York in a few months when my visa goes through. There are many reasons I'm moving to New York, the main ones are: More money Looking to run away from my startup failure And the main one, I'm looking for something cool to do because I'm bored. Read on for some…
A while ago, I soldered together a Z80 homebrew computer and ran some programs on it, then wrote a blog post about it . I did end up running some toy programs and some BASIC games like Super Star Trek, but that got me thinking - how hard would it be to solve a real algorithmic problem on it? It turns out it wasn't hard at all, thanks to the Z80 development kit (z88dk) and the hexload BASIC program…
The conventional wisdom is that if you're starting a business you should do something you're good at or know something about. If you're a software engineer, you should probably be the guy running engineering. If you're in sales, you should probably be the sales guy. I mean, that makes sense. This is going to sound stupid and obvious, but people have a strong bias towards doing things they enjoy…
Since C++17, us C++ programmers have rejoiced in the fact that when we return something from a function, the standard now guarantees that the value won't be copied. This is known as return value optimization (RVO) or copy/move elision, and happens in cases like this: MyType myfunc () // ... return MyType arg1 , arg2 ; That is, MyType is constructed once and never copied or moved. But some…
There are a lot of ways to represent numerical values on a computer, you've got the various fixed-size integer types and floating point types, but you also have arbitrary precision arithmetic, where the size of the number is limited only by the memory of the machine. To represent the real numbers, $\mathbb R $, programmers often choose floating point numbers. But of course, floating point is…
I was recently trying to get to grips with the GAP programming language . For those not familiar, it's the programming language for the GAP computational algebra system. It has tons of algorithms implemented for group theory, representation theory, algebraic number theory, and so on. I was thinking about implementing a TypeScript-style transpiler so I could program with some types, and the first…
For my Master's degree, I (helped greatly by my supervisor) implemented some algorithms and even invented some new algorithms to decompose representations of finite groups. I wrote an extremely long (well, relative to other things I've written) and technical thesis about this, but I find myself increasingly unable to understand what any of it means or why I even have a degree. I thought being…
I'm somehow one of the maintainers of rss2email , a popular Python program for reading RSS feeds and sending feed updates to your email address. I think I reached this point via an unusual route, so I thought I'd write a little about how it happened. For those not familiar, back in 2004, Aaron Swartz (yes, that one, rest in peace) wrote a short Python script that would read an RSS feed and send…
Anyone who has played Halo and fired the Gauss cannon on the Warthog has experienced a strong desire to do it in real life. Usually this is cut down by the idea that Gauss guns aren't real. But of course, they are, and I've built a few. Feel free to replace all mentions of "coilgun" with "Gauss superaccelerator" or "magnetic spaceship cannon" if this will satisfy a childhood fantasy of yours.…
I was decommissioning a few of my older computers and servers, stripping them down for parts. The hard drives in them were mostly IDE drives which had long stopped working. There are almost no useful parts you can strip from a non-functional hard drive except maybe the IDE connector and of course, the extremely strong rare-earth magnets. But what could I do with them? Here are some things I did…
I have a Sun Ultra 45, the last and most powerful Sun SPARC workstation. Even though mine doesn't have both of the two CPU slots filled, the fans are still really loud. Is there a way to control the fans? How could I slow them down? I first tried to find a software solution on OpenBSD and later had to resort to soldering and adding some resistors to the fans to slow them down. The Problem To…
Like everyone, I have a ton of old routers lying around. It pains me to see these very useful computers go to waste, so I made it my business to hack into all of mine and replace the firmware. Maybe the title is a bit dramatic, but it's technically accurate. My first target was an old Sky router, a Sagemcom F@ST2504n. Which OS? The obvious choice is OpenWRT since they have a page with easy…
I've always wanted to design and build my own homebrew computer. By this, I mean buying some ICs and soldering together something like an Apple I or a ZX Spectrum. This post isn't going to be about my struggles designing a homebrew PC, since I haven't done that. Instead, I bought a new Z80 homebrew kit, the RC 2014 . That's right, there is still someone out there making these kits. Why the Z80?…
Until recently, my transcript search web app was running (at https://transcripts.kaashif.co.uk , check it out) in a tmux session, with a PostgreSQL server running on the same machine in the usual way, as a daemon. The web app knows nothing about its dependency on the database, this information is not recorded anywhere except in the code itself. And the database knows nothing about the web app.…
Since I have access to a machine that has the PA-RISC architecture, I thought I'd compile some test programs and see what sort of assembly code produced. Some highlights: A neat way to manage the stack pointer (and one surprise) Every instruction seems to be shorthand for or Completers - a weird way of giving switches to your instructions PA-RISC is considerably less popular than x86, MIPS,…
A while ago, I got my hands on a beast of a machine, a 7U HP L3000 (rp5470) PA-RISC server. These were released in the year 2000 and came with up to 16GB (whoa) of RAM and up to 4 CPUs. The best site for information on PA-RISC machines is, no doubt, OpenPA.net , and they have a fantastic page on my machine. This is the story of how I managed to install Gentoo GNU/Linux on this classic UNIX server.…
Remember my transcript search engine, https://transcripts.kaashif.co.uk ? I'm not a database expert, but even I realised that spending hours and hours trying to optimise my homebrew database transcript search engine was a waste of time. For no reason at all other than to try it out, I went with ElasticSearch. The astute reader will notice that ElasticSearch is meant for "big" data. My collection…
Everyone's studied x86 assembly (just objdump any program on your PC...) and maybe even some ARM or MIPS in a class somewhere, but there are a few features that exist in some CPUs that don't exist at all in any of these designs. I'm talking about register windows! When you call a function on SPARC, the new function just magically gets its own registers neatly separated into input registers, output…
It's a little known fact that there is actually no way in C or C++ to do an unaligned access without invoking undefined behaviour. It's true! Read it yourself here : A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned [...] for the referenced type, the behavior is undefined. C11 (n1570) 6.3.2.3 p7 Sadly, the…
A few weeks ago, I got my hands on a Sun T2000 server. It's got an UltraSparc T1 CPU, 32 threads, 32 GB of memory, a Sun XVR-300 GPU and what sounds like a huge jet engine mounted at the front. It's a great machine (although maybe not as a workstation...), and there are a few things unique to SPARC that I've really been looking forward to playing around with. Mostly LDoms (logical domains - Sun's…
This server (the very one you are reading this post on), at the time of writing this post, runs OpenBSD 6.1-stable. It's fully patched and updated and everything, so it's a perfectly fine OS to run. But the VPS has limited memory and disk space, and the CPU isn't very fast, so compiling large projects on it, especially Haskell ones, is impractical. This post describes a way to build…
I recently got an old Sun Ultra 5 working. It wasn't too difficult, but I needed to dig up a few old serial cables... It already had SunOS 5.8 installed, but I put OpenBSD 6.1 on it, since I need a modern OS to actually do anything with it. The first boot The first step was obviously to just turn it on and see what happened. This went well, it turned on, the CD drive and floppy drives made some…
Migrating mail servers is a tricky business, especially when one server doesn't have IMAP set up. The easiest way is to download all the mail and reupload it to the new mail server. This seems simple enough, but I ran into problems. After all, I was going from an IMAP server somewhere to a maildir (no IMAP sync tool supports mbox for some reason) to an mbox through procmail to a directory of…
There I was, a loyal user of http://mail.zoho.com , when I decided to download all of my emails. For archival purposes, you know. So I fired up mbsync, set everything up, let 'er rip, but after only about 10,000 emails downloaded, I got this error: IMAP command 'AUTHENTICATE PLAIN <authdata>' returned an error: NO [ALERT] Your account is currently not accessible via IMAP due to excessive usage.…
Before I get my Sun Ultra 5 working and can write something about that, I thought I'd go through all the hardware I'm using right now and the OSes I'm running on them. Spoilers: it's all OpenBSD and Debian. I have accumulated quite a few laptops in various states of disrepair. The working ones, I prefer to install OpenBSD on them. The non-working ones become spare parts for the working ones.…
You may have heard of the Star Trek script search tool at http://scriptsearch.dxdy.name . I'm writing a similar thing for Stargate. The difference is, of course, is that my tool will be running on some crappy Amazon AWS t2.nano with no RAM. The first prototype was written in Python, but the parsing code was always written in Haskell (Parsec is great). I decided to move everything into Haskell so…
So I was setting up a laptop I had just picked up, when it came to deciding what OS to install on it. Obviously, I'd probably end up installing some Linux and maybe also OpenBSD (hard drives are huge nowadays, I could fit hundreds of OSs on there). While I had tried out FreeBSD and NetBSD, DragonflyBSD had never been on my radar. It still isn't, really, but I thought I'd try it out on an old…
Today, I decided to install Gentoo on a spare machine I had lying around, since I was bored. Obviously, the first issue I ran into was that emerge x11-base/xorg-server was taking a really long time to run since the Xorg server is a pretty bloated program. Then emerge firefox was taking forever too. One solution (for Firefox anyway) was to use the provided binary packages, this meant firefox-bin…
There are hundreds of blog posts about backing up your PGP keys around on the internet. Most of them just say something like: put a passphrase on it, keep it on a USB stick, a CD, a floppy disk, or something like that. These are all very useful ways to back important stuff up - in fact, I just restored a backup of my GPG keys from a CD after deleting them by accident. These mediums are, however,…
I wanted to make a list of the websites of the people on the website http://nixers.net , and I decided to solve it not by asking people to tell me what their sites were called, but by scraping the forum. I didn't scrape the whole forum, I just scraped one topic on the forum that I created a few years ago: https://nixers.net/showthread.php?tid=1547 There really isn't much to it, all I had to do was…
Some people reading this might be thinking: "hey, it's really easy to do this, why is he writing an article on this?". You are partially right, this should be really easy, but there are some weird things that happened while I set this up that I feel should have been written down somewhere, so my fear that I was completely borking my system would have been assuaged. Anyway, let's get onto the first…
What is frog? Frog is a static website generator written in Racket. It does the same sort of thing as Jekyll, Hakyll and other software like that, some of which I've used in the past. What does "frog" mean? There's a simple answer to this on their README: Q: "Frog"? A: Frozen blog. I'm not 100% on what that means exactly, but the program works great, so who am I to say that their name doesn't make…