Skip to content

Instantly share code, notes, and snippets.

View chr5tphr's full-sized avatar

Christopher chr5tphr

  • Technically a University in Berlin
  • There's no place like 0x7f000001
View GitHub Profile
@chr5tphr
chr5tphr / bcrypt.py
Created May 9, 2018 20:20
CLI to hash passwords using bcrypt
#!/usr/bin/env python3
from getpass import getpass
from bcrypt import gensalt, hashpw
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-r', '--rounds', type=int, default=12)
parser.add_argument('-p', '--prefix', default='2b')
@chr5tphr
chr5tphr / cudamemstat.c
Last active February 9, 2022 10:33
Print CUDA-info in JSON using the Nvidia Management Library (NVML) to avoid parsing of nvidia-smi
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <nvml.h>
#include <time.h>
#define MAXINFO 32
#define MAXCBUF 64
// compile with:
@chr5tphr
chr5tphr / tctpy.py
Created August 1, 2018 14:24
Numpy array to image in console with color codes
import numpy as np
COL_FMT = '\x1b[48;2;%d;%d;%dm\x1b[38;2;%d;%d;%dm'
COL_CLR = '\x1b[0m'
def im2str(im):
if not isinstance(im, np.ndarray) or (im.dtype != np.uint8):
raise TypeError('Input has to be a numpy array with dtype uint8!')
rows = [''.join([COL_FMT%tuple(top.tolist() + bot.tolist()) + '▄' for top, bot in zip(*drow)]) for drow in zip(im[0::2], im[1::2])]
imstr = ((COL_CLR + '\n').join(rows)) + COL_CLR
@chr5tphr
chr5tphr / kpngprint.py
Created August 3, 2018 14:36
prints raw piped png file to kitty terminal
#!/usr/bin/env python3
from base64 import b64encode
import sys
raw = sys.stdin.buffer.read()
def kpngprint(raw):
FRMT = "\x1b_G{control};{payload}\x1b\\"
bcode = b64encode(raw).decode('ascii')
payloads = [bcode[i:i+4096] for i in range(0, len(bcode), 4096)]
#!/usr/bin/env python3
import numpy as np
import sounddevice as sd
from datetime import datetime, timedelta
from time import sleep
from scipy.signal import sawtooth, square
from argparse import ArgumentParser
wform = sawtooth
size(50cm,50cm);
unitsize(1cm);
real blocks[] = {0,1,1,2,3,5,8,13,21,34,55};
//string cont[] = {"","DE","AD","BE","EF","C0","FF","EE","DE","FE","C7"};
string cont[] = {"0","1","1","2","3","5","8","13","21","34","55"};
pen p = linewidth(0.1cm);
pair base = (0,0);
for (int i=1;i<blocks.length;++i){
@chr5tphr
chr5tphr / pytorch_fwd_grad.py
Created February 8, 2019 13:47
Forward mode automatic differentiation "trick" in Pytorch
#!/usr/bin/env python3
import torch
def fwd_grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False):
if isinstance(outputs, torch.Tensor):
outputs = (outputs,)
if isinstance(inputs, torch.Tensor):
inputs = (inputs,)
v = [torch.ones_like(out, requires_grad=True) for out in outputs]
u = [torch.ones_like(inp) for inp in inputs] if grad_outputs is None else grad_outputs
@chr5tphr
chr5tphr / dotln
Last active February 22, 2019 10:52
Shebang script/ list to link dotfiles from .config to home
#!/usr/bin/env -S bash -c 'sed -e "/^#\\|^\$/d" "$0"|while read V;do ln -sfT "$HOME/.config/$V" "$HOME/.$V";done'
#ssh directory
ssh
gitconfig
tmux.conf
@chr5tphr
chr5tphr / portfwd-dhcp.rules
Created February 21, 2019 23:30
Forward dhcp and dns from unprivileged host port to privileged virtual network port
#!/usr/bin/env sh
iptables -A FORWARD -i tap0 -o tap0 -j ACCEPT
# dhcp at 1067
iptables -t nat -A PREROUTING -i tap0 -p udp -m udp --dport 67 -j DNAT --to-destination :1067
iptables -t nat -A POSTROUTING -o tap0 -p udp -m udp --sport 1067 -j SNAT --to-source :67
iptables -A UDP -p udp -m udp --dport 1067 -j ACCEPT
# DNS at 1053
iptables -t nat -A PREROUTING -i tap0 -p udp -m udp --dport 53 -j DNAT --to-destination :1053
@chr5tphr
chr5tphr / bwfull
Last active August 6, 2023 08:48
Bubblewrap full isolation
#!/bin/sh
BWROOT="${1:?"Root not specified!"}"
shift
env -i bwrap \
--bind "$BWROOT" / \
--unshare-user \
--unshare-cgroup \
--unshare-ipc \
--unshare-pid \