Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / channel.py
Created Aug 8, 2020
Channels for asyncio
View channel.py
import asyncio
import collections
class Channel:
"""A channel is a tool for passing values between tasks.
The default channel is unbuffered, meaning that put() blocks until
there's a receiver on the other size to get(), creating a rendezvous
synchronization point between the two tasks.
@skeeto
skeeto / emacs-pcg32.patch
Last active Jun 14, 2020
PCG32 patch for Emacs
View emacs-pcg32.patch
Switch to a permuted congruential generator
Rather than try to detect and use whatever PRNG happens to be a
available on the system, just implement a PRNG in Emacs. This generator
is stronger, faster, and more reliable than any system-provided PRNG.
This implementation also works on all platforms supported by Emacs.
This is a mixture of GPL-licensed code and my own. To the extent that it
is possible, I hereby release my changes into the public domain.
---
@skeeto
skeeto / randu.c
Last active Jun 25, 2020
RANDU weakness demonstration
View randu.c
/* RANDU weakness demonstration
* $ cc -O3 randu.c -lm
* $ ./a.out | mpv --no-correct-pts --fps=60 -
* $ ./a.out | x264 --frames 720 --fps 60 -o randu.mp4 /dev/stdin
* Ref: https://en.wikipedia.org/wiki/RANDU
* Ref: https://nullprogram.com/blog/2017/11/03/
* Ref: https://nullprogram.com/video/?v=randu
* This is free and unencumbered software released into the public domain.
*/
#include <math.h>
@skeeto
skeeto / rooks.c
Last active May 22, 2020
Sliding Rooks solver and animator
View rooks.c
/* Sliding Rooks solution with animation
* $ cc -Ofast rooks.c
* $ ./a.out | mpv --no-correct-pts --fps=60 -
* $ ./a.out | x264 --fps=60 -o rooks.mp4 /dev/stdin
* Ref: https://possiblywrong.wordpress.com/2020/05/20/sliding-rooks-and-queens/
* Ref: https://nullprogram.com/video/?v=rooks
*/
#include <stdio.h>
static const unsigned char value_pal[] = {0x00, 0x67, 0x94, 0xff};
@skeeto
skeeto / x.c
Created May 9, 2020
Mystery obfuscated C program (by yours truly)
View x.c
/**** cc -Ofast x.c -lm && ./a.out | mpv --no-correct-pts --fps=60 --fs - ****/
#include<math.h>
#include<stdio.h>
#include<string.h>
#define L long
#define F float
#define T 4e-3f
#define X(x,y,z) 10*(y-x)
#define Y(x,y,z) x*(28-z)-y
#define Z(x,y,z) x*y-2.6666667f*z
@skeeto
skeeto / lorenz.c
Last active Jun 25, 2020
Lorenz system animation
View lorenz.c
/* Lorenz system animation
* $ cc -Ofast lorenz.c -lm
* $ ./a.out | mpv --no-correct-pts --fps=60 --fs -
* $ ./a.out | x264 --fps 60 --frames 3600 -o lorenz.mp4 /dev/stdin
* Ref: https://nullprogram.com/video/?v=lorenz
* Ref: https://nullprogram.com/blog/2017/11/03/
* Ref: https://nullprogram.com/blog/2018/02/15/
* This is free and unencumbered software released into the public domain.
*/
#include <math.h>
@skeeto
skeeto / walk3d.c
Last active Jun 25, 2020
3D random walker animation
View walk3d.c
/* 3D random walker animation
* $ cc -Ofast walk3d.c -lm
* $ ./a.out | mpv --no-correct-pts --fps=60 -
* $ ./a.out | x264 --fps 60 --frames 3600 -o walk3d.mp4 /dev/stdin
* https://redd.it/geka1q
* https://nullprogram.com/video/?v=walk3d
* This is free and unencumbered software released into the public domain.
*/
#include <math.h>
#include <stdio.h>
@skeeto
skeeto / read-password-w32.c
Last active Jul 5, 2020
Read UTF-8 passwords on Windows
View read-password-w32.c
/* UTF-8 console password prompt for Windows
* This is free and unencumbered software released into the public domain.
*/
#include <windows.h>
// Display prompt then read zero-terminated, UTF-8 password.
// Return password length with terminator, or zero on error.
static int
read_password(char *buf, int len, char *prompt)
{
@skeeto
skeeto / epidemic.c
Created Apr 26, 2020
Epidemic simulation
View epidemic.c
/* Epidemic simulation
* $ cc -Ofast -march=native epidemic.c -lm
* $ ./a.out | mpv --no-correct-pts --fps=60 -
* $ ./a.out | x264 -o simulation.mp4 --fps 60 --frames 2700 /dev/stdin
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@skeeto
skeeto / sandpiles.c
Created Apr 25, 2020
Sandpiles idenity calculator using AVX2 SIMD
View sandpiles.c
/* Sandpiles identity compute and render
* Many piles are processed in parallel using AVX2 and OpenMP.
*
* $ cc -O3 -march=native -fopenmp sandpiles.c
* $ ./a.out >identity.ppm
*
* $ cc -O3 -march=native -DANIMATE -DN=64 -DSCALE=16 sandpiles.c
* $ ./a.out | mpv --no-correct-pts --fps=20 -
*
* Ref: https://www.youtube.com/watch?v=1MtEUErz7Gg
You can’t perform that action at this time.