Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / show-all-256-colors.py
Last active September 24, 2025 15:40
Script to show all 256 colors supported by xterms
#!/usr/bin/python
"""Print a swatch using all 256 colors of 256-color-capable terminals."""
__author__ = "Marius Gedminas <marius@gedmin.as>"
__url__ = "https://gist.github.com/mgedmin/2762225"
__version__ = '2.0'
def hrun(start, width, padding=0):
@mgedmin
mgedmin / gist:9547214
Created March 14, 2014 12:59
Setting up a Jenkins slave on Linux
# This is how you add a Jenkins slave
# On master:
sudo -u jenkins -H ssh-keygen
# On slave
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /bin/bash jenkins-slave
install -d -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave
import argparse
import pathlib
import sys
old_bytes = bytes([0x80, 0x79, 0x05, 0x00, 0x0f, 0x94, 0xc2])
new_bytes = bytes([0xc6, 0x41, 0x05, 0x01, 0xb2, 0x00, 0x90])
def main():
parser = argparse.ArgumentParser(description="sublime text patcher")
@mgedmin
mgedmin / filter_plugins__dns.py
Created September 4, 2024 11:24
Managing DNS servers with Ansible
# filter_plugins/dns.py
import dns.zone # pip install dnspython or pipx inject ansible dnspython
import dns.resolver
import dns.flags
def get_dns_serial(zone, ns=None):
resolver = dns.resolver.Resolver(configure=True)
resolver.use_edns(0, ednsflags=dns.flags.DO, payload=4096)
if ns:
@mgedmin
mgedmin / lock_user.py
Created July 4, 2024 10:17
Ansible module to lock a user account
#!/usr/bin/python
import spwd
import subprocess
DOCUMENTATION = '''
---
module: lock_user
short_description: locks user accounts
description:
- The M(lock_user) module invokes C(passwd -l) to lock user accounts.
@mgedmin
mgedmin / github_mirror.py
Last active May 27, 2024 06:00
Mirror all my github repositories and gists
#!/usr/bin/env python3
# See http://stackoverflow.com/questions/3581031/backup-mirror-github-repositories/13917251#13917251
# You can find the latest version of this script at
# https://gist.github.com/4319265
import os
import sys
import json
import urllib.request
import subprocess
@mgedmin
mgedmin / termtoggle.vim
Created April 26, 2024 11:23
Show/hide terminal by pressing F12 in Vim
fun! ToggleTerminal()
let terms = term_list()
if terms == [] " no terminals, open one
botright term
elseif bufwinnr(terms[0]) == -1 " terminal hidden, show it
exec 'botright sbuffer' terms[0]
else " terminal visible, hide it
exec bufwinnr(terms[0]) .. 'hide'
endif
endf
@mgedmin
mgedmin / postfix.py
Last active February 6, 2024 14:21
Ansible module for postfix configuration
#!/usr/bin/python
import subprocess
DOCUMENTATION = '''
---
module: postfix
short_description: changes postfix configuration parameters
description:
- The M(postfix) module changes postfix configuration by invoking 'postconf'.
@mgedmin
mgedmin / StartSSL.md
Last active October 22, 2023 07:52
Free StartSSL.com SSL certificate HOWTO

How to get a free StartSSL.com SSL certificate

I'm writing this up from memory, so errors may appear.

This has been updated to use SHA256 certificates.

Start

  1. Go to http://www.startssl.com/
  2. Click on 'Control Panel'
@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,
}