Skip to content

Instantly share code, notes, and snippets.

View fredcallaway's full-sized avatar

Fred Callaway fredcallaway

View GitHub Profile
@fredcallaway
fredcallaway / fred-bigrams
Created October 9, 2015 19:30
NLP Project 1: Language modeling
---
title: "NLP Project 1: Language modeling"
author: Fred Callaway
---
__Note to Grader:__ I had difficulties with my partner, which is why this is being turned in late, and separately. Please contact Dr.Cardie if you are hearing this for the first time.
# Model components
@fredcallaway
fredcallaway / add_print_parentheses.py
Last active December 8, 2015 03:25
Adds parentheses to print statements in a python file.
import re
def add_print_parentheses(file_name):
match = None # a regex match when we are in a print statment
lines = []
with open(file_name) as file:
for line in file:
line = line.rstrip()
if match: # we are in a print statement
indentation = re.match(r'[ ]*', line).span()[1]
"""IO spoofing."""
import sys
from contextlib import contextmanager
from io import StringIO
from collections import deque
@contextmanager
def capture_stdout():
@fredcallaway
fredcallaway / PlainTasksWithPastDue.py
Created July 16, 2016 10:21
PastDue for PlainTasks
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sublime, sublime_plugin
import os
import re
import webbrowser
import itertools
from datetime import datetime
from datetime import timedelta
@fredcallaway
fredcallaway / gscholar.py
Created September 10, 2016 22:21
Quick fix for the Reference Importer alfred workflow
#!/usr/bin/env python
# encoding: utf-8
"""
gscholar.py
Created by Andrew Ning on November 16, 2013
Updated by Fred Callaway September 2016
"""
from __future__ import print_function
@fredcallaway
fredcallaway / classypedia.css
Created September 12, 2016 18:39
Classypedia with improved TOC
@font-face {
font-family: 'Cinzel';
font-style: normal;
font-weight: 400;
src: local('Cinzel-Regular'), url(//themes.googleusercontent.com/static/fonts/cinzel/v1/mLL0ZqnXRx3m16FnBy9gcg.woff) format('woff');
}
@font-face {
font-family: 'Droid Sans';
font-style: normal;
font-weight: 400;
@fredcallaway
fredcallaway / iterated_learning.ipynb
Last active October 18, 2016 05:05
MPL's don't like circles
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import itertools as it
import numpy as np
ivs = [
('hit', [0, 1, 2]),
('layout', 'ABCDEF'),
('cue', 'TF'),
]
# At present, the first iv defines the number and orderof trials. Thus,
@fredcallaway
fredcallaway / stochastic_matrix.py
Created November 10, 2016 06:11
Stochastic matrix in pymc3
import numpy as np
import pymc3 as pm
import theano
class StochasticMatrix(pm.Continuous):
"""A stochastic matrix has rows that sum to 1."""
def __init__(self, theta, *args, **kwargs):
shape = (theta.shape[-1], theta.shape[-1])
kwargs.setdefault('shape', shape)
super(StochasticMatrix, self).__init__(*args, **kwargs)
from toolz import pipe
class Blank(object):
"""Forgive me Lord, for I have sinned.
Inspired by implicit partial application in Coconut:
http://coconut.readthedocs.io/en/master/DOCS.html#implicit-partial-application
"""
def __getattr__(self, attr):