Skip to content

Instantly share code, notes, and snippets.

View nobbynobbs's full-sized avatar
👀
who's there?

Roman nobbynobbs

👀
who's there?
  • Nizhny Novgorod, Russia
View GitHub Profile
@nobbynobbs
nobbynobbs / main.py
Last active January 23, 2020 21:37
Marshmallow nested Schema
"""
dependencies:
flask = "^1.1.1"
flask_marshmallow = "^0.10.1"
flask_sqlalchemy = "^2.4.1"
marshmallow-sqlalchemy = "^0.21.0"
"""
import sys
@nobbynobbs
nobbynobbs / q50550830.py
Last active May 27, 2018 11:27
answer for stackoverflow
import lxml.etree as ET
import csv
# load file
tree = ET.parse('users.xml')
# iterate through each user tag
users = tree.findall('.//user')
all_roles = list({role.find('name').text for role in tree.findall('.//role')})
# just w mode, no wb. wb for binary data
with open('user_list.csv', "w") as csv_file:
@nobbynobbs
nobbynobbs / app.py
Created April 30, 2019 16:23
aiohttp-server-and-session
from aiohttp import web, ClientSession
from aiohttp.web import middleware
async def search(request):
q = request.query.get("q", "")
session = request.app["client_session"]
async with session.get("https://ya.ru", params={"q": q}) as request:
body = await request.read()
return web.Response(body=body, headers={"content-type": "text/html"})
@nobbynobbs
nobbynobbs / main.py
Created June 17, 2019 08:58
logging example
import logging
import requests
# init simpliest custom logger
logger = logging.getLogger("myAwesomeLogger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
@nobbynobbs
nobbynobbs / store_parser.py
Last active October 22, 2019 15:17
simple parser
import pprint
from collections import namedtuple
# fields names mapping
fields = {
"Название": "name",
"Сорт": "sort",
"Цена": "price",
"Картинка": "image",
}
@nobbynobbs
nobbynobbs / install_geospatial_libs.sh
Last active November 10, 2019 13:51
how to install geospatial libraries for python on ubuntu 18.04 (GDAL, mapnik)
# GDAL
sudo apt install gdal-bin libgdal-dev
pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal"
# MAPNIK
sudo apt install mapnik-utils libmapnik-dev libboost-all-dev
mapnik-config -v # check mapnik version
@nobbynobbs
nobbynobbs / test_ws_in_twisted.py
Last active April 6, 2020 06:46
py27, twisted, autobahn
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import
import base64
import pytest
import pytest_twisted
from typing import Dict, Any, List
import abc
class Repository(abc.ABC):
def __init__(self, model):
self.model = model # or connection pool
def create_one(self, data: Dict[str, Any]):
item = self.model.from_dict(data)
import math
import signal
from concurrent.futures import ProcessPoolExecutor
from contextlib import suppress
from time import sleep
values = [40000000, 30000000, 20000000, 10000000]
PRIMES = [
112272535095293,
@nobbynobbs
nobbynobbs / generic_descriptors.py
Created October 31, 2020 11:52
generic descriptor and inheritance
from typing import (
Generic, Optional, TYPE_CHECKING,
Type, TypeVar, Union, overload,
)
T = TypeVar("T", bound="A") # noqa
class Descr(Generic[T]):
@overload