Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / conftest.py
Created September 9, 2020 11:28
How to get a pytest progress bar in xterm title
# Put this in your top-level conftest.py
class XTermProgress:
def __init__(self, stdout=sys.stdout):
self.init(stdout)
self.session = None
self.reported = set()
self.args = []
@mgedmin
mgedmin / interfaces
Created May 11, 2020 18:23
/etc/network/interfaces with static IPv6
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address X.X.X.X
pointopoint X.X.X.Y
netmask 255.255.255.255
gateway X.X.X.Y
dns-nameservers A.B.C.D A.B.C.E A.B.C.F
@mgedmin
mgedmin / MAGIC_BROWSER.md
Created October 8, 2019 15:13
How to make your desktop open different URLs in different browsers, depending on the URL

How to make your desktop open different URLs in different browsers, depending on the URL

  • vim ~/bin/open-the-right-browser

    #!/bin/sh
    case "$1" in
      *git.example.com*) browser=firefox;;
      *) browser=chromium-browser;;
    esac
    

exec $browser "$@"

@mgedmin
mgedmin / compare_reportgen_output.py
Created September 6, 2019 06:05
A script we use to compare a bunch of PDFs pairwise
#!/usr/bin/env python
"""
Compare PDF reports pixel-wise.
When reportgen functional tests fail, you may want to see visually what
exactly changed. To do that:
(1) set your changes aside, e.g.
git stash
mg@platonas: /tmp/experiment $ tree
.
├── roles
│   └── common
│   └── tasks
│   ├── generate_confi1g.yml
│   ├── main.yml
│   └── sync_rules.yml
└── test.yml
@mgedmin
mgedmin / full-report.txt
Created November 19, 2018 09:46
cd ~/src/zopefoundation && check-python-versions *
AccessControl:
setup.py says: 2.7, 3.5, 3.6, 3.7
tox.ini says: 2.7, 3.5, 3.6, 3.7
.travis.yml says: 2.7, 3.5, 3.6, 3.7
appveyor.yml says: 2.7, 3.5, 3.6
Acquisition:
@mgedmin
mgedmin / gist:78ceb2081ea2a76a40d3f8fc505a61fc
Created September 27, 2018 12:46
Python exception chaining dot jpg
Traceback (most recent call last):
File "/home/mg/src/zodbbrowser/.tox/py37/lib/python3.7/site-packages/zope/configuration/config.py", line 817, in toargs
args[str(name)] = field.fromUnicode(s)
File "/home/mg/src/zodbbrowser/.tox/py37/lib/python3.7/site-packages/zope/configuration/fields.py", line 85, in fromUnicode
self._DOT_VALIDATOR.validate(to_validate)
File "/home/mg/src/zodbbrowser/.tox/py37/lib/python3.7/site-packages/zope/schema/_bootstrapfields.py", line 291, in validate
self._validate(value)
File "/home/mg/src/zodbbrowser/.tox/py37/lib/python3.7/site-packages/zope/schema/_field.py", line 670, in _validate
raise InvalidDottedName(value).with_field_and_value(self, value)
zope.schema.interfaces.InvalidDottedName: .systemerror.SystemErrorView
Python 2.7.14 (default, Sep 23 2017, 22:06:14)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Wat(object):
... __slots__ = ('a', 'b')
... a = 42
...
>>> x = Wat()
@mgedmin
mgedmin / roles-letsencrypt-tasks-main.yml
Created April 16, 2018 10:45
Upgrading all certbot dependencies given pip >= 10
- name: install letsencrypt
pip:
name: "{{ item }}"
virtualenv: /opt/letsencrypt
state: "{{ 'present' if ansible_check_mode else 'latest' }}"
extra_args: >-
{% if 'pip' not in item and not ansible_check_mode -%}
--upgrade-strategy=eager
{%- endif %}
with_items:
mg@platonas: ~ $ docker run --rm -it ubuntu:xenial
root@c197c14c8a8d:/# apt update -qq && apt install -qqy virtualenv git python
30 packages can be upgraded. Run 'apt list --upgradable' to see them.
The following additional packages will be installed:
ca-certificates dh-python file git-man ifupdown iproute2 isc-dhcp-client isc-dhcp-common krb5-locales less libasn1-8-heimdal libatm1
libbsd0 libcurl3-gnutls libdns-export162 libedit2 liberror-perl libexpat1 libffi6 libgdbm3 libgmp10 libgnutls30 libgssapi-krb5-2
libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 libhx509-5-heimdal libidn11
libisc-export160 libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libmagic1 libmnl0 libmpdec2
libnettle6 libp11-kit0 libperl5.22 libpopt0 libpython-stdlib libpython2.7-minimal libpython2.7-stdlib libpython3-stdlib
libpython3.5-minimal libpython3.5-stdlib libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3