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 / containers-and-permissions.md
Last active May 13, 2022 12:18
A reference for running containers with non-root permissions

When implementing development environments inside a container, usually I want to:

  1. Run as non-root inside the container (many tools do not like being run as root).
  2. Behave as the non-root user executing the container when reading/writing from mounted volumes

There are some additional (small) security benefits from running as non-root inside a container.

The solution to these problems is complicated by the way that different container runtimes behave:

keep-id

Across the different container runtimes, there is often a flag such as userns=keep-id that maps the UID:GID of the host to the container. Linux creates users by default with UID 1000, so default non-root users will often map directly to host UID.

#!/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
# 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 '"'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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)
@pervognsen
pervognsen / rad.py
Last active January 18, 2024 02:30
# Reverse-mode automatic differentiation
import math
# d(-x) = -dx
def func_neg(x):
return -x, [-1]
# d(x + y) = dx + dy
def func_add(x, y):
@nadavrot
nadavrot / Matrix.md
Last active November 15, 2024 16:00
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

@danizen
danizen / multiauthenticator.py
Created March 15, 2018 23:06
MultiAuthenticator for jupyterhub
from urllib.parse import urlsplit
from tornado import gen
from tornado.escape import url_escape
from tornado.httputil import url_concat
from traitlets import (
Unicode, Integer, Dict, TraitError, List, Bool, Any,
Type, Set, Instance, Bytes, Float,
observe, default,
@Mnkai
Mnkai / README.md
Last active November 4, 2024 11:37
TDP and turbo parameter modification with MSR on non-overclockable Intel CPU (such as Intel i7-8550U)

TDP and Turbo Parameter Modification with MSR on Non-Overclockable CPUs

Disclaimer

  • Modifying MSR may void your CPU's (or system board's) warranty. Proceed with caution. I am not responsible for any damage caused by this article.
  • MSR addresses vary significantly between CPUs. Check your CPU's MSR address using Intel's documentation.
  • This has only been tested on the Intel i7-8550U (Kaby Lake R).
  • This article is a translation of this article. If you can read Korean, I recommend reading that article instead.

Introduction