Skip to content

Instantly share code, notes, and snippets.

View luhn's full-sized avatar

Theron Luhn luhn

View GitHub Profile
@luhn
luhn / mount.sh
Created April 5, 2021 21:21
Mount NVMe EBS volume
# Mount the data disk
# Adapted from https://gist.github.com/ctompkinson/30f570882af38879b36fc7bffe3d1a60
device=/dev/sdh
mount_point=/monitor-config
apt-get install -y nvme-cli
while [ true ]; do
for blkdev in $(nvme list | awk '/^\/dev/ { print $1 }'); do
mapping=$(nvme id-ctrl --raw-binary "${blkdev}" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g')
if [ ${mapping} = ${device} ]; then
echo "Found $device on $blkdev"
@luhn
luhn / abcbench.py
Created July 13, 2022 19:47
ABC Benchmark
import timeit
from abc import ABC, abstractmethod
class A(ABC):
@abstractmethod
def a(self):
...
@luhn
luhn / encoder.py
Last active September 6, 2022 20:56
Override default JSON encoder to add support for dataclasses
import json
from dataclasses import dataclass, is_dataclass, asdict
class DataclassEncoder(json.JSONEncoder):
def default(self, obj):
if is_dataclass(obj):
return asdict(obj)
return super().default(obj)
@luhn
luhn / README.md
Last active May 9, 2023 20:25
Celery SQS Error

Celery SQS bug

  1. Install dependencies with pip install -r requirements.txt
  2. Fill up the queue by running python tasks.py 500
  3. Start Celery with celery -A tasks worker --loglevel=INFO -c 3
  4. Disconnect computer from internet until you receive a CANCEL_TASKS_BY_DEFAULT warning. This may take a couple minutes and you'll see several errors, but you have to wait until the warning.
  5. Reconnect to the internet. After a couple seconds, Celery will reconnect and tasks will start flowing again.
  6. Let tasks run for about a minute. You'll notice a slight slowdown and then suddenly tasks will stop entirely for a couple minutes, before resuming again.