Skip to content

Instantly share code, notes, and snippets.

View wetmore's full-sized avatar

Matthew Wetmore wetmore

View GitHub Profile
from django.conf import settings
from django.db import models
# A Batch represents one batch, and may be assigned to multiple
# users.
class Batch(models.Model):
name = models.CharField(max_length=200)
assigned_users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
def __str__(self):
{-# LANGUAGE GADTs, RankNTypes, TypeFamilies, DataKinds, DeriveFunctor, TypeOperators #-}
import Data.Type.Equality
import Data.List (intercalate)
import Data.Maybe (catMaybes)
data HasVars = Var | NoVar
data SHasVars a where
SVar :: SHasVars Var
@wetmore
wetmore / stocks.hs
Last active November 8, 2015 08:16
Find the maximum profit from buying and selling once.
data StockState = StockState { hi :: Int, lo :: Int, lowest :: Int }
deriving Show
solve xs = (hi st) - (lo st)
where
st = solve' xs
solve' [] = StockState 0 0 0
solve' (x:xs) = foldl go (StockState 0 0 x) xs
where
assignment = __dirname.substr(__dirname.lastIndexOf('/') + 1)
module.exports = (grunt) ->
grunt.initConfig
watch:
files: ['!full.tex', '*.tex']
tasks: 'exec:pdf'
options:
event: ['changed']
exec:
@wetmore
wetmore / gist:25a968bd4ffbaf67416a
Created October 4, 2014 20:44
Tex source for a homework assignment with code and math
\documentclass[a4paper,english]{article}
%% Use utf-8 encoding for foreign characters
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{siunitx}
%% Vector based fonts instead of bitmaps
@wetmore
wetmore / gist:2c6286e0873fd2ee4b7e
Created October 4, 2014 20:36
Tex source for notes on a talk about quantum teleportation
\documentclass[11pt, oneside]{article} % use "amsart" instead of "article" for AMSLaTeX format
\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for for rotated page geometry
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx} % Use pdf, png, jpg, or eps with pdflatex; use eps in DVI mode
% TeX will automatically convert eps --> pdf in pdflatex
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{epigraph}
  1. Give an algorithm to find the longest common subsequence for two given strings using edit distance (the minimal number of additions, deletions and substitutions needed to transform one string into the other).
@wetmore
wetmore / gist:11137017
Last active August 29, 2015 14:00
Fun math problems

Fun problems (rendered at http://mathb.in/18258)

  1. Find $\displaystyle\sum_{n=1}^\infty \frac{n}{2^n}$

  2. Find $\displaystyle\sum_{n=1}^\infty \frac{n^2}{2^n}$

  3. Let $a(k) = \displaystyle\sum_{n=1}^\infty \frac{n^k}{2^n}$. Find a recurrence relation for $a(k)$.

  4. Let $\mathcal{N}$ be the set of natural numbers that do not contain a 6 in their decimal expansion (so, $\mathcal{N} = { 1, 2, 3, 4, 5, 7, \ldots, 14, 15, 17, \ldots }$). Prove that $$ \sum_{n\in\mathcal{N}} \frac{1}{n} < 80 $$

@wetmore
wetmore / jsreview.md
Last active December 29, 2015 03:49
Reviewing some parts of javascript I don't know well enough. And also just a dump of some current knowledge.
@wetmore
wetmore / gist:6600824
Last active December 23, 2015 07:29
hack101 api
import requests
import os
twilio_sid = os.environ['TWILIO_SID']
twilio_auth = os.environ['TWILIO_AUTH']
twilio_url = 'https://api.twilio.com/2010-04-01/Accounts/%(twilio_sid)s/SMS/Messages.json' % locals()
weather_url = 'http://api.openweathermap.org/data/2.5/weather'
weather_params = {'q': 'montreal'}
r = requests.get(weather_url, params=weather_params)