RSSAmplifier

Blog

Michael Maclean

A software developer and technical architect, based in Scotland.

mgdm.netRSS feed ↗55 posts

Latest posts

Using private flakes in NixOS

I’ve been using Nix and NixOS for a while now, but I’d got into a way of working where it was doing what I needed to do, so I haven’t felt the need to modernise it with the new features that have come along since I started using it. On the other hand, I did want to use some code that I’m not ready to open source yet and I wanted to find a neat way to do that. It’s likely that none of this post…

Adventures in digital radio

A few years ago I got my foundation amateur radio licence. It was something I’d been considering doing for quite a long time but there were few opportunities to do so where I was at the time. I used it a bit as MM6YHF, mainly on 2m and 70cm analogue FM repeaters. It’s been a while since I did very much radio, as where I stay now is a bit further away from the repeaters so it became harder to do. A…

Using JQ with SQLite

A while ago I was doing some work with data that I was loading into SQLite. I had been using jq to do some exploratory work to get different parts of the data out, but those queries didn’t directly translate to the JSON operators that exist in SQLite. I wondered if it might be possible to add an extension to SQLite to add operators that speak jq ’s syntax. It turns out that it’s relatively easy. I…

Wrangling JSON in PostgreSQL

I’ve been using SQLite a bit in some of my own projects recently, and I think it’s a great solution for small self-hosted applications, avoiding the need to run a full-blown RDBMS where it’s not really warranted. Xe’s post about JSON in SQLite talks a lot about how to use SQLite to handle JSON data and load it into other tables without having to have your application do it, which is great. On the…

Firecracker, Ignite, and ZFS

Now that I have my NixOS Pi 4 up and running and doing a couple of useful things, I thought I’d see what else I could do with it. So far it’s just running DHCP, DNS and Tailscale, so it’s got a bit of spare horsepower. I also wrote a fan control daemon for the Argon ONE case because I had some different requirements from the one that Argon40 themselves ship. I decided to try out running…

htmlq, revisited

A couple of years ago I wrote about a tool I’d created called htmlq . At the time, I’d been doing a bit of web scraping, and while it’s absolutely doable using Python and BeautifulSoup glued together with a shell script, it was a bit slow waiting for the Python startup time for each iteration. I ended up writing a bit more code to do the thing I wanted to do at an acceptable pace. Don’t get me…

Why Nix?

I’ve written a lot about Nix and NixOS over the last couple of years, and I use Nix in some way most days that I’m on a computer. Sometimes when I mention this, people ask me what’s so interesting about it. I’m going to try and answer that here, by running through what I find useful about Nix. If you read the front page of the Nix website , you’ll see a quote like this: Nix is a tool that takes a…

Installing NixOS on the Raspberry Pi 4

I have been wanting to find a more permanent home for the DNS server I built before which was on a Pi 4 running Raspbian. As is evident by the number of posts I have on here about installing Nix on every computing device I can get my hands on, I wanted to put NixOS on it. Previously I’d not been keen doing that on an SD card because I still have a perception that Pis running Linux can chew them up…

Installing NixOS on Kimsufi machines

Note 2: This was fun at the time, but these days you probably want to use nixos-anywhere and probably disko . I’ve been using a few EC2 and DigitalOcean machines for various small projects recently, but I was getting a little bored of the cost of all the little machines I’d ended up setting up for different purposes. I decided to consolidate them all into one hardware machine upon which I am going…

systemd socket activation

My last post on this topic caught some attention, so I’m going to continue exploring some of the systemd features that may be useful to people writing network services. Here are some more things about socket activation I didn’t cover in the previous post. Firstly, it’s not something that needs a binding to a specific library to work (although systemd does make one available for this task). It uses…

Using Nix to install Go tools for VS Code

I use both Nix on macOS and NixOS on different machines, so most of my projects have acquired shell.nix files at their root so that I can have the same set of tools and dependencies available to me regardless of which machine I’m on. I also use VS Code at least some of the time, and the Go extension there requires a number of command line tools for much of its functionality. It’s quite happy to go…

Avoiding complexity with systemd

Unix machines, since the early days of the operating system, have been designed for multiple users to use concurrently. Traditionally there is a set of “unprivileged” users used by people and system services, and the root account which can generally do anything. Because of the concept that most things in Unix are represented by a file, users could be allowed to perform various operations by adding…

How to accidentally a MySQL server

