Skip to content

Instantly share code, notes, and snippets.

View matutter's full-sized avatar

Mat Utter matutter

View GitHub Profile
@matutter
matutter / uc-lxc.sh
Last active July 15, 2023 21:03
Create a UnifiController LXC
# Assume logged in as `root` in ProxMox 8
cd /root
# Install prereqs
apt install -y skopeo umoci jq -y
# Download and extract RootFS
lxc-create unifi-controller-7.4.162 -t oci --lxcpath /root/lxc -- --url docker://linuxserver/unifi-controller:7.4.162
@matutter
matutter / docker-ce-install.sh
Created May 4, 2023 03:45
docker-ce install on debian
apt install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install docker-ce docker-ce-cli containerd.io -y
usermod -aG docker $USER
@matutter
matutter / load.py
Last active June 10, 2021 02:05
Example of declaring and loading namespace packages
# dirs/c/xx_plugins/c_module/__init__.py
# dirs/c/xx_plugins/d_module/__init__.py
# dirs/a/b/xx_plugins/ab_module/__init__.py
import sys
import os.path as op
import importlib
import pkgutil
from types import ModuleType
from typing import List
@matutter
matutter / app.py
Created May 14, 2021 01:14
Very simple fast api example
"""
curl -d '{"data":"abc123"}' -H "Content-Type: application/json" -X POST http://localhost:8000/thing/data
"""
from fastapi import FastAPI
from pydantic import BaseModel
from starlette.requests import Request
app = FastAPI()
@matutter
matutter / cython_port.svg
Last active March 21, 2021 18:10
Profiling a cython port of SCons & using timestamp based deciders.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matutter
matutter / ph_create_if_not_exists.py
Created July 18, 2020 02:04
A python script to create a database if it does not exist with psycopg2 & Postgres.
from psycopg2 import connect, extensions, sql, OperationalError
import re
POSTGRES_PASSWORD = 'mypasswd'
POSTGRES_USER = 'myuser'
POSTGRES_DB = 'mytest12'
connect_string = f"postgres://{POSTGRES_USER}:{POSTGRES_PASSWORD}@localhost"
db_connect_string = f"{connect_string}/{POSTGRES_DB}"
@matutter
matutter / stf-compose.yml
Last active June 24, 2020 12:20
Compose file to run STF on a local machine.
##
# Usage:
# Run `docker-compose up`
# Navigate to localhost:7100 in your browser
version: "3.6"
services:
stf:
image: openstf/stf
command: bin/stf local
@matutter
matutter / FilteredConnectionExample.py
Created February 6, 2020 04:10
Example on adding filtering to connection fields.
class RoleInput(graphene.InputObjectType):
role = String()
class FilteredConnectionField(SQLAlchemyConnectionField):
def __init__(self, type, input_type, *args, **kwargs):
fields = {name: field.type() for name, field in input_type._meta.fields.items()}
kwargs.update(fields)
super().__init__(type, *args, **kwargs)
@matutter
matutter / poly_delete.py
Created January 26, 2020 05:30
SQLAlchemy cascade delete with polymorphic tables
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:', echo=False)
session = sessionmaker(bind=engine)()
Base = declarative_base()
@matutter
matutter / gql_poly.py
Last active January 18, 2020 16:15
Dynamic generation of graphql interface based on polymorphic ORM inheritance
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Boolean, String, String, Integer, ForeignKey
from sqlalchemy.orm import sessionmaker
from secrets import token_hex
from json import dumps
import graphene
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from graphene.relay import Connection
from collections import defaultdict