This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WriteProcessMemory demo | |
// $ cc -nostartfiles -o demo.exe demo.c | |
// $ cl demo.c /link /subsystem:console kernel32.lib | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#define countof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a))) | |
typedef unsigned char u8; | |
typedef signed int b32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Summarize a numeric sequence | |
// Ref: https://old.reddit.com/r/commandline/comments/11hw06b | |
// Ref: https://github.com/ahmedakef/summarize | |
// This is free and unencumbered software released into the public domain. | |
#include <float.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
double sum, err; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function hotpatch example | |
// $ gcc -nostartfiles -o hotpatch.exe hotpatch.c | |
// $ clang -nostdlib -Wl,/subsystem:console -o hotpatch.exe hotpatch.c -lkernel32 | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <stdint.h> | |
#define W32 __attribute((dllimport, stdcall)) | |
W32 void *CreateThread(void *, size_t, void *, void *, int, int *); | |
W32 int FlushInstructionCache(void *, void *, size_t); | |
W32 void *GetStdHandle(int); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define countof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a))) | |
#define new(a, t, n) (t *)alloc(a, sizeof(t), n) | |
#define S(s) (str){(char *)s, countof(s)-1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ref: https://github.com/lionkor/logkeys-cleanup | |
#include <stdio.h> | |
typedef struct trie trie; | |
struct trie { | |
trie *child[256]; | |
_Bool terminal; | |
}; | |
static void insert(trie *t, char *word, trie **heap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stddef.h> | |
#include <stdlib.h> | |
#define new(a, t) (t *)alloc(a, sizeof(t)) | |
typedef struct { | |
char *beg; | |
char *end; | |
} arena; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* EnumSet benchmark | |
* $ javac Benchmark.java | |
* $ java -ea Benchmark | |
* Ref: https://nullprogram.com/blog/2021/04/23/ | |
*/ | |
import java.util.Arrays; | |
import java.util.EnumSet; | |
import java.util.HashSet; | |
import java.util.Set; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parse /proc/meminfo into a hash map | |
// This is free and unencumbered software released into the public domain. | |
#include <fcntl.h> | |
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Advent of Code 2023 Day 15 | |
// https://adventofcode.com/2023/day/15 | |
// https://nrk.neocities.org/articles/aoc23 | |
// This is free and unencumbered software released into the public domain. | |
#include <stddef.h> | |
#include <string.h> | |
#define assert(c) while (!(c)) *(volatile int *)0 = 0 | |
#define new(a, t, n) (t *)alloc(a, sizeof(t)*n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ cc -mwindows stretchdibits.c | |
#include <windows.h> | |
enum { | |
WIDTH = 1280, | |
HEIGHT = 720, | |
}; | |
static unsigned char *pixels; |