Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@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 / show-all-256-colors.py
Last active August 24, 2023 16:23
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 / 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 / .pythonrc
Created December 30, 2010 20:37
snippets for export PYTHONSTARTUP=~/.pythonrc
# This is the actual file that combines all of the other snippets
# I've been using it for a while, so it's officially Bug Free (TM)
# Python startup script. vim: set ft=python :
# from http://www.norvig.com/python-iaq.html
# also see Tarek Ziade's _Expert_Pythom_Programming_ page 19
import os, sys
# Coloured prompt
if os.getenv('TERM') in ('xterm', 'vt100', 'rxvt', 'Eterm', 'putty'):
@mgedmin
mgedmin / disk-inventory.py
Created June 22, 2012 11:17
disk-inventory
#!/usr/bin/python
"""
Produce a disk inventory for fridge:
- how many hard disks and how large
- how are they partitioned
- how are the RAID devices defined
- where are they mounted
- how much space is used and how much is free
@mgedmin
mgedmin / github_mirror.py
Last active January 13, 2022 07:46
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