Skip to content

Instantly share code, notes, and snippets.

@jart
jart / redbean-requirements.c
Last active Jul 1, 2021
redbean requirements for serenityos kernel
View redbean-requirements.c
/*
redbean: kernel requirements
x86-64 linux system five abi
rax name rdi rsi rdx r10 r8 r9
----- -------------- ------------------------ --------------------------- ------------------------------ -------------------------- ------------------------ ---------------
0x000 read unsigned int fd char *buf size_t count - - -
0x003 close unsigned int fd - - - - -
0x005 fstat unsigned int fd struct stat - - - -
0x007 poll struct pollfd *ufds unsigned int nfds int timeout -
View vpternlog.c
/**
* Example of how AVX512's FPGA-like VPTERNLOG instruction could
* be used to implement the other instructions in the x86 isa.
* Here we implement MMX PADDB. Due to the way we need to reshape
* the data, VPTERNLOG is probably most useful for huge datasets.
*/
uint64_t vpternlog(uint64_t a, uint64_t b, uint64_t c, uint64_t t) {
int i;
uint64_t r;
@jart
jart / reallz4.S
Created Jan 13, 2021
Tiniest lz4 block copier that's binary compatible with i8086 + i386 + x86_64
View reallz4.S
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
View rmsiface.txt
RMS NOTATION TUTORIAL
BEHAVIOR
=: write-only
+: read/writeable
&: earlyclobber (impacts register sharing, defensive copying, etc.)
%: commutative
,: groups alternative constraints
?: discourages group of constraints
@jart
jart / illumination.sh
Last active Mar 13, 2021
Rational Illumination for PC and TV w/ IBM Scratchpad
View illumination.sh
#!/bin/sh
fricas -nosman <<EOF
E := [_
-- Standard Illumination Model for Computers_
--_
-- Is defined as a system of linear equations, where negative_
-- colors don't exist and is solved by computing the point at_
-- which they all intersect the one which needs to be defined_
-- as the Planckian locus of the illuminant._
@jart
jart / defer.c
Last active Mar 8, 2021
Go-like defer for C that works with most optimization flag combinations under GCC/Clang
View defer.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
View printimage.c
/*bin/echo ' -*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;coding:utf-8 -*-┤
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ To the extent possible under law, Justine Tunney has waived │
│ all copyright and related or neighboring rights to this file, │
│ as it is written in the following disclaimers: │
│ • http://unlicense.org/ │
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
╚────────────────────────────────────────────────────────────────────'>/dev/null
if ! [ "${0%.*}.exe" -nt "$0" ]; then
@jart
jart / isort.c
Last active May 27, 2020
Simple macro that makes djbsort (crypto submission reference impl version) 40% faster and 10% smaller
View isort.c
/*bin/echo '───────────────────────────────────────────────────────╗
│ To the extent possible under law, Justine Tunney has waived │
│ all copyright and related or neighboring rights to this file, │
│ as it is written in the following disclaimers: │
│ • http://unlicense.org/ │
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
╚────────────────────────────────────────────────────────'>/dev/null
CC=${CC:-cc}
CFLAGS=${CFLAGS:--g -Wall -Werror -Os -fno-pie -march=native}
$CC $CFLAGS -o isort.o -c isort.c &&
View proxy.py
#!/usr/bin/env python2
import BaseHTTPServer
import SocketServer
import base64
import httplib
import mimetypes
import os
import shutil
import ssl
@jart
jart / fone.go
Last active Jun 6, 2020
Linux CLI Telephone in 300 lines of Go. This is a NAT traversing SIP user agent. It can hook into the PSTN via gateways like Flowroute. The keyboard can be used to send DTMF tones.
View fone.go
// To the extent possible under law, Justine Tunney has waived
// all copyright and related or neighboring rights to this file,
// as it is written in the following disclaimers:
// - http://unlicense.org/
// - http://creativecommons.org/publicdomain/zero/1.0/
package main
// #cgo pkg-config: ncurses libpulse-simple
// #include <stdlib.h>