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 wsgiref.simple_server import make_server | |
from webob.dec import wsgify | |
def node(mapping): | |
def deco(func): | |
def wrapper(request): | |
try: | |
called_count = request.environ['nodechain.chaincount'] | |
except KeyError: |
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 block.chain import chain, MaybeF | |
def fib(ctx, x): | |
x.append(x[-2] + x[-1]) | |
return x | |
print chain.chain.do(fib).do(fib).do(fib).do(fib).value(MaybeF(), [1, 1]) |
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 copy | |
class AttributeSupplier(object): | |
def __init__(self, *args): | |
self.consts_module = __import__(*args) | |
def __getattr__(self, name): | |
return copy.deepcopy(getattr(self.consts_module, name)) | |
consts = AttributeSupplier('constant_values', globals(), locals(), ['app', 'consts']) |
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
config.add_chart_type('linechart', 'tochart.charts.Linechart') | |
config.add_chart_backend('highcharts', 'tochart.backends.Highcharts') | |
@tochart_config('daily.linechart.highcharts', | |
chart_type='linechart', | |
chart_backend='highcharts') | |
def daily(request, data) | |
x = 1 | |
y = 2 | |
return [(x, y), (x, y)] |
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 chain | |
import multiprocessing | |
import socket | |
import sys | |
def static_view(env, start_response): | |
mes = 'test' | |
start_response('200 OK', [('Cache-Control', 'private'), | |
('Content-Type', 'text/html'), |
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 django.db import models | |
from .storage import AsyncFileSystemStorage | |
a_fs = AsyncFileSystemStorage() | |
class UploadedFile(models.Model): | |
image = models.ImageField('Uploaded image file', upload_to='.', storage=a_fs) |
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 CoreModel(object): | |
def __init__(self, name, published=False): | |
self.name = name | |
self.published = published | |
def publish(self): | |
self.publish = True | |
def unpublish(self): | |
self.publish = False |
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 MongoDBBackend(object): | |
def __init__(self, db, user): | |
self.db = db | |
self.user = user | |
def inc_feature(self, feature, cat): | |
"""特徴 feature がカテゴリ cat に出現した回数を 1 増やす""" | |
features = self.db.features.find({'user': self.user, | |
'feature': feature, | |
'category': cat}) |
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
chunker1 = lambda xs: zip(xs[:-1:2], xs[1::2]) | |
chunker2 = lambda xs: [xs[i:i+2] for i in range(0,len(xs),2)] | |
def chunker3(xs): | |
i = 0 | |
while xs[i:i+2]: | |
yield xs[i:i+2] | |
i += 2 |
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 colandar | |
class InvalidChoice(Exception): | |
pass | |
class Choice(str): | |
"""Class for choice value of some schema | |
""" |