Skip to content

Instantly share code, notes, and snippets.

View timsavage's full-sized avatar
😎
Why do we need a status?

Tim Savage timsavage

😎
Why do we need a status?
View GitHub Profile
@timsavage
timsavage / Unifi-Video-Install.md
Last active March 23, 2022 23:05
Instructions to get a running install of Unifi Video

Setup Unifi-Video

Requirements

  • Debian 9
  • OpenJDK-8-jre 8u252
  • MongoDB 4.4

Install Debian 9 (Stretch)

Get the net-install image from Debian.org for your particular Hardware (usually AMD64)

@timsavage
timsavage / camera-on-air.py
Created September 10, 2021 05:22
Python script to monitor when a webcamera is activated on Linux
import shutil
import subprocess
import time
COMMANDS = [shutil.which("lsmod")]
MOD_NAME = b"uvcvideo"
def get_uvc_user_count() -> int:
"""
# Python Prime Sieve
#
# MyFirstPython Program (tm) Dave Plummer 8/9/2018
#
# This is the main prime_sieve class. Call it with the number you wish as an upper limit, then
# call the runSieve method to do the calculation. printResults will dump the count to check validity.
#
# Updated 3/22/2021 for Dave's Garage episode comparing C++, C#, and Python
from sys import stdout # So I can print without an automatic python newline
@timsavage
timsavage / smart-sync.py
Last active August 25, 2020 23:55
Script for syncing static websites to S3.
#! /usr/bin/env python3
"""
Script for syncing static websites to S3. Requires Python 3.6+
- Uses ETags to determine if a file has changed.
- Cleans up remote files.
- Sets public ACLs
- Supplies the correct content-type
- Uses GZip encoding for appropriate file types.

Keybase proof

I hereby claim:

  • I am timsavage on github.
  • I am timsavage (https://keybase.io/timsavage) on keybase.
  • I have a public key whose fingerprint is B8B4 CB98 C8A8 4138 376E B77A AE89 3004 2ACF 1BA1

To claim this, I am signing this object:

@timsavage
timsavage / websocket_server.py
Last active June 27, 2023 16:58
Simple example of a websocket server with Tornado
# While this code still works, I would recommend using Fast API for websockets in modern applications.
# See: https://fastapi.tiangolo.com/advanced/websockets/
# Note this is targeted at python 3
import tornado.web
import tornado.httpserver
import tornado.ioloop
import tornado.websocket
import tornado.options
@timsavage
timsavage / generate.py
Created March 14, 2016 16:39
Code Generation with Jinja
from jinja2 import Template, Environment
# The environment is used to configure the template engine
# See: http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment
env = Environment(autoescape=False, optimized=False)
# Open your template and compile into a template object.
with open("template.txt", "r") as f:
template = env.from_string(f.read())
@timsavage
timsavage / __init__.py
Last active November 12, 2019 00:49
Customising Django Auth username length for Django 1.8+
default_app_config = 'myapp.auth.apps.MyAuthAppConfig'