Skip to content

Instantly share code, notes, and snippets.

View mildsunrise's full-sized avatar
🦊
*rolls*

Alba Mendez mildsunrise

🦊
*rolls*
View GitHub Profile
@mildsunrise
mildsunrise / kleene.py
Last active September 30, 2023 15:55
Kleene's algorithm for regexes
from typing import TypeVar, Optional
from collections import defaultdict
S = TypeVar('S') # state node
def kleene_algorithm(out_edges: dict[Optional[S], dict[Optional[S], str]]) -> str:
''' calculates a regular expression that is equivalent to the NFA given by `out_edges`.
`out_edges` describes the possible transitions, indexed first by source node and then by destination node.
a transition is an input symbol in the form of a regex, but it's not limited to a single symbol -- any
@mildsunrise
mildsunrise / perspective.ts
Last active September 30, 2023 09:01
use WebGL to apply a perspective transform to an image
function assertNotNull<T>(x: T | null, message?: string): T {
if (x === null)
throw Error(message ?? 'unexpected null')
return x
}
const vertexShader = `
precision mediump float;
attribute vec2 position;
@mildsunrise
mildsunrise / fnmt_handle.py
Last active September 19, 2023 09:11
🔐 Open source implementation of FNMT's certificate configurator v1.0.1 (https://twitter.com/mild_sunrise/status/1585611873860440067)
#!/usr/bin/env python3
'''
Open source implementation of FNMT's certificate configurator v1.0.1
<https://www.sede.fnmt.gob.es/descargas/descarga-software/instalacion-software-generacion-de-claves>
No warranty provided; use this ONLY if you know what you're doing.
Usage: ./fnmt_handle.py <fnmtcr URL>
Fulfills the request indicated by the URL, sending request to answer operation as completed if there are no errors.
For the fnmtcr://request phase, the generated private key is written to "privkey.pem" in current directory.
@mildsunrise
mildsunrise / README.md
Last active September 13, 2023 09:47
OpenSCAD module for simple gears with round teeth

Simple module that makes gears with circular-shaped teeth. The gears maintain their shape even for extremely low teeth numbers up to 2. Parameters:

  • teeth: number of teeth.
  • step: width of one teeth (diameter of the circle).

Two gears produced with the same step will transfer movement, so one typically fixes a step for all the gears and varies teeth for each gear, which decides the radius and transfer ratio. Example:

@mildsunrise
mildsunrise / crossteaser.rs
Last active September 11, 2023 23:48
traverses the Cross Teaser state graph to calculate puzzle diameter
#![feature(new_uninit)]
use std::mem::MaybeUninit;
// node is stored as 5 bits * 8.
// for bit, the eight S4 elements are separated into sign and A4.
// the A4 are all stored together as a base 12 number (29 bits), and the 8 signs are stored
// together in a bitfield at the MSB part. this concentrates the "islands" of elements together
// and keeps actual RSS at pretty much the real graph size (~3.5GiB/set) despite the ~16GiB/set
// virtual memory allocated. note that to make the code simpler, node stores the elements in
@mildsunrise
mildsunrise / clear.py
Created July 17, 2012 16:06
"clear" command in Python
class clear:
def __call__(self):
import os
if os.name==('ce','nt','dos'): os.system('cls')
elif os.name=='posix': os.system('clear')
else: print('\n'*120)
def __neg__(self): self()
def __repr__(self):
self();return ''
@mildsunrise
mildsunrise / getPerspectiveTransform.mts
Last active June 24, 2023 15:42
portable / efficient JS version of OpenCV getPerspectiveTransform()
/**
* solve a 2x2 linear system, given its augmented matrix, in place.
* first 2 columns left unchanged.
*/
function solve2x2([ x, y ]: [number[], number[]]) {
let [ a, b, c, d ] = [ x[0], x[1], y[0], y[1] ]
const det = a * d - b * c
if (!det) throw Error('inversion failed')
const k = 1 / det
; (a *= k, b *= k, c *= k, d *= k)
@mildsunrise
mildsunrise / README.md
Last active May 27, 2023 02:18
🖥 Lightweight diskless VM with QEMU

🖥 Lightweight diskless VM with QEMU

This document describes a process to quickly setup a Linux VM for testing or kernel development.

The VM requires no disk image, instead it boots off a directory on the host (using virtiofs). This is:

  • more performant (no FS-in-FS overhead)
  • more convenient for experiments (both host and guest can modify files concurrently)
  • safer (no corruption* in case of kernel panic)
  • easier to set up
@mildsunrise
mildsunrise / document.tex
Last active May 5, 2023 13:07
My boilerplate LaTeX source file.
\documentclass[LANGUAGE,OPTIONS]{CLASS}
% encoding
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{babel}
% formatting and fixes
\frenchspacing
@mildsunrise
mildsunrise / crossteaser.py
Created April 30, 2023 13:51
definition of the Cross Teaser group
'''
definition of the Cross Teaser group, using my groups library:
<https://github.com/mildsunrise/finite-algebra>
the puzzle is tilted 45 degrees, with the front slots in *down right* direction.
crosses are assigned in clockwise order, starting from the upper cross:
0
7 1
6 . 2