Skip to content

Instantly share code, notes, and snippets.

Avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / letsencrypt.yml
Created Jun 14, 2021
Example of an Ansible playbook that uses group_by
View letsencrypt.yml
---
- hosts: all
tasks:
- group_by: key="{{ 'using_letsencrypt' if letsencrypt_certs|default([]) else 'not_using_letsencrypt' }}"
changed_when: no
tags: always
- group_by: key="{{ ansible_distribution.lower() ~ '_' ~ ansible_distribution_release }}"
changed_when: no
tags: always
View test_apt_key.py
import os
from units.compat import mock
from units.compat import unittest
from ansible.modules import apt_key
class AptKeyTestCase(unittest.TestCase):
@mgedmin
mgedmin / prune_libvirt_images.py
Created Jun 9, 2021
prune unused vagrant-libvirt images
View prune_libvirt_images.py
#!/usr/bin/python3
"""
Script to remove unused libvirt images left lying around by libvirt-vagrant.
This is a workaround for
https://github.com/vagrant-libvirt/vagrant-libvirt/issues/85
"""
import argparse
import functools
@mgedmin
mgedmin / conftest.py
Created Sep 9, 2020
How to get a pytest progress bar in xterm title
View conftest.py
# 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
/etc/network/interfaces with static IPv6
View interfaces
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 Oct 8, 2019
How to make your desktop open different URLs in different browsers, depending on the URL
View MAGIC_BROWSER.md

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 Sep 6, 2019
A script we use to compare a bunch of PDFs pairwise
View compare_reportgen_output.py
#!/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
View gist:fbbe7cc70951a5ba45d9b33867b30246
mg@platonas: /tmp/experiment $ tree
.
├── roles
│   └── common
│   └── tasks
│   ├── generate_confi1g.yml
│   ├── main.yml
│   └── sync_rules.yml
└── test.yml
@mgedmin
mgedmin / full-report.txt
Created Nov 19, 2018
cd ~/src/zopefoundation && check-python-versions *
View full-report.txt
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 Sep 27, 2018
Python exception chaining dot jpg
View gist:78ceb2081ea2a76a40d3f8fc505a61fc
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