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
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 /
Last active Jul 25, 2019
Helper program to add HTTP/SOCKS proxy support to SSH


This program adds proxy support to ssh. Once installed, ssh will obey the ssh_proxy environment variable (or all_proxy as a fallback) and will try to connect to the server through that proxy. Example:

export ssh_proxy="socks5://"
ssh  # will connect through SOCKS5 proxy
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 /
Last active Jun 10, 2019
Wrapper that simplifies SSH tunnels


ssh-from simplifies common usage of SSH tunnels, and makes double (or triple) tunnels a piece of cake.
Here is an example, where I SSH to a computer that is behind two NATs, tunneling through each router:

Double tunnel example

Details coming to the blog soon.


jmendeth /
Created Jul 17, 2012
"clear" command in Python
class clear:
def __call__(self):
import os
if'ce','nt','dos'): os.system('cls')
elif'posix': os.system('clear')
else: print('\n'*120)
def __neg__(self): self()
def __repr__(self):
self();return ''
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 28, 2019
Implementation of the D'Hondt method
""" Implements the D'Hondt method.
Given a chamber of `total_seats` seats, and a dictionary of
integer values (vote counts), one for each party, assigns seats
to each party using the D'Hondt method.
Returns a dictionary of integer values (assigned seats). Results
are undefined if two parties have the same number of non-zero
votes, or there are no votes.
Example (taken from Wikipedia):
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
You can’t perform that action at this time.