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 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 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 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 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
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 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 flask import Flask, request | |
from flask.ext.restful import Resource, Api | |
from flask.ext.sqlalchemy import SQLAlchemy | |
from marshmallow import Schema, post_dump | |
app = Flask(__name__) | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///quotes.db' | |
api = Api(app) |
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 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 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
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 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 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 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 operator import attrgetter | |
from hashlib import md5 # because it's fast | |
class BaseRepository(object): | |
def find(self, pk): | |
raise NotImplementedError() | |
def find_by(self, **keys): | |
raise NotImplementedError() |
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
@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 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 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) |
OlderNewer