Skip to content

Instantly share code, notes, and snippets.

@hoefling
hoefling / filter-python2-deps
Last active April 16, 2019 08:57
filter installed packages having 2.7 as only python target and activate python2_7 use flag
#!/usr/bin/env bash
$(which eix) --compact --installed --use python_targets_python2_7 \
--not --use python_targets_python3_5 --not --use python_targets_python3_4 \
--not --use python_targets_python3_3 --not --use python_targets_python3_2 \
| sed -n 's/^\[I\] \(.*\/.*\) ([[:digit:]].*$/\1/p' \
| awk '{print $1" python_targets_python2_7"}' \
> /etc/portage/package.use/python2_7
@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
#!/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"""
# 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
@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()))"
@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 / 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 / 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 / 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 / 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()