Skip to content

Instantly share code, notes, and snippets.

@nrdmn
nrdmn / vsock-notes.md
Last active August 16, 2026 11:57
vsock notes

vsock notes

about vsocks

Vsocks are a means of providing socket communication (either stream or datagram) directly between VMs and their host operating system. The host and each VM have a 32 bit CID (Context IDentifier) and may connect or bind to a 32 bit port number. Ports < 1024 are privileged ports.

@nrdmn
nrdmn / colors.sed
Created August 11, 2019 20:52
ANSI colors to IRC colors
s/\x1b\[0m/\x0f/g
s/\x1b\[1m/\x02/g
s/\x1b\[30m/\x031/g
s/\x1b\[31m/\x035/g
s/\x1b\[32m/\x033/g
s/\x1b\[33m/\x037/g
s/\x1b\[34m/\x032/g
s/\x1b\[35m/\x036/g
s/\x1b\[36m/\x0310/g
s/\x1b\[37m/\x0315/g
@nrdmn
nrdmn / gist:9bed16155eabe57cfe665173f45a4d2b
Last active July 29, 2024 23:10
NetBSD Pi Hole Howto
/etc/localtime:
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime
/etc/rc.conf:
inetd=NO
postfix=NO
named=YES
@nrdmn
nrdmn / ipcollapse.py
Last active February 9, 2024 13:57
collapse a list of IP addresses
#!/usr/bin/python3
# reads a list of IP subnets in CIDR notation from stdin and collapses it
import sys
import ipaddress
subnets6 = []
subnets4 = []
input_list = sys.stdin.readlines()
@nrdmn
nrdmn / ws2812.s
Last active November 6, 2021 16:56
ws2812 for avr, 16 MHz. follows gcc abi, restores interrupts if necessary. 64 bytes.
.equ PORTB, 5
; void ws2812(const char *ptr, const size_t n);
.global ws2812
ws2812:
; Move ptr (r24, r25) to X (r26, r27)
movw X, r24
; Move n (r22, r23) to r24, r25
movw r24, r22
@nrdmn
nrdmn / fcntl.c
Created November 28, 2020 12:54
LD_PRELOAD and varargs
#define _GNU_SOURCE
#include <dlfcn.h>
#include <fcntl.h>
int fcntl(int fd, int cmd, ...)
{
if (cmd == F_OFD_SETLKW || cmd == F_OFD_SETLK) {
return 0;
}
int (*orig)(int, int, ...) = dlsym(RTLD_NEXT, "fcntl");
@nrdmn
nrdmn / cc-wrapper.c
Last active December 23, 2020 21:37
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <ctype.h>
void unescape(char *buf)
U-Boot 2009.08 (Sep 27 2011 - 09:33:22)
CPU: Freescale i.MX50 family 1.1V at 800 MHz
mx50 pll1: 800MHz
mx50 pll2: 400MHz
mx50 pll3: 216MHz
ipg clock : 66666666Hz
ipg per clock : 66666666Hz
/**
* Apply a function which produces an array to all of an array's elements and concatenate the results.
*
* @param callable $func The function to be applied to every of $arr's elements to produce a new array each.
* @param array $arr
* @return array
*/
function array_flatmap(callable $func, array $arr) : array
{
return array_merge([], ...array_map($func, $arr));
@nrdmn
nrdmn / peano.zig
Last active September 16, 2019 22:34
Pointer Arithmetic
const std = @import("std");
fn Add(comptime A: type, comptime B: type) type {
if (A == type) {
return B;
} else {
return Add(@typeInfo(A).Pointer.child, *B);
}
}