Skip to content

Instantly share code, notes, and snippets.

@tautologicc
tautologicc / wb_alloc.h
Created September 22, 2023 18:43 — forked from WilliamBundy/wb_alloc.h
A single-file header allocation library for C (probably bugs out in C++, sorry)
/* This is free and unencumbered software released into the public domain. */
/* Check the bottom of this file for the remainder of the unlicense */
/* wb_alloc.h
*
* Three custom allocators that can (hopefully) safely allocate a very large
* amount of memory for you. Check the warnings below for an explanation
*
* Version 0.0.1 Testing Alpha
*/
<!DOCTYPE html>
<html lang="pt">
<title>Flordle</title>
<style>
:root {
--cell-size: 64px;
--cell-gap: 8px;
}
*,
@tautologicc
tautologicc / git-bump
Last active August 6, 2023 01:36
Bump a project version.
#!/bin/sh
# git-bump <command> - bump a project version
USAGE="[init|major|minor|patch|premajor|preminor|prepatch]"
SUBDIRECTORY_OK=1
. "$(git --exec-path)/git-sh-setup"
set -eu
@tautologicc
tautologicc / pre.css
Created January 15, 2023 16:41
Simple presentations in HTML
.slide {
border: 1px solid currentColor;
break-before: always;
display: flex;
flex-direction: column-reverse;
margin-bottom: 3rem;
margin-top: 3rem;
max-width: 35rem;
padding: 3rem;
}
@tautologicc
tautologicc / coro.c
Last active December 18, 2022 02:50
Reentrant coroutines in C, using Duff's device
#include <stdio.h>
// Adapted from https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
#define CORO_BEGIN(state) \
switch (*(state)) { \
case 0:
#define CORO_YIELD(state, value) \
do { \
@tautologicc
tautologicc / README.md
Created December 4, 2022 21:27 — forked from lithdew/README.md
Differences between Linux and Mac for sockets.
  1. A listening socket blocked on accept() can be unblocked by calling shutdown(socket_fd, SHUT_RD) on Linux. On Mac, calling shutdown(socket_fd, SHUT_RD) on a listening socket that is blocked on accept() will return an error ENOTCONN. To unblock a listening socket blocked on accept() on Mac requires calling close(socket_fd), which will cause the blocking accept() call to return an error EBADF.

Therefore, in order to unblock a socket on accept() on both Mac/Linux, shutdown() should not be relied on. Rather, an async cancellation scheme (such as cancellation tokens in .NET) should be used instead to unblock the call to accept().

  1. When a socket is instantiated and subsequently registered to epoll, or when a socket is shut down (via. shutdown() or setsockopt(SO_LINGER)) on Linux, epoll will be notified with EPOLLHUP on the socket. On Mac, kqueue will only notify when a socket is shut down (via. shutdown() or setsockopt(SO_LINGER)) by sending a EV_EOF notification on filters EVFILT_READ, and EVFILT_WRITE.

Thi

@tautologicc
tautologicc / .zshrc
Last active October 31, 2023 15:25
Start ssh-agent, with Apple keychain support
if [ "$(uname)" = Darwin ]; then
alias ssh-add='ssh-add --apple-use-keychain'
fi
export SSH_ENV="$HOME/.ssh/env"
if [ -e "$SSH_ENV" ]; then
. "$SSH_ENV"
fi
@tautologicc
tautologicc / x11_forwarding_macos_docker.md
Created November 7, 2022 01:00 — forked from sorny/x11_forwarding_macos_docker.md
X11 forwarding with macOS and Docker

X11 forwarding on macOS and docker

A quick guide on how to setup X11 forwarding on macOS when using docker containers requiring a DISPLAY.

This guide was tested on:

  • macOS Catalina 10.15.4
  • docker desktop 2.2.0.5 (43884) - stable release
  • XQuartz 2.7.11 (xorg-server 1.18.4)

Step-By-Step Guide

@tautologicc
tautologicc / oss.md
Last active November 12, 2023 14:43
@tautologicc
tautologicc / paren.c
Last active May 29, 2022 17:27
C program that verifies that every opening parenthesis is followed by a closing one
// SPDX-License-Identifier: CC0
extern int write();
int
main(int argc, char *argv[])
{
if (argc < 2) {
static char usage[] = "usage: paren STRING\n";
write(2, usage, sizeof usage);
return 2;