Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / day24.rs
Last active December 24, 2022 13:54
Advent of Code 2022, day 24 solution
use num_integer::lcm;
use std::cmp::Ordering;
use std::collections::{BinaryHeap, HashMap};
#[derive(Copy, Clone)]
pub struct Pos {
x: usize,
y: usize,
}
@mgedmin
mgedmin / day22.rs
Created December 22, 2022 15:51
Advent of Code 2022, day 22 solution
use lazy_static::lazy_static;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use num_integer::gcd;
use regex::Regex;
use std::collections::{HashMap, VecDeque};
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum Facing {
Right = 0,
@mgedmin
mgedmin / part1.rs
Created December 21, 2022 08:35
Advent of Code 2022 solution for day 21
use std::collections::HashMap;
use num_rational::Rational64;
pub type Number = Rational64;
#[derive(Debug)]
pub enum Expr<'a> {
Unknown,
Number(Number),
Add(&'a str, &'a str),
@mgedmin
mgedmin / letsencrypt.yml
Created June 14, 2021 08:21
Example of an Ansible playbook that uses group_by
---
- 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
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 June 9, 2021 10:40
prune unused vagrant-libvirt images
#!/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 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