Skip to content

Instantly share code, notes, and snippets.

@nrdmn
nrdmn / vsock-notes.md
Last active October 14, 2024 15:48
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 / 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);
}
}
@nrdmn
nrdmn / primes.hs
Last active September 15, 2019 13:17
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr)
import Data.List (genericTake)
import Text.Read (readMaybe)
-- sqrt possibly inaccurate for large primes.
primes = 2 : [ n | n<-[3,5..], all (\x -> n `mod` x /= 0) $ takeWhile (<= (floor $ sqrt $ fromIntegral n)) primes]
-- guaranteed to be correct for all primes, but much slower:
-- primes = 2 : [ n | n<-[3,5..], all (\x -> n `mod` x /= 0) $ takeWhile (<= (quot n 2)) primes]
-- for all n out of [1..] there's a prime p so that n < p < 2*n (Bertrand's postulate)