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
from collections import namedtuple, deque | |
from random import shuffle | |
from functools import partial | |
from itertools import chain | |
WhiteCard = namedtuple('WhiteCard', 'text', verbose=False) | |
BlackCard = namedtuple('BlackCard', ['text', 'pick', 'draw'], verbose=False) | |
white_text = ['itertools', 'functools', 'fibonacci sequence', 'WSGI', | |
'a list comphrension', 'Javascript', 'RESTful', 'C++', |
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
from itertools import takewhile | |
def sieve(n): | |
"""Sieve of Eratosthenes | |
Returns a list of primes from 2 to n. | |
""" | |
if n < 2: | |
return [] |
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
Warning: JAVA_HOME environment variable is not set. | |
Fetching / updating 3 artifacts and their dependencies | |
Exception in thread "main" java.lang.UnsupportedClassVersionError: jove/xsbti/ArtifactInfo : Unsupported major.minor version 52.0 | |
at java.lang.ClassLoader.defineClass1(Native Method) | |
at java.lang.ClassLoader.defineClass(ClassLoader.java:800) | |
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) | |
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) | |
at java.net.URLClassLoader.access$100(URLClassLoader.java:71) | |
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) | |
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) |
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
from flask import Flask, render_template | |
app = Flask(__name__) | |
@app.route('/<page_name>') | |
@app.route('/', defaults={'page_name': 'index'}) | |
def page(page_name): | |
return render_template(page_name, {'page_name': page_name}) |
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
var WeaponList = React.createClass({ | |
render: function() { | |
return (<ul className="list-unstyled"> | |
<li> | |
<Weapon name="flail" attrs={["1d8 bludgeoning;"]} /> | |
</li> | |
<li> | |
<Weapon name="morning star" attrs={["1d8 piercing;"]} /> | |
</li> | |
</ul> |
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 operator | |
from inspect import isclass, isfunction | |
def _is_permission_factory(perm): | |
return isclass(perm) or isfunction(perm) | |
class Permission(object): | |
"Base permission class" | |
def allow(self, user, request, *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
@expose('/register/', method=['POST'] | |
def create_new_user(): | |
form = NewUserForm() | |
username, password, email = form.data.username, form.data.password, form.data.email | |
if User.query.filter_by(User.username == username).first(): | |
return {'success': False, 'reason': 'Username in use already'} | |
elif User.query.filter(User.email == email).first(): |
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
from functools import singledispatch | |
from abc import ABCMeta, abstractmethod | |
class CriterionMeta(ABCMeta): | |
def __new__(mcls, name, bases, attrs): | |
dispatcher = singledispatch(attrs['_default']) | |
attrs.update({'_dispatcher': dispatcher, 'register': dispatcher.register}) | |
return super(CriterionMeta, mcls).__new__(mcls, name, bases, attrs) |
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
from .command_bus import DefaultCommandBus, ValidatingCommandBus, LoggingCommandBus, SupportsSelfExecution | |
from .command_name_formatters import (ChangeToOn_CommandName, ChangeToLowerCaseCommandName, | |
RemoveCommandFromName, MultipleCommandNameFormatter) | |
from .command_validators import LogsFailedValidationsValidator, GenerousMappingCommandValidator | |
from .commands import HelloPersonCommand, HelloPersonHandler | |
from .dependencies import DependencyStore, BasicDependencySatsifier | |
from .displayer import CallableDisplayer | |
from .formatter import StringFormatter | |
from .inflector import (CallableOrNextInflector, DefaultInflector, InstantiatingInflector | |
CommandNameInflector, MultipleCommandNameInflector, FirstOneWinsInflector) |
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 UserNotFound(Exception): | |
@classmethod | |
def by_username(cls, username): | |
return cls("No user found with username: {0}".format(username)) | |
def find_user(username): | |
user = User.query.filter_by(username==username).first() | |
if not user: | |
raise UserNotFound.by_username(username) | |
return user |
OlderNewer