Skip to content

Instantly share code, notes, and snippets.

View biggers's full-sized avatar

Mark Biggers biggers

View GitHub Profile
@biggers
biggers / py_rotate_log_dict_config.py
Created December 19, 2017 19:23
Python3 rotating log-file configuration via "config.dictConfig"
import sys
import logging
import logging.config
import random
import string
# "thank you" to folks on StackOverflow.com for various ideas,
# for this example. Works with Python3.
@biggers
biggers / tcpclient.py
Last active January 2, 2018 15:01
"continously-running" Tornado TCP client example -- sends to 'tornado/demos/tcpecho/server.py'
import time
import logging
from tornado.options import options, define
from tornado import gen
from tornado.tcpclient import TCPClient
from tornado.iostream import StreamClosedError
from tornado.ioloop import IOLoop
define("host", default="127.0.0.1", help="TCP server host")
define("port", default=9888, help="TCP port to connect to")
@biggers
biggers / recipe-pyenv.sh
Created September 26, 2017 17:46
shell-recipe for pyenv install of Python 3.6.2 on CentOS / Redhat 6.7
# REF: https://github.com/pyenv/pyenv/blob/master/README.md
# ... building Python 3.6.2 on Bastion, "locally"
# yum install [Python3 build pre-reqs, on CentOS 6.7]
curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
tee -a $HOME/.bash_profile <<EOF
export PATH="\$HOME/.pyenv/bin:\$PATH"
eval "\$(pyenv init -)"
@biggers
biggers / py_syslog_dict_config.py
Last active May 31, 2023 20:21
Python dictConfig logging example using SyslogHandler - modified from Stackoverflow answer
import logging
import sys
from logging import config
# REF, modified from:
# https://stackoverflow.com/a/19367225
if sys.platform == "darwin":
address = '/var/run/syslog'
facility = 'local1'
@biggers
biggers / LinuxLVM.sh
Created September 1, 2017 13:50
simple Linux volume mgmt example / recipe(s) - LVM
-*-sh-*-
Various bits, pieces, notes -- on using Linux Volume (Disk) Mgmt,
on various Linux distros
"A Debian Grimoire - LVM: Logical Volume Management, Version 2"
http://deb.riseup.net/storage/lvm2/
@biggers
biggers / csv_summary_to_sql.py
Created August 14, 2017 19:05
How-to use the PyMySQL module for Python3 DB-API, working simple example (need a SQL table created, first)
import pymysql.cursors
import os
from attrdict import AttrDict
import sys
# Test a one-row Insert, Select for Capacity DB
# ... using Py DB-API
#
# Install:
# pip3 install PyMySQL attrdict
@biggers
biggers / async_threadpool_blocking_fn.py
Created August 10, 2017 16:38
async Python3 code using blocking-function
from concurrent.futures import ThreadPoolExecutor, as_completed
import time
import random
TPOOL_SIZE = 8
def blocking(pid):
""" a non-deterministic "blocking" ? task
"""
@biggers
biggers / streamlogger.py
Last active June 30, 2017 14:44 — forked from pmuller/streamlogger.py
StreamLogger is a context handler which proxies an output stream to python's logging
#!/usr/bin/env python3
#
# Port of "Fabric streamlogger" to Python3
# Credit (originally): https://gist.github.com/2376336.git
# pmuller - streamlogger.py
import sys
import logging
from io import StringIO
@biggers
biggers / network_mgr_wired_mgmt_recipe.sh
Created January 18, 2017 14:09
Enable wired-interfaces (incl VPN) to be managed by systemd - Ubuntu Linux 16+
# NetworkManager should manage wired interfaces!
# Linux Mint 18.x (Ubuntu 16.04)
# REF: "fixing VPN problem in Ubuntu",
# http://blog.wensheng.org/search?updated-min=2015-01-01T00:00:00-06:00&updated-max=2016-01-01T00:00:00-06:00&max-results=5
aptitude install etckeeper
git log
nmcli c # NOTE: no wired-interface controlled
emacs -nw /etc/NetworkManager/NetworkManager.conf
@biggers
biggers / x11vnc.sh
Created August 19, 2016 14:37
x11vnc service start-up script
#!/bin/sh
VNC_SERVER=/usr/bin/x11vnc
VNC_DISPLAY=:0
LOG_FILE=/tmp/x11vnc-run.log
case "$1" in
start|restart)
killall ${VNC_SERVER}