Skip to content

Instantly share code, notes, and snippets.

View TomFaulkner's full-sized avatar
:octocat:
GitHub activity feed is almost as exciting as early Twitter.

Tom Faulkner TomFaulkner

:octocat:
GitHub activity feed is almost as exciting as early Twitter.
View GitHub Profile
@TomFaulkner
TomFaulkner / gist:9c9f2fd785542947505a3204ddde1e69
Created February 21, 2019 02:36
Docker Compose for home server
version: "3"
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "80:80/tcp"
- "443:443/tcp"
- "192.168.1.21:67:67/udp"
- "192.168.1.21:53:53/udp"
@TomFaulkner
TomFaulkner / find-duplicate-files.bash
Last active December 29, 2018 03:43 — forked from OndraZizka/find-duplicate-files.bash
Finds duplicate files. An alternative to `fdupes -r -S .`
find -type f -size +3M -print0 | while IFS= read -r -d '' i; do
#echo $i
echo -n '.'
if grep -q "$i" md5-partial.txt; then
echo -n ':'; #-e "\n$i ---- Already counted, skipping.";
continue;
fi
#md5sum "$i" >> md5.txt
MD5=`dd bs=1M count=1 if="$i" status=none | md5sum`
MD5=`echo $MD5 | cut -d' ' -f1`
@TomFaulkner
TomFaulkner / ubuntu18.04-vfio.md
Last active January 24, 2025 13:52
VFIO Setup on Ubuntu 18.04
@TomFaulkner
TomFaulkner / Python Patch Parent.py
Created July 24, 2018 20:38
Patch the parents of a class for unit testing
# source: https://stackoverflow.com/a/24577389/9893423
# The MockFoo class still has the methods of the Foo class and it doesn't
# have the methods defined in the parent because the parent is now a Mock class.
from contextlib import contextmanager
@contextmanager
def patch_parent(class_):
"""
Mock the bases
# spread
# Author:- Rohit Tanwar
# https://github.com/kriadmin/30-seconds-of-python-code
# Contributors:-Rohit Tanwar
# Implements javascript's [].concat(...arr). Flattens the list(non-deep) and returns an list.
def spread(arg):
ret = []
for i in arg:
@TomFaulkner
TomFaulkner / AutoVivication.py
Last active February 27, 2018 21:36
Instant nested dicts
# Borrowed from:
# https://stackoverflow.com/questions/2600790/multiple-levels-of-collection-defaultdict-in-python
class AutoVivification(dict):
"""Implementation of perl's autovivification feature."""
def __getitem__(self, item):
try:
return dict.__getitem__(self, item)
except KeyError:
value = self[item] = type(self)()
return value
@TomFaulkner
TomFaulkner / background_loop.py
Created February 11, 2018 00:31
Monitor with a daemon thread
"""Background Loop for running a monitor process
Uses a daemon thread, so no delays in exiting.
Don't use this for things that involve writing data, as weird things
may happen if the daemon dies while writing.
Pass in an a function to call as "action"
This does what I need it for at the moment, for other uses one might
need to extend the action call to pass on parameters or *args, **kwargs.
@TomFaulkner
TomFaulkner / perpetual_timer.py
Created February 11, 2018 00:28
Python Perpetual (Repeating) Timer
"""
PerpetualTimer: Run a function every x seconds until PerpetualTimer.cancel().
Source, with some modificiations:
https://stackoverflow.com/questions/12435211/python-threading-timer-repeat-function-every-n-seconds
Example usage:
def printer():
print('ipsem lorem')
@TomFaulkner
TomFaulkner / extendable_enum.py
Last active May 10, 2019 16:41
Extendable Enum
"""An extendable Enum
Though this one is probably better:
https://pypi.python.org/pypi/aenum
"""
from enum import Enum
class ExtendableEnum(Enum):
@classmethod
### Keybase proof
I hereby claim:
* I am tomfaulkner on github.
* I am tomfaulkner (https://keybase.io/tomfaulkner) on keybase.
* I have a public key ASC4oGzsjuO8XVLPSyBWTYJemCFTjO4q91585EtPyS1KRwo
To claim this, I am signing this object: