Skip to content

Instantly share code, notes, and snippets.

@BrandonLMorris
BrandonLMorris / minimal-pytorch-cnn.py
Created October 12, 2018 14:48
A no-frills working implementation of a convolutional neural network in pure PyTorch
from absl import app, flags
import torch
from torch import nn
import torch.nn.functional as F
from torchvision.datasets import FashionMNIST
from torchvision.transforms import Compose, ToTensor
from torch.utils.data import DataLoader
FLAGS = flags.FLAGS
dev = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@BrandonLMorris
BrandonLMorris / doom-q-learning.py
Created October 9, 2018 23:26
Deep Q-learning example to play Doom with PyTorch
#!/usr/bin/env python3
"""
Brandon L Morris
Adapted from work by E. Culurciello
"""
from absl import app, flags
import itertools
from random import sample, randint, random
@BrandonLMorris
BrandonLMorris / tensorflow_cnn.py
Created September 9, 2017 16:38
TensorFlow MNIST classifier example, adopted from https://www.tensorflow.org/get_started/mnist/pros
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
import argparse
import os
import matplotlib.pyplot as pyplot
EPOCHS = 5000
MINIBATCH_SIZE = 50
SAVE_PATH = 'mnist-cnn-model.cpkt'
pid name appeared
1 Alchemy 2014 Southeast
2 Balloons 2010 Southeast
3 Bit Counting 2010 Southeast
4 Black Vienna 2009 Mid-Central
5 Block Game 2009 Southeast
6 Bounce 2012 Mid-Central
7 Bulletin Board 2008 Mid-Central
8 Burnout 2011 Southeast
9 Underground Cables 2010 Southeast
#!flask/bin/python
import sys
from time import time
from app import database
from app.modules.user_manager import models as user
# Query once, filter each time
t = time()
q = database.session.query(user.User)
@BrandonLMorris
BrandonLMorris / Dockerfile
Created March 15, 2016 18:57
Dockerized Flask Example
FROM ubuntu:14.04
# Install Python Setuptools
RUN apt-get install -y python-setuptools
# Install pip
RUN easy_install pip
# Add and install Python Modules
ADD requirements.txt /src/requirements.txt
"""A simple example of using unittest.mock to patch a function in a test"""
import unittest
from unittest.mock import patch
def f(x):
return 2**x
def g(y):
retrun f(y % 15)

General

auacm-cli is a command line tool that can be used to interact with the auacm.com api through the terminal. The general command is auacm will subcommands for interacting with particular facets of the site.

Subcommands

  • [none] for general information
  • login/logout
  • problem
  • submit
  • comp[etition[s]]
"""
Simple example of currying and creating higher-order functions
in Python.
Taken from
https://stackoverflow.com/questions/24881604/when-should-i-use-function-currying-in-python
"""
def curry2(f):
"""
@BrandonLMorris
BrandonLMorris / mutable_probs.py
Created February 12, 2016 14:54
Demonstrating a gotcha of Python mutable types
"""
Simple demonstration of the gotcha that can occur in Python with mutable
types being shared across instances of a class
Taken with slight modification from the Python Guide
http://docs.python-guide.org/en/latest/writing/gotchas/
(The same thing applies to default arguments)
"""