Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / encryptdir.py
Created January 22, 2018 13:14
Encrypt every file in a directory with GPG
#!/usr/bin/env python
"""Create an encrypted copy of a directory.
Usage:
encryptdir.py [-n] [-v] -r <recipients> <directory> <encrypted-directory>
"""
import os
@mgedmin
mgedmin / gist:a0d087193487a2d0c96f8fd8d5a6b29e
Created January 15, 2018 20:13
/bin/sh, wat you doing?
mg@platonas: ~ $ ./wat.sh
hi
1
hi
2
mg@platonas: ~ $ cat wat.sh
#!/bin/sh
x=1
x=2 echo hi
---
- hosts: localhost
gather_facts: no
tasks:
# bad -- inserts spaces after every newline
- shell: |
cat <<'EOF'
UPDATE TABLE BLAH BLAH;
COMMIT;
EOF
@mgedmin
mgedmin / host-keys.yml
Created October 19, 2017 15:21
Ansible playbook to install SSH host keys in known_hosts
# Ansible playbook that installs host keys for all of my servers into ~/.ssh/known_hosts
# group_vars/all has to list them all like
#
# ssh_host_keys:
# github: |
# github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
# fridge: |
# fridge.pov.lt ssh-dss ...
# fridge.pov.lt ssh-rsa ...
#
@mgedmin
mgedmin / dns_fabfile.py
Created October 6, 2017 14:14
Example of using Fabric to manage DNS zone files for BIND
"""
example.com DNS deployments
"""
import time
import collections
from fabric.api import env, task, settings, local, put, run, abort, warn, quiet
from fabric.contrib.files import contains
@mgedmin
mgedmin / ansible-2.3-strange-warning.md
Created May 2, 2017 13:32
Ansible 2.3 strange warning about {{/}} in when condition

I've an Ansible role that sets up Postfix transport maps. It's configured like this:

roles/mail-server/vars/defaults.yml

# maps domain -> primary mail server hostname/IP
# e.g. backup_mx_for: { example.com: mail.example.com }
backup_mx_for: {}

# same as above, only without a blanket accept rule
@mgedmin
mgedmin / mailcap
Created February 2, 2017 15:39
Handling HTML mail with Mutt
# HTML (when you press Enter in the attachment list)
text/html; /usr/bin/links -html-assume-codepage %{charset} '%s'; needsterminal; description=HTML Text; nametemplate=%s.html
# maybe also consider -html-hard-assume 1
# HTML mail (rendered in Mutt's pager and also what you get when replying)
text/html; /usr/bin/w3m -dump -s -o display_link=yes -o display_link_number=yes -o decode_url=yes -T text/html -I %{charset}; copiousoutput; description=HTML Text

One thing that surprises newer programmers is that the older 8-bit microcomputers from the 70s and 80s were designed to run at the speed of random memory access to DRAM and ROM. The C64 was released in 1982 when I was born and its 6502 CPU ran at 1 MHz (give or take depending on NTSC vs PAL). It had a 2-stage pipelined design that was designed to overlap execution and instruction fetch for the current and next instruction. Cycle counting was simple to understand and master since it was based almost entirely on the number of memory accesses (1 cycle each), with a 1-cycle penalty for taken branches because of the pipelined instruction fetch for the next sequential instruction. So, the entire architecture was based on keeping the memory subsystem busy 100% of the time by issuing a read or write every cycle. One-byte instructions with no memory operands like INX still take the minimum 2 cycles per instruction and end up redundantly issuing the same memory request two cycles in a row.

- name: scripts to create docker images
copy: src={{ item.script }} dest=./{{ item.script }} mode=0775
register: scripts
with_items:
- { image: foo-test-image, script: build-docker-image.sh }
- { image: foo-debian-image, script: build-debian-image.sh }
- { image: foo-packaging-image, script: build-packaging-image.sh }
tags: docker
- name: list docker images