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
jmendeth / diff.py
Created Jul 15, 2019
Quick & dirty uility for diffing filesystems
View diff.py
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 f.read().strip().splitlines() }
with open("/other/etc/passwd") as f:
@jmendeth
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
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
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
path=/var/mails/%d/%n
# Permission of new directories.
dir_mode=0750
@jmendeth
jmendeth / parser.py
Last active Apr 10, 2019
Parsing twitter IDs
View parser.py
"""
Simple parser for Twitter-generated IDs.
ID model taken from Snowflake, which is no longer used:
https://github.com/twitter-archive/snowflake/blob/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231/src/main/scala/com/twitter/service/snowflake/IdWorker.scala
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
jmendeth / grc-to-notes.py
Created Mar 24, 2019
Script to play notes according to a Float stream coming from i.e. GNU Radio
View grc-to-notes.py
#!/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
jmendeth / docker_commands.md
Created Feb 22, 2019
Useful Docker commands
View docker_commands.md

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
jmendeth / arithmetic.py
Last active Mar 6, 2019
Integer (and polynomial) modular arithmetic for Python!
View arithmetic.py
"""
INTEGER MODULAR ARITHMETIC
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).
@jmendeth
jmendeth / description.md
Last active May 24, 2018
File description of the .fpk format used by Sid Meier's Pirates! (and Civilization IV?)
View description.md

.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: https://forums.civfanatics.com/threads/civ4-pakbuild.136023/

Script

@jmendeth
jmendeth / enmiendas-pdl-nombre.md
Last active May 29, 2018
Summary about spanish bill 122/000072 ammendments
View enmiendas-pdl-nombre.md

Enmiendas PdL cambio de nombre (122/000072)

EAJ-PNV

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)

Cs

You can’t perform that action at this time.