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 django.core import serializers | |
f = open('dic_user_status.json', b'w') | |
json = serializers.serialize("json", DicUserStatus.objects.all()) | |
f.write(json) | |
f.close() |
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 requests | |
CLIENT_ID = 'wxzr4lZtT3W4uZd3kOlHdteeugUjmUDT4lbYJkh6' | |
CLIENT_SECRET = 'xItJryuKsaAcLk9fAp6OZXd4vKaD4WZ96jxxcLHVehog80TMWEr9NtdM5hz8xvz9eEtR0XXQgfnQdUTAj6Fieb2b5u0OrdPHhp7f2ntif9GfI2bfVPz2Wxg2JQJakb2c' | |
TOKEN_URL = 'http://localhost:8000/api/v2/auth/user/auth/' | |
USERNAME = 'username' | |
PASSWORD = 'password' |
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
def create_all_positions(max_x, max_y): | |
all_positions = list() | |
for row in xrange(1, max_y+1): | |
all_positions.append([(col, row) for col in xrange(1, max_x+1)]) | |
return all_positions | |
def get_next_empty(all_positions, used_positions): | |
for row in all_positions: | |
for position in row: |
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 datetime | |
import time | |
dt = datetime.datetime(2010, 2, 25, 23, 23) | |
time.mktime(dt.timetuple()) |
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
# models mixin | |
class SyncMixin: | |
@classmethod | |
def get_sync_type(cls) -> int: | |
"""Returns sync type.""" | |
raise NotImplemented() | |
@classmethod | |
def get_sync_model(cls): | |
"""Returns django.db.Model child class. |
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 asyncio | |
class Awaitable: | |
def __await__(self): | |
yield | |
async def main(): | |
await Awaitable() |
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
def to_minutes(wd, h, m): | |
return wd * 24 * 60 + h * 60 + m | |
def from_minutes(minutes): | |
wd = minutes // (24 * 60) | |
rest = minutes - (wd * 24 * 60) | |
return wd, rest // 60, rest % 60 | |
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 inspect | |
from typing import List, TypeVar, Type, Set | |
T = TypeVar('T') | |
def find_subclasses(cls: Type[T], deep=True) -> List[Type[T]]: | |
res: List[Type[T]] = [] | |
subclasses: List[Type[T]] = cls.__subclasses__() | |
for subclass in subclasses: |
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 asyncio | |
import asyncpg | |
async def main(): | |
conn: asyncpg.Connection = await asyncpg.connect() | |
def callback(c: asyncpg.Connection, pid: int, ch: str, p: str): | |
print(c, pid, ch, p) |
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 peewee import * | |
User = Table('users', ('id', 'username')) | |
s = Select().columns('id', 'username').from_(User) | |
sub = Select().columns(s.c.id, s.c.username).from_(s) | |
print(s.c) | |
print(s._returning) | |
print(sub._returning) |