Skip to content

Instantly share code, notes, and snippets.

@ktprograms
ktprograms / README.md
Last active April 1, 2022 10:17
Swift program that connects to the QEMU Guest Agent on a localhost TCP socket and runs guest-set-time to re-sync the Guest Time after the Host wakes from sleep.

How to use this

Steps before launching the VM

  1. Open the VM Configuration
  2. Go to the QEMU tab and scroll to the bottom.
  3. Click on the text box with the grey text New...
  4. Paste these two lines into it:
-chardev socket,port=4321,host=127.0.0.1,server,nowait,id=qga0
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0

Steps to GHC + Shellcheck on Alpine Arm64

This is everything I had to do in order to get a working GHC running on Alpine aarch64, which I could then use to bootstrap cabal-install and compile shellcheck. I will be compiling GHC 8.10.7 because (a) cabal-install doesn't support GHC 9.x, and (b) there seems to be a linker bug on GHC 9.x.

Note: I am using doas in these instructions (except when in the chroot), but feel free to replace it with sudo

Here's a brief overview of the steps needed:

@ktprograms
ktprograms / qemu-binfmt
Last active October 27, 2021 08:29
OpenRC init script that adds qemu binfmt_misc entries. Modified version of https://github.com/jirutka/qemu-openrc/blob/master/qemu-binfmt.initd
#!/sbin/openrc-run
i386_magic="\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00"
i386_mask="\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
x86_64_magic="\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00"
x86_64_mask="\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'
arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
@ktprograms
ktprograms / Base85.kt
Last active November 23, 2020 09:37
Kotlin Base85 (Ascii85) encoder/decoder. Doesn't add the <~ and ~> at the start and end.
import kotlin.math.pow
object Base85 {
// Data class to represent the 5 output values of the base85 / ascii85 encoding
private data class Block(val a: UInt, val b: UInt, val c: UInt, val d: UInt, val e: UInt)
// Encode a ByteArray to a Base85 / Ascii85 String
fun encode(arr: ByteArray): String {
var final = ""
for (x in arr.indices step 4) {