Skip to content

Instantly share code, notes, and snippets.

View aw's full-sized avatar

Alex Williams aw

View GitHub Profile
@aw
aw / explain.md
Last active April 28, 2024 10:05
[SOLVED] Proxmox VE and cloud-init snippets etc

Proxmox VE 6.x release includes a feature to add custom cloud-init configs. Unfortunately there is poor documentation, so I had to figure this out by adding pieces of information together.

The custom cloud-init files (user-data, meta-data, network-config)

The cloud-init files need to be stored in a snippet. This is not very well documented:

  1. Go to Storage View -> Storage -> Add -> Directory
  2. Give it an ID such as snippets, and specify any path on your host such as /snippets
  3. Under Content choose Snippets and de-select Disk image (optional)
  4. Upload (scp/rsync/whatever) your user-data, meta-data, network-config files to your proxmox server in /snippets/snippets/ (the directory should be there if you followed steps 1-3)
@aw
aw / haproxy-db.conf
Created July 8, 2011 04:29
HAProxy configuration for MySQL failover and redundancy
# HAProxy configuration - haproxy-db.cfg
##
## FRONTEND ##
##
# Load-balanced IPs for DB writes and reads
#
frontend db_write
bind 172.16.0.50:3306
@aw
aw / gist:1008793
Created June 5, 2011 08:38
Simple ip_nonlocal_bind IPv6 workaround
#! /bin/sh
#
## Tested on Linux Debian 5.0 (Lenny)
#
# OK I know this is nothing new/special.
# If you've always configured your LBs a certain way, you might have to use this method instead.
#
# Scenario: High-availability setup with 2 HAProxy/Keepalived load-balancers on IPv6
#
# Problem: HAProxy won't start (cannot bind socket) because the virtual IPv6 address is not assigned
@aw
aw / mongodb-invariant-failure.md
Created March 30, 2017 06:42
[SOLUTION] MongoDB aborting after invariant() failure

I recently ran into an issue of MongoDB shell commands not working. The error message was:

Invariant failure !driverName.empty() && !driverVersion.empty() && !osType.empty() && !osName.empty() && !osArchitecture.empty() && !osVersion.empty() src/mongo/rpc/metadata/client_metadata.cpp

I ran an strace on the mongo command and saw it was trying (and failing) to open the following files:

@aw
aw / http-patch.l
Created November 5, 2017 09:43
Monkey-patch PicoLisp http.l
(patch _htHead
'(case (lowc (till " ^M^J" T)) @S)
(fill '(case (lowc (till " ^M^J" T))
("auth-hash:" (setq *AUTH_HASH (pack (cdr (line)))))
("auth-cookie:" (setq *AUTH_COOKIE (pack (cdr (line)))))
("auth-token:" (setq *AUTH_TOKEN (pack (cdr (line)))))
. @S) ) )
@aw
aw / sram.rs
Last active March 8, 2021 03:29
Rust embedded driver for Microchip 23x SRAM/NVSRAM - https://blog.a1w.ca/p/rust-embedded-driver-microchip-23x-sram/
#![no_std]
#![no_main]
use panic_halt as _;
use embedded_graphics::fonts::{Font12x16, Text};
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::Rectangle;
use embedded_graphics::{primitive_style, text_style};
@aw
aw / mysqlchk_status.sh
Created July 8, 2011 04:28
Check if a MySQL server is healthy
#!/bin/bash
#
# This script checks if a mysql server is healthy running on localhost. It will
# return:
#
# "HTTP/1.x 200 OK\r" (if mysql is running smoothly)
#
# - OR -
#
# "HTTP/1.x 500 Internal Server Error\r" (else)
@aw
aw / bitmap64.l
Last active November 9, 2020 08:44
Fast'ish bitmap ops (population count, set/clear/toggle bit) in PicoLisp
#!/usr/bin/env pil
# 64-bit max
#
# functions to set/clear/toggle a specific bit in an 64-bit integer (8 bytes)
[de lpad (Int)
(pad 64 (bin Int) ]
[de getbit (Int Pos)
(& 1 (>> Pos Int) ]
@aw
aw / twos-complement.md
Created October 12, 2020 09:42
Twos complement and reverse in PicoLisp

This obtains the twos complement of a signed integer (from signed -> unsigned), or reverse (from unsigned -> signed)

  • Int: an positive or negative integer
  • Size: expressed in bits (ex: 8, 16, 32, 64...)
(de twos-complement (Int Size)
  (if (lt0 Int)
      (+ Int (>> (- Size) 1))
      (if (=0 (& Int (>> (- (- Size 1)) 1)))
 Int
@aw
aw / posix_mq_attr.md
Last active September 15, 2020 03:03
mq_attr struct size is 64 bytes, not 32

Problem

When parsing with PicoLisp (native) and the mq_getattr() call, I kept seeing errors such as:

corrupted size vs. prev_size

or