Skip to content

Instantly share code, notes, and snippets.


Alba Mendez mildsunrise

View GitHub Profile
View crc32.js
const table = new Int32Array(256).map((_,n) => [...Array(8)]
.reduce(c => (c>>>1) ^ ((c&1) * 0xEDB88320), n))
const fn = (C, b) => (C>>>8) ^ table[(C^b) & 0xFF]
const crc = (x, seed) => ~x.reduce(fn, ~seed)
// Example:
crc( Buffer.from('Hello') ) === 0xF7D18982
mildsunrise /
Created Jul 15, 2019
Quick & dirty uility for diffing filesystems
import os, re
# Ignores differences on folder mode / ownership
# Collapses "all contents are new" into "whole folder is new"
# Forces no type differences (i.e. link vs dir, etc.)
# Keeps in mind loaded passwd / group for comparison of UID or GID
with open("/etc/passwd") as f:
new_uid_table = { int(x.split(":")[2]): x.split(":")[0] for x in }
with open("/other/etc/passwd") as f:
mildsunrise / optimal-bifurcation.c
Last active Jun 14, 2019
Implementation of the optimal bifurcation algorithm
View optimal-bifurcation.c
Implementation of the optimal bifurcation algorithm.
- bw: Amount of bandwidth to distribute
- N: Number of links
- Cs: Capacities of each link, in descending order
- hCs: Square roots of the capacities
- b [output]: Bandwidths to send through each link
Given a set of links whose capacities are the items of `Cs`, split the
mildsunrise / unpack-config.ts
Last active May 17, 2019
Quick script to write many config files in a single file
View unpack-config.ts
const util = require('util')
const path = require('path')
const fs = require('fs')
const mkdir = util.promisify(fs.mkdir)
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
const trimLines = text => text.replace(/^[ \t]*\n?|\n?[ \t]*$/g, '')
const dedent = text => {
const lines = text.split('\n').map(line => line.trim() ? line : '')
mildsunrise /
Last active Apr 10, 2019
Parsing twitter IDs
Simple parser for Twitter-generated IDs.
ID model taken from Snowflake, which is no longer used:
Twitter IDs are 64-bit, and have the following structure:
- Bits 63 - 22: timestamp (in ms)
- Bits 21 - 17: datacenter ID
- Bits 16 - 12: worker ID
mildsunrise /
Created Mar 24, 2019
Script to play notes according to a Float stream coming from i.e. GNU Radio
#!/usr/bin/env python3
# $ apt install libasound2-dev libjack-jackd2-dev zynaddsubfx
# $ pip3 install python-rtmidi mido
# Then run Zynaddsub, send a float stream from GNU Radio to UDP localhost:8011
from socket import socket, SOCK_DGRAM
from struct import unpack
import math, mido
def value_to_note(x):
dbs = 10 * math.log10(x)
mildsunrise /
Created Feb 22, 2019
Useful Docker commands

Useful Docker commands

Search for Drupal or Drupal-like installs in all started containers (assumes overlay2 storage used):

sudo docker inspect $(docker ps --format '{{.ID}}') --format '{{.GraphDriver.Data.MergedDir}} {{.Name}}' | xargs -L1 bash -c 'echo Scanning container "$1"; sudo find $0 -name authorize.php'

docker-ps Like docker ps -a but with less info:

sudo docker ps -a --format "table {{.ID}}\t{{.Status}}\t{{.Names}}\t{{.Image}}"
mildsunrise /
Last active Jan 15, 2021
Integer (and polynomial) modular arithmetic for Python!
These functions implement modular arithmetic-related functions (GF(p)).
As an implied precondition, parameters must be integers unless otherwise noted.
This code is NOT safe to use for cryptography.
def gcd(a, b):
""" Euclidean algorithm (iterative).
mildsunrise /
Last active May 24, 2018
File description of the .fpk format used by Sid Meier's Pirates! (and Civilization IV?)

.FPK files

.fpk files can be found in the installation location of «Sid Meier's Pirates!» and contain most assets of the game.

Conceptually, an .fpk is just a zip of files. It's probably just a format they quickly invented to prevent people from messing with their assets. It's pretty simple, but the filenames are 'obfuscated' by adding 1 to each letter.

Apparently, Firaxis (game devs) released a «Civ4 PakBuilder» tool to pack/unpack .fpk files:


mildsunrise /
Last active Jan 25, 2021
Summary about spanish bill 122/000072 amendments

Enmiendas PdL cambio de nombre (122/000072)


Afectan al artículo 8, que permite bajo ciertas condiciones que los extranjeros que no hayan podido hacer el cambio de nombre en su país lo hagan aquí:

  • #1 [tecnicidad] El artículo 8 pasa a ser una disposición en sí misma (neutra)
  • #2 [tecnicidad] Retoque de redacción en el artículo 8 (algo buena)