Skip to content

Instantly share code, notes, and snippets.

View westphahl's full-sized avatar
😬
Whoops!

Simon Westphahl westphahl

😬
Whoops!
View GitHub Profile
@westphahl
westphahl / 01-test_cache.py
Last active June 17, 2021 11:56
Reproducer for tree cache event race
from kazoo.client import KazooClient
from kazoo.recipe.cache import TreeCache
zuul_root = "/path/to/src/opendev/zuul/zuul"
k = KazooClient(
hosts="localhost:2281",
keyfile=f"{zuul_root}/tools/ca/keys/clientkey.pem",
certfile=f"{zuul_root}/tools/ca/certs/client.pem",
ca=f"{zuul_root}/tools/ca/certs/cacert.pem",
@westphahl
westphahl / 98-wireguard.network
Created February 22, 2020 17:53
Wireguard systemd config
# /etc/systemd/network/98-wireguard.network
[Match]
Name = wg0
[Network]
Address = 10.200.200.1/32
[Route]
Gateway = 10.200.200.1
Destination = 10.200.200.0/24
@westphahl
westphahl / bug_demo.py
Last active September 9, 2019 20:39
Pika - Connection reset bug
# Issue: https://github.com/pika/pika/issues/753
import logging
import pika
class Consumer:
def run(self, queue):
self.connection = connection = pika.BlockingConnection()
class assert_raises(object):
def __init__(self, exc_type):
self.exc_type = exc_type
def __enter__(self):
pass
def __exit__(self, exc_type, exc_value, traceback):
assert self.exc_type == exc_type, "Expected exception not raised"
@westphahl
westphahl / signalblocker.py
Created July 22, 2015 17:40
context manager to block signals
import time
import signal
class SignalBlocker:
def __init__(self, signal):
self._signal = signal
self._signal_blocked = False
epfd = epoll_create(1);
if (epfd == -1)
errExit("epoll_create");
ev.events = EPOLLIN;
ev.data.fd = sockfd;
epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &ev);
ev.events = EPOLLIN;
ev.data.fd = STDIN_FILENO;
# Evaluate prompt
setopt prompt_subst
# History config
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
# VIM key bindings
bindkey -v
# Key bindings for 'home' and 'end'
bindkey "^[[1~" beginning-of-line
@westphahl
westphahl / gist:4663221
Last active December 11, 2015 21:29
Testing SMTP with telnet
$ echo '[email protected]' | base64
bWVAZXhhbXBsZS5jb20=
$ echo 'secret' | base64
c2VjcmV0
@westphahl
westphahl / gist:1297896
Created October 19, 2011 10:13
Base template
<!DOCTYPE html>
<html lang="de">
<head>
<title>{% block title %}{% endblock %}</title>
<meta charset="utf-8">
<link rel="stylesheet" href="{{ MEDIA_URL }}style/screen.css">
</head>
<body>
@westphahl
westphahl / gist:989000
Created May 24, 2011 16:04
Abfrage von Ankünften für Bahnhöfe (Q&D mit gevent/BeautifulSoup)
#!/usr/bin/env python
import gevent
from gevent import monkey, GreenletExit
monkey.patch_all()
import sys
import urllib2
from datetime import datetime, date, time
from BeautifulSoup import BeautifulSoup