Skip to content

Instantly share code, notes, and snippets.

@hoefling
hoefling / schema.py
Created May 6, 2020 19:48 — forked from miikka/schema.py
Using Hypothesis to generate XML based on RELAX-NG
import string
from lxml import etree
from lxml.etree import QName
from lxml.builder import E
from hypothesis import strategies as st
NS = "http://relaxng.org/ns/structure/1.0"
@hoefling
hoefling / async.py
Created January 20, 2020 17:05 — forked from phizaz/async.py
Python turn sync functions to async (and async to sync)
import functools
def force_async(fn):
'''
turns a sync function to async function using threads
'''
from concurrent.futures import ThreadPoolExecutor
import asyncio
pool = ThreadPoolExecutor()
@hoefling
hoefling / test_aiomock.py
Last active October 3, 2019 11:28
test aiomock
from unittest.mock import Mock
import asyncpg
import pytest
from async_lru import alru_cache
@alru_cache
async def run():
conn = await asyncpg.connect(user='user', password='pass', database='db', host='127.0.0.1')
await conn.close()
@hoefling
hoefling / wsgi_bjoern.py
Created July 24, 2019 19:53 — forked from gcavalcante8808/wsgi_bjoern.py
Bjoern Django Final
import bjoern
import os, signal
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = get_wsgi_application()
NUM_WORKERS = 8
@hoefling
hoefling / conftest.py
Created August 28, 2018 10:00 — forked from asfaltboy/conftest.py
A pytest fixture to test Django data migrations
# based on https://gist.github.com/blueyed/4fb0a807104551f103e6
# and on https://gist.github.com/TauPan/aec52e398d7288cb5a62895916182a9f (gistspection!)
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
import pytest
@pytest.fixture()
@hoefling
hoefling / pip-query
Created May 29, 2018 10:51
List python packages with Pacman package owners, see https://unix.stackexchange.com/questions/444195/
#!/usr/bin/env python3
import operator
import subprocess
import sys
import pkg_resources
try:
from pip._internal.commands.list import tabulate
except ImportError:
@hoefling
hoefling / List all the platform tags on the system (for wheel compliance check)
Last active November 23, 2017 22:26
List all the platform tags on the system (for wheel compliance check)
python -c "from pip.pep425tags import get_supported; print('\n'.join(str(tag) for tag in get_supported()))"
# count commits, sort by author
$ git shortlog -s -n
# same as above, w/o merge commits
$ git shortlog -s -n --no-merges
# same as above on all remote branches
$ git shortlog -s -n --no-merges --all
# counts insertions/deletions/delta locs for all authors in repo
#!/usr/bin/env bash
[ -d "/tmp/zopetest" ] && rm -rf /tmp/zopetest
mkdir /tmp/zopetest
touch /tmp/zopetest/__init__.py
cat > /tmp/zopetest/interface.py << EOL
import zope.interface
class IFoo(zope.interface.Interface):
"""Foo blah blah"""
@hoefling
hoefling / init_nanorc
Created July 30, 2016 10:33
Init nanorc on CentOS7
#!/usr/bin/env bash
find /usr/share/nano/ -type f -name "*.nanorc" | sed 's/^/include /g' > $HOME/.nanorc