Skip to content

Instantly share code, notes, and snippets.

@deadpixi
deadpixi / thebe.c
Last active January 14, 2024 18:26
An insertion-order-preserving hash table in C, as part of the Thebe scripting language (which I will eventually get around to finishing).
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "thebe.h"
/*** TODO
* - switch tables to use uint32_t indexes; that's big enough for anybody, maybe even consider using
#!/usr/bin/env python3
import sys
from typing import Dict, List, Optional
class Game:
def __init__(self, initial_location: "Room") -> None:
self.location: Room = initial_location
self.inventory: Dict[str, Item] = {}
@deadpixi
deadpixi / keys.py
Last active October 21, 2022 15:24
A minimal set of input key sequences that covers a wide variety of terminals...
{'kcub1': {'\\E[217z', '\\EOD', '\\E[D', '\\ED'},
'kcud1': {'\\EB', '\\E[221z', '\\E[B', '\\EOB'},
'kcuf1': {'\\EC', '\\E[219z', '\\EOC', '\\E[C'},
'kcuu1': {'\\EOA', '\\E[A', '\\E[215z', '\\EA'},
'kend': {'\\EF',
'\\EOF',
'\\E[146q',
'\\E[220z',
'\\E[4~',
'\\E[8~',
@deadpixi
deadpixi / uuid4-apljk.md
Last active October 15, 2022 14:58
UUIDv4 in three different array languages.

UUIDv4 Generation in Three Different Array Languages

Here we see the same UUIDv4 generation function written in three different APL(-like) languages: APL, J, and K.

The algorithm is very simple, but one that lends itself well to implementation in an array language:

  • Generate a list of 36 random numbers between 0 and 15.
  • Transform each of those digits into a single-character string of the corresponding hex digit.
  • Join those characters together into a 36-character string.
  • Replace some of the characters with dashes.
  • Replace the character representing the version nybble with 4 (to indicate a version 4 UUID).
  • Constrain the character whose top two bits represent the variant to one that indicates the UUID is an RFC4122 UUID.
@deadpixi
deadpixi / uuid.rexx
Last active August 12, 2022 06:00
A UUIDv4 generator in REXX.
/* A UUIDv4 generator.
* By rob@frigidriver.com
* This should work with any ANSI REXX interpreter,
* and I *think* it would work with ARexx, but I
* haven't checked.
*/
/* Store the 16 bytes of random data in a string called bits
* We will populate this using either using the RANDOM function
* or by reading from /dev/random, whichever the user requests.
@deadpixi
deadpixi / rxring.c
Last active August 29, 2015 14:26 — forked from giannitedesco/rxring.c
TPACKET_V3 mmap packet sockets, showing off flexible frame sizes and multi-process hash fanout
/* Copyright (c) 2013 Gianni Tedesco
* Released under the terms of the GNU GPL version 3
* mmap() packet socket transmission
*/
#ifndef __linux__
#error "Are you loco? This is Linux only!"
#endif
#include <stdio.h>