Skip to content

Instantly share code, notes, and snippets.

Avatar

Aryeh Leib Taurog altaurog

View GitHub Profile
@altaurog
altaurog / docker_descendants.py
Last active Aug 3, 2022
Python3 script to find descendants of one or more docker images
View docker_descendants.py
#!/usr/bin/python3
#
# usage: python3 docker_descendants.py <image_id> ...
import sys
from subprocess import check_output
def main(images):
image_ids = set(images)
@altaurog
altaurog / droprace.py
Created Jul 10, 2014
PostgreSQL drop/rename race condition
View droprace.py
import logging
import os
import sys
import time
import threading
import psycopg2
"""
This script demonstrates the following race condition under PostgreSQL:
One connection, in transaction, drops table "mytable," then renames
@altaurog
altaurog / vew-bootstrap.sh
Created Jul 19, 2020
virtualenvwrapper bootstrap script
View vew-bootstrap.sh
#!/bin/bash
mkdir ~/.venv
python3 -m venv ~/.virtualenvs/venv
~/.virtualenvs/venv/bin/pip install virtualenvwrapper
if [ -n "`$SHELL -c 'echo $ZSH_VERSION'`" ]; then
config=~/.zshrc
elif [ -n "`$SHELL -c 'echo $BASH_VERSION'`" ]; then
config=~/.bashrc
@altaurog
altaurog / partition.py
Created Aug 12, 2015
Linux partitioning tools
View partition.py
sec = 512
k = 1024
m = k * k
g = m * k
bs = 4 * m /sec
# Generate a partition table for consumption by sfdisk
# (partition plan is hardcoded below)
partplan = (
@altaurog
altaurog / Dockerfile
Last active Jun 22, 2020
starlette on docker x-forwarded-proto
View Dockerfile
FROM debian:10-slim
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc make python3 python3-dev python3-pip
RUN pip3 install setuptools wheel
RUN pip3 install uvicorn starlette
COPY app.py app.py
@altaurog
altaurog / Dockerfile
Last active Feb 3, 2020
Error using SQLProvider
View Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
RUN apt-get update && apt-get install -y netcat
COPY Test.fsproj Program.fs /Test/
WORKDIR /Test
RUN dotnet restore # --verbosity detailed
@altaurog
altaurog / insertmany.py
Last active Feb 1, 2017 — forked from dvarrazzo/exmany.py
Test for a different implementation of psycopg executemany
View insertmany.py
import contextlib
import itertools
import operator
import os
import sys
import time
import psycopg2
import pgcopy
View ct_pd.py
"""
Performance benchmark: pandas DataFrame.pivot against crosstab
"""
from datetime import datetime, timedelta
import io
import random
import sys
import time
import pandas as pd
@altaurog
altaurog / ip.py
Created Aug 12, 2015
Python classes for working with ipv4 addresses
View ip.py
tohex = lambda a:'.'.join('%02X' % p for p in a)
fromhex = lambda h:[int(p,16) for p in h.split('.')]
tobin = lambda a:'.'.join('{0:08b}'.format(p) for p in a)
frombin = lambda h:[int(p,2) for p in h.split('.')]
class IPAddr(object):
def __init__(self, address):
if isinstance(address, (int,long)):
self.long = address
else:
@altaurog
altaurog / pnid.py
Created Aug 12, 2015
Get PID of n'th parent (linux only)
View pnid.py
import os
"""
Get PID of n'th parent
This works in linux only
"""
def pnid(n=1, pid=os.getpid()):
for i in range(n):
try:
procfile = open("/proc/%s/status" % pid)