Skip to content

Instantly share code, notes, and snippets.

Avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / .pythonrc
Created Dec 30, 2010
snippets for export PYTHONSTARTUP=~/.pythonrc
View .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 / show-all-256-colors.py
Last active Mar 25, 2022
Script to show all 256 colors supported by xterms
View show-all-256-colors.py
#!/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):
View disk-inventory.py
#!/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 Jan 13, 2022
Mirror all my github repositories and gists
View github_mirror.py
#!/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 / gist:9547214
Created Mar 14, 2014
Setting up a Jenkins slave on Linux
View gist:9547214
# 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
@mgedmin
mgedmin / StartSSL.md
Last active Nov 3, 2021
Free StartSSL.com SSL certificate HOWTO
View StartSSL.md

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 / update-tcp-ports-html.py
Created Jan 14, 2012
Script to convert netstat -tln output into pretty HTML
View update-tcp-ports-html.py
#!/usr/bin/python
"""
Update TCP port assignments page in /var/www/HOSTNAME/ports/index.html.
"""
import datetime
import optparse
import os
import pwd
import socket
@mgedmin
mgedmin / conf.py.rst
Created Jul 22, 2013
HOWTO add "Show on GitHub" and "Edit on GitHub" links to the Sphinx sidebar
View conf.py.rst

Edit on GitHub links for Sphinx

Create _ext/ and _templates/ subdirectories.

Move edit_on_github.py into the _ext/ subdirectory.

Move sourcelink.html into the _templates/ subdirectory.

Add the following after the import sys, os line

@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):