Skip to content

Instantly share code, notes, and snippets.

View harrisonturton's full-sized avatar
🏠
Working from home

Harry Turton harrisonturton

🏠
Working from home
  • Canva
  • Sydney, Australia
View GitHub Profile
@harrisonturton
harrisonturton / Makefile
Last active January 29, 2024 11:30
Using libjxl to transcode a JPEG file into a JPEG-XL file
COPTS=-std=c++17 -Wall
INCLUDE=-I/usr/local/include/jxl/ -L/usr/local/lib/
LIBS=-ljxl -ljxl_threads
BIN=main
$(BIN): main.cc
clang++ $(COPTS) $(INCLUDE) $(LIBS) -o $@ $<
.PHONY: clean
clean:
@harrisonturton
harrisonturton / myfs.c
Last active July 17, 2023 13:51
Creating Linux virtual filesystems (LWN, 2003)
/*
* Author: Harrison Turton <harrisonturton@gmail.com>
*
* This follows the LWN article "Creating Linux virtual filesystems":
*
* https://lwn.net/Articles/57369/
*
* However, this was published in 2003. The VFS has changed quite a
* bit since then, and so the code had to be tweaked to work. So
* isn't a byte-for-byte copy, I had to go digging through the kernel
@harrisonturton
harrisonturton / kvm.c
Created July 17, 2023 13:45
Using the KVM API (LWN, 2015)
/*
* This follows the LWN tutorial "Using the KVM API":
*
* https://lwn.net/Articles/658511/
*
* Which runs a virtual machine that executes the following
* 16-bit x86 code (the assembled binary is hardcoded in):
*
* mov $0x3f8, %dx
* add %bl, %al
@harrisonturton
harrisonturton / tuntap.rs
Last active June 14, 2023 23:01
Persistent TUN/TAP device in Rust
use nix::errno::Errno;
use nix::fcntl::{open, OFlag};
use nix::ioctl_write_int;
use nix::libc::{__c_anonymous_ifr_ifru, c_char, c_short, ifreq, IFNAMSIZ};
use nix::sys::stat::Mode;
use nix::unistd::close;
use std::ffi::{CString, NulError};
use std::os::fd::RawFd;
use std::ptr::copy_nonoverlapping;
@harrisonturton
harrisonturton / database.rs
Last active June 2, 2022 03:31
Generic, async database trait for tokio-postgres
#![feature(generic_associated_types)]
use anyhow::Error;
use async_trait::async_trait;
use tokio_postgres::{row::Row, types::ToSql};
/// This is an example of how to abstract Rust database libraries (e.g. tokio-postgres)
/// behind a trait. This is useful to swap out a concrete implementation with a fake,
/// or for changing the underlying database implementation (e.g. switching to sqlx)
/// without needing to update the consumers of this module.
@harrisonturton
harrisonturton / queue.go
Last active June 14, 2023 14:58
RabbitMQ client that automatically reconnects when the connection fails, and has a confirmed push method (i.e. the server is guaranteed to recieve the message)
package main
import (
"errors"
"github.com/streadway/amqp"
"log"
"os"
"time"
)
@harrisonturton
harrisonturton / auto_build.sh
Last active September 16, 2018 12:07
Script to autobuild COMP2310 Assignment 1. It automatically detects your OS, and allows you to easily set the build mode from the commandline.
#!/bin/bash
# Harrison Turton 2018
# --------------------------------------
# This script will automatically detect your
# operating system, and build accordingly.
#
# A build mode flag can be included, wherein
# the script will supply the relevant build
# mode flags to gnatmake. Defaults to
Verifying my Blockstack ID is secured with the address 1MyqUD58TPzSG1ib1zKdruZVSohii2wnBC https://explorer.blockstack.org/address/1MyqUD58TPzSG1ib1zKdruZVSohii2wnBC