- Everything is an object
- The Object must be instantiated
- If it is not instantiated, it is not an object *(e.g. print, console, math)
- If it is not an object, wrap it in an object (e.g. max = Max(3,2,1))
- Constructors accept only objects
- Constructors store their arguments
- Constructors have no logic
- Constructors only accept objects that do not change
This file contains hidden or 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
| ON = 1 | |
| OFF = 0 | |
| def switch(setting=OFF): | |
| def switchdec(function): | |
| if not hasattr(function, 'enabled'): | |
| function.enabled = setting | |
| def wrapper(*args,**kwargs): | |
| if getattr(function, 'enabled'): | |
| return function(*args,**kwargs) |
This file contains hidden or 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
| (function (window) { | |
| var Keyboard = function() { | |
| var keyCodes = {}; | |
| var keyNames = { | |
| // Controls | |
| "backspace": 8, "tab": 9, "return": 13, "shift": 16, "ctrl": 17, "alt": 18, "capslocks": 20, | |
| "esc": 27, "space": 32, "left": 37, "up": 38, "right": 39, "down": 40, | |
| "page-up": 33, "page-down": 34, "end": 35, "home": 36, | |
| "insert": 45, "delete": 46, |
This file contains hidden or 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 | |
| reload(sys) | |
| ENCODING = 'utf-8-sig' | |
| sys.setdefaultencoding(ENCODING) | |
| def read_file(path): | |
| with codecs.open(path, 'r', ENCODING) as file_: | |
| return file_.read() | |
| def write(string, path): |
This file contains hidden or 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 os | |
| import logging | |
| from tornado.httpserver import HTTPServer | |
| from tornado.ioloop import IOLoop | |
| from tornado.web import Application, RequestHandler, StaticFileHandler, url | |
| from tornado.options import define, options | |
| from tornado import gen | |
| define('port', default=8888) |
This file contains hidden or 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
| from __future__ import division | |
| import functools | |
| import itertools | |
| import math | |
| import threading | |
| def partition(collection): | |
| size = len(collection) | |
| part_count = int(math.ceil(math.sqrt(size))) |
This file contains hidden or 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
| from scipy import stats | |
| import numpy as np | |
| import pandas as pd | |
| sns.set_context('talk') | |
| for df in [1, 6, 120]: | |
| dist = stats.t(df, loc=0, scale=1) | |
| range_ = np.linspace(dist.ppf(0.01), dist.ppf(0.99), num=100) | |
| pdf = pd.Series(dist.pdf(range_)) |
This file contains hidden or 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
| # For when you are pissed off that python 3 has no print statement. | |
| # Use echo+ Instead. No Brackets. | |
| class Print(object): | |
| def __add__(self, other): | |
| print(other) | |
| return self | |
| def __lshift__(self, other): | |
| return self.__add__(other) |
This file contains hidden or 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
| from IPython.core.magic import register_cell_magic | |
| from IPython.display import HTML | |
| @register_cell_magic | |
| def alert(line_parameter, cell): | |
| ''' | |
| Enables Bootstrap Alert Blocks as Cell magic, like so: | |
| In [1]: %%alert info | |
| This is a message |
This file contains hidden or 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 UnexpectedSymbol(Exception): pass | |
| operations = { | |
| '+': lambda a,b: a+b, | |
| '-': lambda a,b: a-b, | |
| '*': lambda a,b: a*b, | |
| '/': lambda a,b: a/b | |
| } | |
| precedence = { |