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 datetime | |
import webapp2 | |
from google.appengine.ext import db | |
from google.appengine.api import users | |
class MyUser(db.Model): | |
user = db.UserProperty() | |
# nickname = db.UserProperty() | |
date = db.DateTimeProperty(auto_now_add=True) |
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
def protocol(func): | |
"""Decorator to create protocol decorators for views from simple funcs. | |
A protocol is just a dictionary existing the 'protocols' property (which is | |
a dictionary by itself) of a registered view function. | |
Protocols should be used to tell something meaningful about a view to some | |
blueprint. For example, authentication blueprint can distinguish protected | |
views from views accessible by anonymous. | |
Protocol decorator has static method get() returning protocol info. |
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 MetaFabric(object): | |
backends = (test_base.PostgreSQLOpportunisticTestCase, | |
test_base.MySQLOpportunisticTestCase) | |
modules = ('trust', | |
'identity', | |
'contrib.oauth1', | |
'contrib.federation', | |
'contrib.endpoint_filter', | |
'token', |
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
def print_tree(node): | |
c_level = [node,] | |
while c_level: | |
print " ".join((i.val for i in c_level)) | |
n_level = [] | |
for i in c_level: | |
if i.left: | |
n_level.append(i.left) | |
if i.right: | |
n_level.append(i.right) |
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 random | |
def reader(n, path="big.txt"): | |
with open(path, 'rb') as iterative: | |
cache = [] | |
while n > 0: | |
try: | |
line = next(iterative) | |
if random.randint(1, 100) % 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
""" Asynchronous Fibonacci Server | |
##Solution | |
Any kind of caching is potentially expensive and unlikely to justify themselves in | |
comparison with generating of value, especially with small values of "n". | |
Asynchronous concurrent model was chosen because it is much more cheaper than | |
multithreading due to peculiar properties of Python threads. Since we are | |
dealing with extra simple application logic and architecture, aiohttp was chosen | |
on the grounds of exceptive simplicity. Also |
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 | |
import sys | |
def rotator(matrix): | |
n = len(matrix) | |
i = 0 | |
while i < n: | |
j = i | |
while j < n: |
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
""" | |
Benchmarking localhost (be patient) | |
Completed 10000 requests | |
Completed 20000 requests | |
Completed 30000 requests | |
Completed 40000 requests | |
Completed 50000 requests | |
Completed 60000 requests | |
Completed 70000 requests | |
Completed 80000 requests |
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
def longest(): | |
with open("data.txt", "rb") as file: | |
lengths = [len(i) for i in file] | |
return lengths.index(max(lengths)) |
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 Node(object): | |
def __init__(self, name, parent=None): | |
self.name = name | |
self.parent = parent | |
def __str__(self): | |
return self.name | |
def __repr__(self): | |
return self.__str__() |
OlderNewer