Skip to content

Instantly share code, notes, and snippets.

View nickeldan's full-sized avatar

Daniel Walker nickeldan

View GitHub Profile
@nickeldan
nickeldan / dont_interrupt.py
Last active July 17, 2024 04:05
Context manager for temporarily blocking KeyboardInterrupt
import signal
import threading
class SigintHandler:
def __init__(self):
self._orig_handler = None
self._interrupted = threading.Event()
@property
def interrupted(self):
@nickeldan
nickeldan / capture.c
Last active October 2, 2023 02:59
Capture packets with classic BPF
#include <errno.h>
#include <fcntl.h>
#include <net/bpf.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
@nickeldan
nickeldan / sync.c
Last active June 24, 2023 17:45
Parent/child synchronization
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdbool.h>
#include <unistd.h>
typedef struct syncChannel {
int fds[2];
} syncChannel;