Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / summarize.c
Created March 5, 2023 20:44
P-square summary
View summarize.c
// 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;
@skeeto
skeeto / cmd.c
Created February 27, 2023 05:04
libtool-compatibility cmd.exe wrapper
View cmd.c
// libtool-compatibility cmd.exe wrapper
// Converts libtool's Cygwin-style "cmd //c ..." to "cmd /c ..."
// $ cc -nostartfiles -o cmd.exe cmd.c
// This is free and unencumbered software released into the public domain.
#define MAX_PATH 260
#define COUNTOF(a) (int)(sizeof(a) / sizeof(0[a]))
#define FATAL "cmd.exe (fake): CreateProcessW() failed\n"
#define CMDEXE "\\cmd.exe"
@skeeto
skeeto / example.c
Created February 22, 2023 23:10
Infinite gamepad rumble on Windows
View example.c
// $ cc -nostartfiles example.c
// $ cl example.c /link /subsystem:console kernel32.lib
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <xinput.h>
struct gamepad {
void (*XInputEnable)(BOOL);
DWORD (*XInputSetState)(DWORD, XINPUT_VIBRATION *);
DWORD (*XInputGetState)(DWORD, XINPUT_STATE *);
@skeeto
skeeto / child.c
Last active February 16, 2023 20:35
Win32 piped child example
View child.c
// $ cc -nostartfiles -o child.exe child.c
// $ cl child.c /link /subsystem:console kernel32.lib
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int mainCRTStartup(void)
{
HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE);
HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
for (;;) {
View hin9.c
// $ cc -Isrc/hin -Isrc/system -Iexternal/basic/include \
// hin9.c -luring -lz $(pkg-config lua-5.3 --cflags --libs)
// Ref: https://gitlab.com/tiotags/hin9
// Ref: https://old.reddit.com/r/linux/comments/zl2vm1
#define _GNU_SOURCE
#define HIN_USE_CGI
#include "external/basic/basic_args.c"
#include "external/basic/basic_endianness.c"
#include "external/basic/basic_hashtable.c"
#include "external/basic/basic_lists.c"
View generator.c
// Generates a random city adjacency list
// Ref: https://old.reddit.com/r/C_Programming/comments/zgdxqr
// This is free and unencumbered software released into the public domain.
#include <stdio.h>
#include <time.h>
#define NCITIES 1000
#define NEDGES (NCITIES*10)
static int randint(unsigned long long *s, int n)
@skeeto
skeeto / make-w64devkit-iso.sh
Created December 6, 2022 17:18
Build an ISO image that runs a portable w64devkit
View make-w64devkit-iso.sh
#!/bin/sh
set -xe
dir="$(mktemp -d "${TMPDIR:-/tmp}/iso-XXXXXX")"
cleanup() {
rm -rf -- "$dir"
}
trap cleanup EXIT
todos >$dir/autorun.inf <<EOF
@skeeto
skeeto / vocab.c
Last active December 4, 2022 19:00
activity stream @vocab extractor
View vocab.c
// Find the @vocab element in an activity stream
// Ref: https://mccue.dev/pages/12-3-22-practical-advent
#include <string.h>
struct buf {
char *buf;
int len, off;
};
struct tok {
@skeeto
skeeto / randn.c
Last active November 19, 2022 16:24
Approximate Random Gaussian Generator
View randn.c
// Approximate Random Gaussian Generator
// $ cc -O3 -fopenmp -o randn randn.c -lm
// $ ./randn
// Ref: https://old.reddit.com/r/algorithms/comments/yyz59u
// This is free and unencumbered software released into the public domain.
#include <math.h>
#include <stdint.h>
#include <stdio.h>
struct kahan { double sum, err; };
@skeeto
skeeto / fuzz.c
Last active November 8, 2022 00:54
Jsonic fuzz tester
View fuzz.c
// Fuzz test for Jsonic
// $ afl-gcc -m32 -fsanitize=address,undefined fuzz.c jsonic.c
// $ afl-fuzz -m800 -iexamples/heroes -oout ./a.out
// https://github.com/rohanrhu/jsonic
// This is free and unencumbered software released into the public domain.
#include <stdio.h>
#include <stdlib.h>
#include "jsonic.h"
static int explore(jsonic_node_t *root, char *buf)