Skip to content

Instantly share code, notes, and snippets.

BrandonLMorris /
Created July 5, 2015 00:29
Pull stock quote from API
import urllib.request
import json
base_url = ""
def get_quote(symbol):
html = urllib.request.urlopen(base_url + symbol).read().decode("utf-8")
parsed_json = json.loads(html)
return parsed_json["Name"] + ": " + str(parsed_json["LastPrice"])
#!/usr/bin python3
A simple script to send a text message over gmail. Text messages are sent as
emails. The mail address depends on the carrier, based on the table below:
Sprint: or
Virgin Mobile:
BrandonLMorris /
Created January 28, 2016 15:25
Pointing out an interesting quirk with Java's Math.abs() where it actually returns a negative number
import java.util.*;
* Problem statement: Given a number (that is guaranteed to fit within a 32 bit
* two's compliment integer), print the absolute value of that number.
* The catch: A two's compliment signed integer has a larger range for negative
* numbers than it does positive. So simply returning Math.abs() on the input
* won't always work if the input is Integer.MIN_VALUE (-2147483648).
BrandonLMorris /
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
(The same thing applies to default arguments)
Simple example of currying and creating higher-order functions
in Python.
Taken from
def curry2(f):


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


  • [none] for general information
  • login/logout
  • problem
  • submit
  • comp[etition[s]]
"""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)
View SQLAlchemy stress test
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)
View auacm-problems-needed
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
BrandonLMorris /
Created September 9, 2017 16:38
TensorFlow MNIST classifier example, adopted from
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
import argparse
import os
import matplotlib.pyplot as pyplot
EPOCHS = 5000
SAVE_PATH = 'mnist-cnn-model.cpkt'