Skip to content

Instantly share code, notes, and snippets.

@aib
aib / gist:ce5bb91ee6e006bcaaa4f438879bfd7b
Created January 24, 2020 09:50
Python standard library breakdown
import collections
import importlib
import inspect
import sys
MODULES = """\
string
re
difflib
textwrap
@aib
aib / tuntap.py
Created February 4, 2019 05:58
TUN/TAP packet decoder prototype
import struct
import bitstream
import dotdict
import numpy as np
import pytun
def read_uint(stream, n=None):
integer = 0
for _ in range(n):
@aib
aib / tuntap_tun.py
Created February 4, 2019 00:25
tun packet decoder
import struct
import bitstream
import dotdict
import numpy as np
import pytun
def read_uint(stream, n=None):
integer = 0
for _ in range(n):
@aib
aib / sudoku.py
Created January 1, 2019 20:17
Sudoku CNF
import collections
import itertools as it
import subprocess
import sys
class Sudoku:
def __init__(self, size):
self.width = size*size
self.height = size*size
self._opts = size*size
import functools as ft
import itertools as it
import operator as op
def generate_factors(b, n, smallest_number=1):
if n == 1:
yield [b]
else:
for i in range(smallest_number, b // 2 + 1):
for s in generate_factors(b-i, n-1, i):
class Piped:
def __init__(self, fn, terminal=False):
self.fn = fn
self.terminal = terminal
self.args = []
self.gotval = False
self.val = None
def __call__(self, *args):
self.args = list(args)
@aib
aib / route
Last active February 13, 2018 16:26
Selective IP routing for those who live in interesting times
#!/bin/bash
update_gist() {
GITHUB_USERNAME=aib
GIST_ID=1881c25137724b47f916aec3e87028de
python -c "import json, sys; json.dump({ \"files\": { sys.argv[1]: { \"content\": sys.stdin.read() } } }, sys.stdout)" $(basename "$0") <"$0" | curl -f -s -H "Accept: application/vnd.github.v3+json" -H "Content-Type: application/json" -u "$GITHUB_USERNAME" -X PATCH "https://api.github.com/gists/$GIST_ID" -d@- >/dev/null
}
if [ -z "$1" ]; then
printf "Usage:\n" >&2
#!/usr/bin/env python
import math
import pygame
import random
import rtmidi
from rtmidi.midiconstants import *
import time
TAU = 2 * math.pi
@aib
aib / aibUtils.as
Created January 7, 2017 19:56
My old ActionScript Utility file
/*
* A static class with misc. utilities
*
* aib, 20071120
*/
package
{
import flash.display.DisplayObject;
import flash.display.Graphics;
@aib
aib / hmm.c
Created January 6, 2017 14:25
stagger test
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#define PROCS 10
int child(int n)
{
while (1) {