Skip to content

Instantly share code, notes, and snippets.

View vskrachkov's full-sized avatar

Viacheslav Krachkov vskrachkov

View GitHub Profile
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()
import os
import requests
CLIENT_ID = 'wxzr4lZtT3W4uZd3kOlHdteeugUjmUDT4lbYJkh6'
CLIENT_SECRET = 'xItJryuKsaAcLk9fAp6OZXd4vKaD4WZ96jxxcLHVehog80TMWEr9NtdM5hz8xvz9eEtR0XXQgfnQdUTAj6Fieb2b5u0OrdPHhp7f2ntif9GfI2bfVPz2Wxg2JQJakb2c'
TOKEN_URL = 'http://localhost:8000/api/v2/auth/user/auth/'
USERNAME = 'username'
PASSWORD = 'password'
@vskrachkov
vskrachkov / n2.py
Created July 3, 2017 18:17
Get first not empty coordinates
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:
import datetime
import time
dt = datetime.datetime(2010, 2, 25, 23, 23)
time.mktime(dt.timetuple())
@vskrachkov
vskrachkov / sync.py
Last active February 25, 2018 20:43
# 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.
@vskrachkov
vskrachkov / awaitable.py
Created November 30, 2019 23:11
Create awaitable object in Python
import asyncio
class Awaitable:
def __await__(self):
yield
async def main():
await Awaitable()
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
@vskrachkov
vskrachkov / inspect.py
Created December 17, 2019 14:14
find subclasses and bases
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:
@vskrachkov
vskrachkov / pg_listener.py
Created December 30, 2019 17:30
listen notifications from postgresql using asyncpg
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)
@vskrachkov
vskrachkov / peewee_inspect.py
Created January 2, 2020 11:20
peewee python
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)