Skip to content

Instantly share code, notes, and snippets.

View tekumara's full-sized avatar
🥚

Oliver Mannion tekumara

🥚
View GitHub Profile
@tekumara
tekumara / parse_s3_url.py
Created September 14, 2023 12:27
parse_s3_url
from urllib.parse import urlparse
def parse_s3_url(url: str) -> tuple[str, str]:
pr = urlparse(url)
bucket = pr.netloc
key = pr.path.lstrip("/")
return bucket, key
@tekumara
tekumara / apt-get.sh
Created January 23, 2023 07:50
wrap apt-get to handle lock contention due to unattended upgrades etc.
#!/usr/bin/env bash
set -uoe pipefail
function apt-get() {
# wrap apt-get to handle lock contention due to unattended upgrades etc.
# retry on lock contention up to three times. on other errors, exit without retry
local i=0
while true;
@tekumara
tekumara / pem_to_jwk.py
Created December 22, 2022 01:16
Convert pem to jwk
import base64
import math
from typing import Dict, cast
import cryptography.hazmat.backends.openssl.rsa as rsa
from cryptography.hazmat.primitives.serialization import load_der_private_key, load_der_public_key
from jose import jwt
# stolen from https://github.com/mpdavis/python-jose/blob/fccbcf4/tests/test_jws.py#L143
rsa_private_key = """-----BEGIN RSA PRIVATE KEY-----
# ruff: noqa: SLF001 ARG001
from typing import Callable
from unittest.mock import MagicMock
import aiobotocore.awsrequest
import aiobotocore.endpoint
import aiohttp
import aiohttp.client_reqrep
import aiohttp.typedefs
@tekumara
tekumara / Dockerfile
Created November 21, 2021 11:53
Build a python zip file with dependencies for AWS lambda
FROM public.ecr.aws/lambda/python:3.8 as builder
RUN yum install -y zip
WORKDIR /var/task/
COPY setup.py pyproject.toml ./
COPY src ./src/
RUN pip install --no-cache-dir . --target dist
WORKDIR /var/task/dist
RUN zip --quiet -r9X /var/task/function.zip .
import asyncio
import time
async def heartbeat():
while True:
start = time.time()
await asyncio.sleep(1)
delay = time.time() - start - 1
print(f"heartbeat delay = {delay:.3f}s")
@tekumara
tekumara / etcd-high-cpu-usage-stack-trace.md
Created December 17, 2019 08:14
etcd-high-cpu-usage-stack-trace.md
$ kill -QUIT $PID 
SIGQUIT: quit
PC=0x45b521 m=0 sigcode=0

goroutine 0 [idle]:
runtime.futex(0x165f8c8, 0x0, 0x0, 0x0, 0x0, 0xc4207eed80, 0x0, 0x0, 0x7ffef4c7e778, 0x40f19b, ...)
	/usr/local/go/src/runtime/sys_linux_amd64.s:530 +0x21
runtime.futexsleep(0x165f8c8, 0x0, 0xffffffffffffffff)
	/usr/local/go/src/runtime/os_linux.go:45 +0x4b
@tekumara
tekumara / jupyter.service
Last active May 23, 2018 23:52
systemd service for Jupyter notebook (system python w/ CUDA libraries)
[Unit]
Description=Jupyter Notebook
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/bin/jupyter notebook
Environment="LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/lib:/usr/lib:/usr/local/cuda/extras/CUPTI/lib64"
User=ubuntu
Group=ubuntu