Skip to content

Instantly share code, notes, and snippets.

@marcuscaisey
marcuscaisey / Makefile
Last active February 19, 2021 19:23
Makefile for managing Python requirements.txt with pip-tools (based on https://jamescooke.info/a-successful-pip-tools-workflow-for-managing-python-package-requirements.html)
objects = $(wildcard *.in)
outputs = $(objects:.in=.txt)
sync-targets = $(objects:%.in=sync-%)
upgrade-targets = $(objects:%.in=upgrade-%)
.PHONY: all check clean $(sync-targets) $(upgrade-targets)
all: $(outputs)
%.txt: %.in
{
"keys": ["tab"],
"command": "move",
"args": {"by": "characters", "forward": true},
"context": [{
"key": "preceding_text",
"operator": "not_regex_match",
"operand": "^\\s*$",
"match_all": true,
}, {
@marcuscaisey
marcuscaisey / stopstart
Created April 11, 2019 00:07
Basic script which allows for start/stopping with only one instance allowed to be running at a time.
#!/usr/local/bin/python3
import os
import signal
import time
import sys
PID_FILENAME = __file__.split("/")[-1] + ".pid"
def main():
@marcuscaisey
marcuscaisey / reduce.py
Last active March 21, 2019 22:47
reduce implemented recursively and iteratively
def reduce(function, sequence, initial=None):
i = iter(sequence)
try:
initial = initial if initial is not None else next(i)
except StopIteration:
raise TypeError("reduce() of empty sequence with no initial value")
try:
return reduce(function, i, function(initial, next(i)))
except StopIteration:
return initial
@marcuscaisey
marcuscaisey / staticmethod.py
Last active December 7, 2018 01:03
Basic static method decorator
import functools
def staticmethod_(method):
class_name = method.__qualname__.split(".")[0]
@functools.wraps(method)
def wrapper(*args, **kwargs):
class_ = globals()[class_name]
if isinstance(args[0], class_):
@marcuscaisey
marcuscaisey / classmethod.py
Last active December 7, 2018 01:03
Basic class method decorator
import functools
def classmethod_(method):
class_name = method.__qualname__.split(".")[0]
@functools.wraps(method)
def wrapper(*args, **kwargs):
class_ = globals()[class_name]
if isinstance(args[0], class_):