A long time ago, in a company far, far away Our site ran on dedicated hardware, rented from a managed hosting provider who we never really got around to doing a lot of managing. As such, we all had root on all the machines, and so were free to do what we wanted. We also didn’t really know a lot about configuration management at that point, so changes were largely ad-hoc and unrepeatable. At some…

Evading broken DNS

Once upon a time I had quite a good ISP. They were fairly technically adept, had decent uptime, and would let you use whatever equipment you liked. Unfortunately a couple of years ago they were bought by my current ISP. They’re less friendly, require you to use their own equipment, do not provide a bridge mode on their routers, and finally they do an unfortunate thing where they will redirect any…

Using PostgreSQL in a nix-shell

Sometimes (well, quite often of late, at work) I want to load some data into a PostgreSQL database and do some work with it. I use a Mac at work, and used to do this by installing PostgreSQL using Homebrew and running it system-wide. This stung me a couple of times; Homebrew would upgrade the package to a new minor release (9.5 -> 9.6, etc) and create a new data directory with the version number…

CSP logging with nginx

Background The Content-Security-Policy HTTP response header has a huge number of ways in which you can limit the kinds of resources that your site is permitted to load. This can defend against XSS attacks and other kinds of content injection. It’s very powerful and, depending on how your site is built, can be fairly simple to implement by adding a header to every response that you send, either in…

Developing with Flask on NixOS

I recently acquired a second hand ThinkPad to run NixOS on, and I’ve been using it recently to mess around with a couple of small web projects. I’m prototyping one of these in Flask, and have been using NixOS’s own Flask package in order to do so. I found that I could quite happily do flask run , but as soon as I tried to enable development mode, I’d end up with an error like this: $…

htmlq: Like jq, but for HTML

Continuing my journey into learning Rust, I have been looking around for small, useful projects that might be interesting to build rather than doing exercises. In the mean time I was doing some web scraping using Python and BeautifulSoup, which is great but it can be a little slow. I am aware of Servo, the browser written by Mozilla in Rust, and had the idea to try and recycle parts of it to make…

Debugging network connections on macOS with nettop

Recently I’ve been learning Rust, and by far the simplest way to install that is to use Rustup . That works really well on my home computer, but I wanted to try solving a problem I had at work using Rust, so I tried it on my work Mac. My company’s network has a fairly restrictive set of firewalls, and I found that rustup was somehow failing to connect to the network to download the indexes it…

Installing NixOS

It’s been a while since I’ve had a machine running Linux, and even longer since I’ve had actual desktop hardware. Recently my brother upgraded his gaming PC, and I acquired the old motherboard, CPU, RAM and graphics card. It’s a couple of years old but definitely quick enough for my purposes. I decided to install NixOS on it to give it a proper go. I’d tried Nix on my work OSX laptop for a while,…

MFFI: A new foreign function interface for PHP

In PHP, if you want to make use of a library written in C, you generally have to go and write a new PHP extension. This isn’t that hard if you’ve done it before, but it does require a bit of work and some getting used to. There’s also a fair bit of boilerplate code that is required to create functions, classes, and methods, and to handle parameter parsing. The documentation for this side of things…

PHP at the speed of C

For common cases, most dynamic languages are “fast enough”. For most PHP applications, the most overhead is probably hitting network services like the database, and this accounts for far more of the run time than the speed of the language’s function calls. Also, PHP is a fairly thin glue layer on top of a lot of C libraries, which mean that for any significant algorithmic work, you’re probably…

Vagrantfile inheritance

I’ve recently been using a lot of Vagrant machines at work, and needed to come up with a way to permit people to customise settings such as the developer’s own DNS zone, the amount of RAM and number of vCPUs assigned to each machine, etc. In the Vagrantfile reference I noticed that Vagrant will merge several Vagrantfiles together on launch. First, the Vagrantfile packaged in the box The…

zsh with Antigen

I’ve been using zsh for a while, with oh-my-zsh to add a pile of new features to it. Oh-my-zsh is great, and has a lot of useful things in it, but I found it a bit of a pain to keep my fork of it in sync with the main repository and another fork that I’d stolen things from. The fact that it was one giant repository with everything in there didn’t seem quite right to me. Then, I came across…

PHP room at FOSDEM 2013

I’ve been intending to go to FOSDEM for a few years now, but so far I’ve never quite got around to making it. This year, though, Lorna asked me if I was up for helping to run the PHP devroom. I said yes, and so this year I will be there! There are calls for papers open for the main track and lightning talks, which you can find on the FOSDEM site . We’d also like to see submissions for talks in the…

Why one-line installers are a bad idea

