Skip to content

Instantly share code, notes, and snippets.

@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)
@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");
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
@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 / 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.

/**
* 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 / warp.c
Created September 13, 2019 12:46
#include <sys/time.h>
#include <stddef.h>
#include <stdio.h>
#define THRESHOLD 1000
int main()
{
struct timeval a;
struct timeval b;
@nrdmn
nrdmn / crash.c
Last active September 5, 2019 08:01
atop bug
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
#include <string.h>
#include <unistd.h>
#include <asm/unistd.h>
#include <stdio.h>
int main()
{
if (geteuid() != 0) {
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
, additionalFonts = []
, borderColor = "black"
, border = TopB
, bgColor = "black"
, fgColor = "grey"
, alpha = 255
, position = Top
, textOffset = -1
, iconOffset = -1