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 / sllv2tossl.c
Created February 27, 2024 23:30
converts an SLLv2 pcap into an SLL one (because tools like tcpflow and tcpreplay lack support for SLLv2 and it's maddening)
// compile with: clang -Wpedantic -Wall -Wextra $(pkg-config --cflags libpcap) sllv2tosll.c $(pkg-config --libs libpcap) -o sllv2tossl
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <pcap/pcap.h>
char error_buffer[PCAP_ERRBUF_SIZE];
@mildsunrise
mildsunrise / sa-is.hs
Last active February 26, 2024 14:25
Haskell implementation of SA-IS
{-# LANGUAGE TupleSections #-}
import Data.Array (accumArray, listArray, elems)
import Data.List.Extra (findIndices, groupSortOn, chunksOf)
import Data.Vector ((!), toList)
import Control.Monad (forM_, when, zipWithM)
import qualified Data.Vector as Vec
import qualified Data.Vector.Mutable as MVec
fill v = zipWithM (MVec.write v) [0..MVec.length v - 1]
@mildsunrise
mildsunrise / block.rs
Last active February 18, 2024 18:13
simple linked list allocator in Rust
use std::{mem, ptr};
use crate::BufferAlloc;
unsafe fn write_ptr(n: *mut usize, ptr: Option<*mut usize>) {
debug_assert!(!ptr.is_some_and(|ptr| n == ptr));
ptr::write(n.cast(), ptr.unwrap_or(n))
}
unsafe fn read_ptr(n: *mut usize) -> Option<*mut usize> {
let ptr = ptr::read(n.cast());
@mildsunrise
mildsunrise / daikin.py
Last active February 9, 2024 03:06
Documentation / implementation of Daikin's IR protocol in Python
'''
This module implements the IR protocol for Daikin's air conditioning units.
It is based on this work:
<https://github.com/blafois/Daikin-IR-Reverse>
And contains some additional improvements, such as:
- Implementation of the low layer (IR signal protocol).
The low-level IR protocol is not explained very well by blafois;
no mention is made to the following:
@mildsunrise
mildsunrise / README.md
Last active March 24, 2025 13:10
Documentation of Tuya's weird compression scheme for IR codes

[Tuya][]'s IR blasters, like the [ZS08][], have the ability to both learn and blast generic IR codes. These IR codes are given to the user as an opaque string, like this:

A/IEiwFAAwbJAfIE8gSLIAUBiwFAC+ADAwuLAfIE8gSLAckBRx9AB0ADBskB8gTyBIsgBQGLAUALA4sB8gRAB8ADBfIEiwHJAeARLwHJAeAFAwHyBOC5LwGLAeA97wOLAfIE4RcfBYsB8gTyBEAFAYsB4AcrCYsB8gTyBIsByQHgPY8DyQHyBOAHAwHyBEAX4BVfBIsB8gTJoAMF8gSLAckB4BUvAckB4AEDBfIEiwHJAQ==

Not much is known about the format of these IR code strings, which makes it difficult to use codes obtained through other means (such as a

@mildsunrise
mildsunrise / README.md
Last active January 25, 2024 01:31
JS code in the PDF for Spanish tax form 145

The Spanish government loves (or loved) using JavaScript in their tax forms.

This gist contains the JS blocks in the official tax form 145 PDF, version 1.0/2022. Enjoy.

The code is reproduced verbatim, except for normalizing the encoding (latin-1 to utf-8) and the newlines (CRLF to LF). Using some iconv command + unix2dos should give you back the exact bytes in the PDF, except for one thing: there's a stray CR without accompanying LF in object828.js:139. Yeah, idk.

@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 / signalis.py
Created September 16, 2023 19:49
SIGNALIS save data decoder/encoder
#!/usr/bin/python
"""
signalis.py decode <input.png> <output.json>
signalis.py encode <input.json> <output.png>
the decoder does NOT validate the input image! to do that, encode data again and check image pixels match
"""
import os, sys
import numpy as np
@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

Usage of virglrenderer

Introduction

virglrenderer is a library that gives emulators the necessary tools to implement a [virtio-gpu][] device, in particular one with 3D support. See capability sets below for a summary of the APIs virglrenderer can implement for the guest. It directly implements the logic behind some 3D commands like GET_CAPSET, CTX_CREATE, CTX_SUBMIT_3D, CREATE_RESOURCE_BLOB, and though it closely follows the semantics of virtio-gpu in most cases, it is in theory independent of virtio or any other transport.

Main user is [qemu][qemu-gpu-impl], but there also appears to be a [standalone virtio-gpu vhost-user][qemu-vhost-impl] implementation that uses virglrenderer in qemu/contrib.

virglrenderer's public header is at [src/virglrenderer.h][public-header]. This document attempts to outine the public API and contract, but you should look at the header for an authoritative source of truth since semantics described here could be slightly wrong or have changed, a