There has been a trend in the last while for various bits of useful software to have a one-line shell command recommended as the installation method. The usual form of this is to pipe something like curl or wget to some interpreter, be it bash , php , ruby , or some such. They look like this (taken from RVM’s installation page ): curl -L https://get.rvm.io | bash -s stable --ruby RVM is…

New Toys

For someone who hardly ever actually writes anything, I do spend quite a long time messing about with the software that powers my site. I think over the years I’ve variously used WordPress , eZ Publish , Habari , and probably other things that I’ve forgotten to run a weblog but never actually use it. Welcome to the latest incarnation, which this time is powered by Jekyll . I decided that running a…

PECL/Cairo 0.3.0 released!

As I’m sure you’ve all been longing to hear, we’ve finally got around to releasing a new version of PECL/Cairo ! This version fixes some bugs, and adds support for some new features available since Cairo 1.10 — notably, support for subsurfaces, which are surfaces that draw onto a part of a larger surface, and for recording surfaces, which record all drawing operations and can then be used as…

FrOSCon 2011

I’m very pleased to be able to announce that I’ll be giving two talks at this year’s FrOSCon conference in St Augustin near Bonn in Germany, on the 20th and 21st of August. The first is on the PHP track , and is an overview of the PECL/Cairo extension for PHP. The second talk is on the main track, and is about Making Software See , where I’ll give an introduction to the OpenCV image…

Pango for PHP PECL channel

It occurs to me that though I wrote an introduction post about Pango for PHP , I forgot to mention that it’s actually installable using the PECL installer. pecl channel-discover pecl.mgdm.net pecl install channel://pecl.mgdm.net/Pango-0.1.0 Assuming you have the required development packages installed, it should go off and install it. You may still need to add the extension=pango.so…

Android: LinearLayouts, WebViews and black screens

Just making a quick note in case anyone else is searching for the same problem. I have an app with an activity which previously was just a WebView, but I wanted to add some other widgets above the WebView as well, so I made an XML layout and wrapped the WebView in a LinearLayout. Upon using this as the content view, my WebView went black. Completely. This resulted in a bit of frantic Googling,…

Using Pango for PHP: a taster

The PECL/Cairo library is pretty good at drawing vector graphics (in our opinion, as the developers, at least!), but one thing it’s not able to do by itself is draw text with mildly advanced layout. It has the CairoContext::showText() function, but that doesn’t really let you do anything GD can’t. That’s because the developers of the Cairo library decided to let another more specialised…

libsureelec, a driver for Sure Electronics LCD displays

A few months ago I got a pair of 4x20 LCD displays from Sure Electronics, via eBay. Though they worked quite happily through LCDproc, I didn’t really want to use that (as I intend to use one of them on a Bifferboard ). To that end, I’ve attempted to write a driver for them. Until recently I didn’t have a lot of success, which made me think that the documentation provided with the device was…

CMSes: an update

My previous post was typed in a bit of a hurry (was it that obvious?) and could probably have done with a few more sarcasm tags, though I think I still have a valid, if small, point. It surprised me that these well-maintained projects seem to be content to run with what I would consider to be errors. Though they do run, otherwise nobody would be using them. For what it’s worth, SilverStripe and I…

Where are all the decent PHP CMSes?

I’ve been recently asked to check out some CMSes for someone, and try to find a recommendation. What I’ve been finding hasn’t really been encouraging. Out of the several CMSes I’ve tried, they’ve all failed for various reasons. I admit that I might be looking at this from a slightly different perspective than most - that of admining it and coding against it, rather than as a user - but it’s still…

Habari plugins published

I’ve just committed two new plugins to the habari-extras Subversion. Firstly, there’s the ‘share’ plugin, which adds the Facebook OpenGraph metadata to pages so that the Like button works, and also adds Facebook and Twitter widgets to the bottom of posts. Secondly, there’s a bitly plugin, that pings bit.ly’s API when every post is published and generates a short URL. This URL is then stored in the…

Recent activity: Habari plugins

I think I’m just about keeping to this one-post-a-week thing, almost. I’ve recently been playing with the internals of Habari, writing a couple of plugins. I’ve found it quite well put together, though I don’t seem to ever get the Utils::debug() output to display properly - though this might have been due to the code I was writing running before a redirect. I believe though that I now have got 2…

2011, now with less tumbleweed

It’s my intention this year to at write at least one post on here per week, ideally with some substance to it, rather than just recording what I had for breakfast (that being Twitter’s job, after all). I’m not holding my breath about whether I will manage it or not, but I intend to give it a go. I have a draft in the works, which I will hope to get out there some time soon… In actual news, I have…

