This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def deptartment(request, dept): | |
dept = dept.upper() | |
department = Departent(pcr('depts', dept)) | |
context = {'courses': [course for course in department.courses]} | |
return render_to_response('department.html', context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A collection of wrappers for API objects in the PennCourseReview API.""" | |
from api import pcr | |
class CourseHistory(object): | |
"""A wrapper for coursehistory objects in the PCR API.""" | |
def __init__(self, raw_coursehistory): | |
self.raw = raw_coursehistory | |
self.id = raw_coursehistory['id'] | |
self.name = raw_coursehistory['name'] | |
self.aliases = raw_coursehistory['aliases'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- mode: python -*- | |
from subprocess import Popen, PIPE | |
import sys | |
syntax_checker = "pyflakes" | |
def run(command): | |
p = Popen(command.split(), stdout=PIPE, stderr=PIPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from itertools import izip | |
from melopy import Melopy | |
from nonsense import StationarySource | |
if __name__ == "__main__": | |
try: | |
sample = sys.argv[1] # must not have comments | |
except IndexError: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Based on https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development""" | |
from django.conf import settings | |
from django.conf.urls.defaults import include, patterns | |
from django.contrib import admin | |
from django.views.generic.list_detail import object_detail | |
from app.models import Place | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def adj(g): | |
""" | |
Convert a directed graph to an adjacency matrix. | |
Note: The distance from a node to itself is 0 and distance from a node to | |
an unconnected node is defined to be infinite. | |
>>> g = {1: {2: 3, 3: 8, 5: -4}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import time | |
ef retry(exceptions, tries=5, delay=0.25): | |
"""Retry the decorated function using an exponential backoff strategy. | |
If the function does not complete successfully after the specified number | |
of tries, the exception is raised normally.""" | |
def wrapper(func): | |
@functools.wraps(func) | |
def wrapped(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal | |
constructor: (@name) -> | |
move: (meters) -> | |
alert @name + " moved #{meters}m." | |
class Snake extends Animal | |
move: -> | |
alert "Slithering..." | |
super 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BLACK = 0 | |
RED = 1 | |
GREEN = 2 | |
YELLOW = 3 | |
BLUE = 4 | |
MAGENTA = 5 | |
CYAN = 6 | |
WHITE = 7 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Module for playing the n-arm bandit game.""" | |
import random | |
class Arm(object): | |
"""A point generator.""" | |
def __init__(self): | |
self.mean = random.normalvariate(0, 1) | |
def pull(self): |