Skip to content

Instantly share code, notes, and snippets.

View Rathgore's full-sized avatar

Mark McWilliams Rathgore

View GitHub Profile
@Rathgore
Rathgore / README-python-service-on-systemd-activated-socket.md
Created August 6, 2017 05:24 — forked from drmalex07/README-python-service-on-systemd-activated-socket.md
An example network service with systemd-activated socket in Python. #systemd #python #socket #socket-activation

README

The example below creates a TCP server listening on a stream (i.e. SOCK_STREAM) socket. A similar approach can be followed to create a UDP server on a datagram (i.e. SOCK_DGRAM) socket. See man systemd.socket for details.

An example server

Create an simple echo server at /opt/foo/serve.py.

@Rathgore
Rathgore / forward_docker.md
Last active March 8, 2018 07:00
Forward Docker daemon over SSH

Edit ExecStart in /etc/systemd/system/multi-user.target.wants/docker.service

ExecStart=/usr/bin/dockerd -H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock

Forward daemon port over SSH

ssh -L 4243:localhost:4243 
@Rathgore
Rathgore / gist:dd873a88dc6866666c5a
Created November 25, 2014 00:55
CRC-CCITT NSData extension in Swift
import Foundation
let SEED: UInt16 = 0xFFFF
let crcCCITTLookupTable: [UInt16] = [
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108,
0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210,
0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B,
0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, 0x2462, 0x3443, 0x0420, 0x1401,
0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE,
@Rathgore
Rathgore / delete_old_mail.py
Created May 4, 2012 21:00
Simple script to delete old messages in an IMAP mailbox
MAIL_SERVER = ''
USERNAME = ''
PASSWORD = ''
MAILBOX = 'Spam'
MAX_DAYS = 7 # Deletes messages older than a week
import imaplib
import datetime
today = datetime.date.today()