Skip to content

Instantly share code, notes, and snippets.

@r3
r3 / old_files.py
Last active August 29, 2015 14:10
import datetime
import itertools
import os
import pathlib
import smtplib
FIFTEEN_MINUTES = datetime.timedelta(minutes=15)
{
"room_one": [
"You are in a deep, dark forest. You have wandered off the trail, and have lost your way.",
"A column of chimney smoke appears over the treetops in the failing light. What do you do?"
],
"cottage": [
"You enter the cottage. A table as tall as you stand in the center of the giant room,",
"and whole timbers burn in a cavernous fireplace. A cow on a spit roasts in the flames.",
"The room fills with the smell of perfectly done roast beef. Thundering footsteps",
"come closer and closer until a giant appears in the doorway be"
import random
import json
CONTENT_PATH = './content.json'
DEBUG = True
#raw_input = input # Hack for Python 3
class Scene(object):
@r3
r3 / gen.py
Created June 25, 2013 05:14
Teaching generators
from math import sqrt
def count(start, step):
"""Happens to be included in the standard library"""
number = int(start)
while True:
yield number
start += number
@r3
r3 / decorators.py
Created June 25, 2013 04:56
Review decorators
def increment_result(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs) + 1
return wrapper
@increment_result
def square_it(number):
return number * number
"""The grid representing the Sleuth game board
Each cell in the two dimensional list represents a tile in the game. There are
three types of tiles that exist: inaccessable, normal, and door tiles. Tiles
are traversed only in the four cardinal directions (N, S, E, W). As such,
there exist two types of doors, North/South and East/West doors. The numbers
representing these tiles are defined as follows:
0 : Inaccessable Tile
1 : Normal Tile
# I removed the big tag up top for now. Feel free to add it if you like
# Also removed the '#!/bin/python' bit as this script will never be run
# The namedtuple will be used for handling locations
from collections import namedtuple
# I moved the grid to a separate file because it cluttered up this one.
# Might as well keep the ugly contained, ya know?
from grid import grid
@r3
r3 / gist:3668650
Created September 7, 2012 19:03
Classes
import random
from collections import namedtuple
COUNTRIES = ("Norway", "Sweden", "Germany", "Egypt", "South Africa", "Canada",
"China", "Brazil", "Mexico")
# Normally, I'd store key/value pairs as a dictionary for the next two globals,
# but in this case, it wouldn't help since we don't do any lookups.
CONDITIONS = (("Cancer", 30), ("AIDS", 40), ("Common Cold", 3),
("Healthy", 0))
@r3
r3 / gist:3549083
Created August 31, 2012 04:30
Classes and Instances
class Foo():
# It has an attribute called "class_attribute"
# All instances of 'Foo' will share (have a reference to) this class_attribute
# We are not in a method, so we have no reference to any instances, only the class
class_attribute = None
# This is the special method used when instantiating 'Foo'
# Here, 'self' has a special meaning ONLY because of the way it is called.
# As the first parameter, it will be given the created instance of 'Foo'
# Realize that the word 'self' has no special meaning. It is simply a parameter.
numbers = ("73167176531330624919225119674426574742355349194934"
"96983520312774506326239578318016984801869478851843"
"85861560789112949495459501737958331952853208805511"
"12540698747158523863050715693290963295227443043557"
"66896648950445244523161731856403098711121722383113"
"62229893423380308135336276614282806444486645238749"
"30358907296290491560440772390713810515859307960866"
"70172427121883998797908792274921901699720888093776"
"65727333001053367881220235421809751254540594752243"
"52584907711670556013604839586446706324415722155397"