Skip to content

Instantly share code, notes, and snippets.

@BrandonLMorris
BrandonLMorris / quote.py
Created July 5, 2015 00:29
Pull stock quote from markitondemand.com API
import urllib.request
import json
base_url = "http://dev.markitondemand.com/Api/v2/Quote/json?symbol="
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:
AT&T: number@txt.att.net
T-Mobile: number@tmomail.net
Verizon: number@vtext.com
Sprint: number@messaging.sprintpcs.com or number@pm.sprint.com
Virgin Mobile: number@vmobl.com
@BrandonLMorris
BrandonLMorris / ConvertToPositive.java
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
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)
"""
"""
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):
"""

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]]
"""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)
@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
#!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)
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