Cairo talk feedback from DPC10

I noted a couple of comments after my talk on Cairo at DPC 10 yesterday, so I thought I’d respond to them here to clear up what’s going on. It’s always good to get some feedback about something I’ve been working on so I’d like to reply and keep the conversation going if I can. First off, someone mentioned that the wrapper seems a bit beta and incomplete - and yes, that is true. The 0.2.0 release,…

Ubuntu Accessibility team

Recently I’ve become involved in a move to resurrect the Ubuntu Accessibility team, which seemed to have stagnated until quite recently when Penelope Stowe got involved and suggested I joined too. She arranged a session at the Ubuntu Developer Summit for the next Ubuntu release, Maverick Meerkat, which seems to have gone quite well . The main focus for the team right now is getting organised, and…

EuroWinPHP contest

This year I’ve decided to enter the EuroWinPHP contest, as I figured it might be interesting to learn a bit more about how PHP works on Windows. I originally started using it there, back in around 2002, running early versions of Apache 1.3 and PHP 4.1 on Windows 98 and 2000. These days, though, I’m running IIS7 and PHP 5.3.2, and have a bit more knowledge of how the bits fit together, though since…

Handling fonts in PECL/Cairo

(This is just a quick note to get some information out there for reference, I am adding it to the PHP manual as well!) Currently, in PECL/Cairo the only way to draw text is the referred to as the “toy” text API, which is a very basic way of handling text compared to the facilities available in the Cairo library itself. However, it’s sufficient for most purposes that I’ve come across so far.…

Speaking at DPC10

I’m happy to say that I’ll be speaking at the Dutch PHP Conference in June in Amsterdam, on the subject of the PECL/Cairo extension I’ve been helping out by working on for the past few months. This will be my first appearance as a speaker at a technical conference so I’m a little nervous, but I’ve no doubt I’ll be practicing a bit before it happens. Apologies in advance to anyone I inflict…

PECL/Cairo 0.2.0 released

The first beta version of the PECL/Cairo extension has just been released. This version includes support for loading arbitrary fonts via Freetype, cloning matrices, and has a rather large set of bug fixes. If you’ve been using 0.1.0 for anything at all I’d really recommend an upgrade. Windows builds will appear soon over at perisama.net for all the major PHP variants courtesy of Elizabeth M.…

Cairo article published

I’ve got 3 posts or so queued up in my mind to write out, but some of them rather depend on doing other things first, so this will just be a quick note to say I have an article in the most recent php|architect magazine on the subject of “Vector Graphics with Cairo”. This is a basic introduction to the PECL/Cairo extension which I’ve been helping out on for a while now. Thanks to Keith Casey…

A brief update

Last weekend I spent a couple of days on the yacht Hebridean as part of an RYA sail cruising day skipper course . This was the second half, as we were aboard before last month but had to cancel due to the weather. This time, we combined the course with delivering the yacht to Oban Marina on Kerrera where it will spend the winter. I’m happy to say I passed, so theoretically at least I could be able…

Debug of the year

I saw this article on the BBC, where a man who bought a packet of cigarettes from a petrol station in the US ended up being charged $23,148,855,308,184,500 instead. Wow. I was a little curious as to how this could have happened, though the number didn’t look familar - I know roughly what 2^32, 2^32 / 2, 2^64, 2^64 / 2 look like, and this didn’t appear to be any of those. A swift Google…

PECL/Cairo 0.1.0 released

The first alpha of the PECL Cairo extension I’ve been helping out with has been released. Please download it, play with it, try and break it, and file bugs if you do! There isn’t an official manual yet (for licencing-related reasons which I’m hoping to sort out soon), but I’ll update this post when there is one. For now, there is a lot of stuff in the examples/ directory in the source which…

What I've been up to

I finally decided to get around to doing something about my site, so I’ve made a front page for it which is better than a straight redirect onto the blog. Hopefully it’s reasonable. I’ve been learning a bit more recently about the internals of PHP, and how to write extensions for it. I’ve been practicing by doing a bit of work on a Cairo wrapper that was started in the Google Summer of Code last…

PHP 5.3.0RC2

PHP 5.3.0RC2 has been released , which means that the next version of PHP is just around the corner. It comes right in the middle of the annual PHP Testfest . I rambled on a bit on the Freenode podcast a couple of weeks ago about this - it’s an annual project where PHP usergroups and individuals around the world get together to improve the unit testing of PHP. This has benefits for everyone…