Skip to content

Instantly share code, notes, and snippets.

Alba Mendez jmendeth

Block or report user

Report or block jmendeth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jmendeth /
Created Dec 31, 2019
Parser for Darkest Dungeon saves
from struct import unpack, pack
from sys import argv, stderr
import io
import json
def checked_read(f, amount):
result =
assert len(result) == amount
return result
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
jmendeth /
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:
jmendeth / 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
jmendeth / 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 : '')
jmendeth / maildir.ini
Last active May 17, 2019
Haraka plugin to store mail in a fixed maildir
View maildir.ini
# This file must be placed in "config" directory of your Haraka server.
# Maildir directory. Can be relative to Haraka server directory, or absolute.
# Available tokens:
# %d -> domain
# %n -> username
# Permission of new directories.
jmendeth /
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
jmendeth /
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)
jmendeth /
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}}"
jmendeth /
Last active Mar 6, 2019
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).
You can’t perform that action at this time.