Skip to content

Instantly share code, notes, and snippets.

View ttamg's full-sized avatar

Matt G ttamg

  • London
View GitHub Profile
@ttamg
ttamg / sig_figs.py
Last active June 9, 2022 15:49
Python function to round number to significant figures
from math import floor, log10
def sig_figs(x: float, precision: int):
"""
Rounds a number to number of significant figures
Parameters:
- x - the number to be rounded
- precision (integer) - the number of significant figures
@ttamg
ttamg / ssh-gpu.sh
Created March 25, 2022 17:18
Simple script to connect to GPU server and map Jupyter and Tensorboard ports
#!/bin/sh
ssh -L 8888:localhost:8888 -L 6006:localhost:6006 bob@192.168.1.199
@ttamg
ttamg / mount_gpu.sh
Last active March 25, 2022 15:02
Script to mount GPU server drive on Mac OS - requires SSHFS and MacFUSE
#!/bin/bash
remotedir="bob@192.168.1.199:/gpu" # TODO Add directory on the remote machine
mountdir="/Users/bob/gpu" # TODO Add local directory
echo "Mounting (${mountdir})..."
#Unmount if it's already mounted
if mount | grep "on $mountdir" > /dev/null; then
umount ${mountdir}
@ttamg
ttamg / pytorch_mnist.py
Last active March 13, 2022 21:08
Simple Pytorch script using MNIST to confirm installation is working
# pytorch_mnist.py
# Simple MNIST training script on Pytorch to confirm installation is working correctly
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torchvision
n_epochs = 3
@ttamg
ttamg / benchmark.py
Created March 13, 2022 17:08
AI-benchmark run script
# benchmark.py
from ai_benchmark import AIBenchmark
benchmark = AIBenchmark()
results = benchmark.run()
@ttamg
ttamg / tensorflow_mnist.py
Last active March 13, 2022 17:06
A simple Tensorflow 2 MNIST training example to confirm installation is working
# tensorflow_mnist.py
# A simple Tensorflow 2 MNIST training script to test installation is working correctly.
import tensorflow as tf
import tensorflow_datasets as tfds
(ds_train, ds_test), ds_info = tfds.load(
'mnist',
split=['train', 'test'],
shuffle_files=True,
@ttamg
ttamg / docker-compose.yml
Created December 10, 2021 10:38
Update backend to receive from Traefik
backend:
build: .
ports:
- 8999:80
env_file: .env
restart: unless-stopped
labels:
- "traefik.enable=true"
- "traefik.http.routers.backend.rule=Host(`app.example.com`)"
- "traefik.http.routers.backend.entrypoints=websecure"
@ttamg
ttamg / docker-compose.yml
Created December 10, 2021 10:31
Traefik https service for docker-compose
traefik:
image: "traefik:v2.5"
container_name: "traefik"
command:
#- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
@ttamg
ttamg / docker-compose.yml
Last active December 10, 2021 10:47
Simple FastApi docker-compose - no proxy
version: "3.4"
services:
backend:
build: .
ports:
- 80:80
env_file: .env
restart: unless-stopped
@ttamg
ttamg / get_current_module_path.py
Last active March 9, 2021 13:21
Getting the current module's PATH for use when doing file imports
import os
CWD = os.path.dirname(os.path.abspath(__file__))
#CWD then has the absolute path to this current file