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 / mp4parser.py
Last active April 23, 2024 12:47
🕵️‍♀️ MP4 parser / dissector for the command line
#!/usr/bin/env python3
'''
Portable* ISO Base Media File Format dissector / parser.
Usage: ./mp4parser.py <file name>
(*) Needs Python 3.8+
Goals / development guidelines:
- Low level. Meant as a dissector, i.e. to obtain info about the structure of the file
@mildsunrise
mildsunrise / README.md
Last active April 18, 2024 12:35
Wrapper that simplifies SSH tunnels

ssh-from

ssh-from simplifies common usage of SSH tunnels.
It instructs SSH to start a SOCKS proxy, and spawns a (local) shell that uses this proxy.

$ ssh-from my-host
$ curl http://foo/bar  # the request is tunnelled through my-host
@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 / README.md
Last active April 16, 2024 11:30
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 / polynomials.agda
Last active April 13, 2024 20:54
polynomial algebra over a ring
open import Level using (suc; _⊔_)
open import Function using (id; _∘_)
open import Data.List as List using (
List; []; _∷_; [_]; map; reverse; align; alignWith; foldr; head; last; drop; length
)
import Data.List.Properties as List
import Data.List.Relation.Unary.All as All
import Data.List.Relation.Binary.Pointwise as PW
@mildsunrise
mildsunrise / jni.md
Last active March 30, 2024 16:32
JNI ABI magic numbers

JNIEnv

(keep in mind that JNI methods get a JNIEnv *, not a direct JNIEnv)

given JNIEnv x, you can write ((void**)x)[N] to access a function pointer, where N is:

     4	GetVersion
     5	DefineClass
 6	FindClass
@mildsunrise
mildsunrise / Main.java
Created March 30, 2024 13:37
copy a test image to the clipboard using Java AWT
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.image.*;
import java.io.*;
public class Main {
public static void main(String[] arg) {
var flavorMap = (FlavorTable) SystemFlavorMap.getDefaultFlavorMap();
System.out.println("formats for image flavor: ");
for (var format : flavorMap.getNativesForFlavor(DataFlavor.imageFlavor))
@mildsunrise
mildsunrise / radix_sort.rs
Last active March 4, 2024 12:22
in-place radix sort with sentinel
use std::{ops::{Add, AddAssign}, convert::TryInto};
/// In-place unstable radix sort with sentinel
///
/// - `L` is the type used for bin counts (must be able to hold `arr.len()`).
/// - `key: F` is a function taking an array item + a level, and returning an alphabet symbol.
/// - `AL` is the alphabet length, i.e. number of bins. it must hold that `key(...) < AL`.
///
/// 0 is the sentinel, meaning that for any item, `key(item, max_level) == 0`.
/// `max_level` may differ among items.
@mildsunrise
mildsunrise / install-ubuntu-by-netboot.md
Last active March 1, 2024 22:55
Boot an Ubuntu ISO through network (with EFI)

Netboot Ubuntu with EFI

This method is not netinst. The ISO is downloaded from a URL into RAM, and mounted. After that, installation proceeds exactly as if it was a pen drive / CDROM, and the network cable can be disconnected if you want.

You do not need internet in either computer, just the ISO file.

We don't touch any system files, just delete $TFTPROOT and dnsmasq.conf when you're done.

Before you begin

@mildsunrise
mildsunrise / rtmp2flv.py
Last active March 1, 2024 11:43
convert a captured TCP stream of an RTMP connection into FLV
'''
Reads the contents of a TCP stream carrying [one side of] an
RTMP connection, and blindly dumps streams above 0 in an FLV.
$ ./rtmp2flv.py < tcp-stream > video.flv
'''
from enum import IntEnum, unique
from dataclasses import dataclass, field
from typing import NamedTuple, Self, Optional