Skip to content

Instantly share code, notes, and snippets.

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

Geoffrey McRae gnif

🏠
Working from home
View GitHub Profile
@gnif
gnif / bytesToHR.sh
Created November 3, 2018 01:50
[BASH] Convert bytes to human readable
function bytesToHR()
{
local SIZE=$1
local UNITS="B KiB MiB GiB TiB PiB"
for F in $UNITS; do
local UNIT=$F
test ${SIZE%.*} -lt 1024 && break;
SIZE=$(echo "$SIZE / 1024" | bc -l)
done
@gnif
gnif / notes.md
Last active January 29, 2022 22:02
IBM branded APC SmartUPS 3000VA Notes

These are notes on modifications to make to the IBM branded 2RU APC SmartUPS 3000VA UPS to make it operate as a hybrid solar inverter/ups.

Disable the charging circuit

Since I am charging from solar I do not want the UPS to be able to charge the externally attached battery array, on this model this is very simply done by inserting a diode on the RED and BLACK wires coming from the front of the ups (charging module) to J4 on the main PCB to prevent reverse current flow to the batteries. The diode is required or the charging module wont be powerered at startup which puts the unit into a fault mode.

Coltrolling the output

Initially I was using a solid state relay to disconnect the feed in to the UPS when I was getting enough power to charge the batteries and run my equipment from solar, however this has been causing issues with RCDs (residual current devices) due to the massive inrush current when the UPS is re-connected to the supply. As such I have reverse engineered enough of the circuit to understa

@gnif
gnif / README.md
Created August 13, 2020 03:30
Generate the hex route rule for DHCP (pfSense)

Usage is simple:

./gen.sh 192.168.10.0/24 192.168.10.1

Results:

192.168.10.0/24 via 192.168.10.1 = 18:c0:a8:0a:00:c0:a8:0a:01

@gnif
gnif / vega-10-reset.c
Last active July 2, 2020 10:02
Experimental NON FUNCTIONAL vega 10 reset
static int reset_amdgpu_vega(struct pci_dev *dev, int probe) {
#define AMDGPU_MAX_USEC_TIMEOUT 100000
#define MP0_BASE 0x16000
#define mmMP0_SMN_C2PMSG_33 ((MP0_BASE + 0x0061) * 4)
#define mmMP0_SMN_C2PMSG_64 ((MP0_BASE + 0x0080) * 4)
#define mmMP0_SMN_C2PMSG_81 ((MP0_BASE + 0x0091) * 4)
resource_size_t rmmio_base, rmmio_size;
void __iomem *rmmio;
int ret;
@gnif
gnif / qemu-pcie-nasty.patch
Created October 7, 2018 00:11
Nasty/hacky QEMU patch to enable PCIe x 16 Gen 3.0 for Qemu VFIO
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 6c91bd44a0..f3c7b9d328 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -39,6 +39,166 @@
#define PCIE_DEV_PRINTF(dev, fmt, ...) \
PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__)
+static uint16_t pcie_link_max_width(PCIDevice *dev)
+{
@gnif
gnif / Makefile
Last active January 12, 2020 06:12
Proof of concept: Create Pixmap via DRI3 from shared memory via udmabuf
all:
gcc -D_GNU_SOURCE main.c -Wall -Werror -g -Og -o test -lX11-xcb -lX11 -lxcb -lxcb-dri3 -lxcb-present
@gnif
gnif / main.c
Last active January 1, 2020 20:42
Example X11 application that uses XGetFrame to capture an application window.
/*
Example X11 application that uses XGetFrame to capture an application window.
Copyright 2020 Geoffrey McRae <geoff@hostfission.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@gnif
gnif / clustercheck.sh
Created December 19, 2019 15:44
HAProxy Galera Monitor Script
#!/bin/bash
#
# Script to make a proxy (ie HAProxy) capable of monitoring Galera Cluster nodes properly
# Updated by Geoffrey McRae to check for MySQL command failure, and renamed to 'Galera Cluster'
#
# Author: Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
# Author: Raghavendra Prabhu <raghavendra.prabhu@percona.com>
# Author: Geoffrey McRae <geoff@hostfission.com>
#
# Documentation and download: https://github.com/olafz/percona-clustercheck
@gnif
gnif / main.c
Last active October 31, 2019 11:52
Example client for the new zero-copy shared ram device @ https://github.com/gnif/qemu/blob/master/hw/misc/porthole.c
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/stat.h>
typedef struct {
@gnif
gnif / example-usage.sh
Last active October 6, 2019 06:18
Some bash helper functions for launching QEMU guests directly
#!/bin/bash
source vm-helpers.sh
NODE=1
RAM=16
allocateRAM $NODE $RAM
unbindConsole
takeDevByName "\[AMD/ATI\] Navi 10 (rev c1)" 1