Skip to content

Instantly share code, notes, and snippets.

@btrask
btrask / dirhash.h.c
Last active May 24, 2023 23:02
dirhash directory hashing algorithm, still incomplete
// Copyright 2023 Ben Trask. MIT licensed.
/*
TODO
. Detect directory loops
. Option flags?
. Skip inaccessible files
. More error reporting?
. Count of files skipped
. UTF8 normalization
@btrask
btrask / c-repl
Last active April 24, 2023 20:20
Bash script for running an editor and C compiler in a loop
#!/usr/bin/bash
set -e
set -u
set -o pipefail
set -o noclobber
if [[ $# < 1 ]]; then
echo "Usage: $0 file.c"
exit 1;
@btrask
btrask / slicing.lua
Last active June 15, 2023 16:22
mpv script for extracting video clips
-- Based on https://github.com/Kagami/mpv_slicing
-- Written in 2015 by Kagami Hiiragi kagami@genshiken.org
--
-- To the extent possible under law, the author(s) have dedicated all
-- copyright and related and neighboring rights to this software to the
-- public domain worldwide. This software is distributed without any warranty.
--
-- You should have received a copy of the CC0 Public Domain Dedication along
-- with this software. If not, see
-- http://creativecommons.org/publicdomain/zero/1.0/.
@btrask
btrask / random_stream.c
Created April 7, 2023 20:26
Prints a wall of random hex digits. Looks kind of cool.
// Copyright 2023 Ben Trask. MIT licensed.
// Prints a wall of random hex digits. Looks kind of cool.
// Nostalgic for my days working on StrongLink.
// Uses authentic SHA-256 as a CSPRNG.
// Building:
// cc -std=c99 -Wall -Wextra -Werror -D_XOPEN_SOURCE=500 random_stream.c -lcrypto -o random_stream && ./random_stream
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@btrask
btrask / slowroll.js
Created August 17, 2016 12:25
A simple program to send a request and receive a response one byte at a time.
#!/usr/bin/env node
var net = require("net");
var tls = require("tls");
var urlmodule = require("url");
var url = urlmodule.parse(process.argv[2]);
var protocol = "https:" == url.protocol ? tls : net;
var socket = protocol.connect({
// Author: Ben Trask, 2015
// License: Public domain or CC0
// To compile: cc --std=c99 -Wall -Wextra -Werror -Wno-unused-parameter arg-parsing.c
/*
Recursive composition and argument parsing in C
Since I have my own philosophy of abstraction, and since argument parsing
is an eternal problem, and since the existing solutions in C I've seen
recently seemed disappointing:
// Copyright 2015 Ben Trask
// Provided under the same license as libuv.
/*
Usage:
$ cc -Wall -Wextra -Wno-unused-parameter ./2015-08-05-libuv-runloop-death.c -luv -lpthread -o 2015-08-05-libuv-runloop-death && ./2015-08-05-libuv-runloop-death
EOF - this is fine.
Dead - this should never happen!
2015-08-05-libuv-runloop-death: ./2015-08-05-libuv-runloop-death.c:101: main: Assertion `rc == 0' failed.