Skip to content

Instantly share code, notes, and snippets.

View agoose77's full-sized avatar
🏠
Working from home

Angus Hollands agoose77

🏠
Working from home
View GitHub Profile
@agoose77
agoose77 / leastsq-1d-weighted
Created July 23, 2019 20:16
Weighted 1D iterative least squares
import numpy as np
def pearson_r(x: np.ndarray, y: np.ndarray) -> np.ndarray:
n = len(x)
return (n * x @ y - x.sum() * y.sum()) / np.sqrt(
(n * (x @ x) - x.sum() ** 2) * (n * (y @ y) - y.sum() ** 2)
)
def lstsq_1d(
import operator
import inspect
import pytest
def getattribute(obj, name):
return object.__getattribute__(obj, name)
def setattribute(obj, name, value):
object.__setattr__(obj, name, value)
#!/usr/bin/python3
# Originally from from Mark Slater 29/11/16
# Modified for per-user name mapping by Mark Colclough, 28 July 2017
# Modified to suppress SystemExit exception by Angus Hollands, 3 Dec 2019
# Install as /usr/lib/cups/backend/safeq
# Configure a safeq backend in CUPS (lpinfo -v should show it)
# URL/Connection: safeq://localhost (direct)
# PPD: Generic PostScript Printer Foomatic/Postscript

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
class Deferred:
def __init__(self, call, *args, **kwargs):
self.call = getattr(call, 'func', call)
self.args = args
self.kwargs = kwargs
def result(self):
return self.call(*self.args, **self.kwargs)
# Inspiration from http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/
def y_comb(f):
def outer(x):
def inner(y):
return (x(x))(y)
return f(inner)
return outer(outer)
from collections import deque, namedtuple, defaultdict
from time import time
from types import coroutine
from enum import auto, Enum
from operator import itemgetter
def async_contextmanager(func):
class ctx:
def __init__(self, *args, **kwargs):
from collections import deque, namedtuple
from time import time
from enum import auto, Enum
from operator import itemgetter
class Trap(Enum):
SLEEP = auto()
SPAWN = auto()
WHOAMI = auto()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Use F1 as modifier
unbind C-b
set -g prefix F1
bind F1 send-prefix
# split panes using h and b
bind h split-window -h
bind v split-window -v
unbind '"'