Skip to content

Instantly share code, notes, and snippets.

Petr Messner messa

View GitHub Profile
View aiohttp_graphql_server_minimal_example.py
from aiohttp import web
from aiohttp_graphql import GraphQLView
from graphql.execution.executors.asyncio import AsyncioExecutor
from graphql import (
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLField,
GraphQLNonNull,
GraphQLString,
View async_context_stack_example.py
import asyncio
from contextlib import contextmanager, asynccontextmanager, AsyncExitStack
@contextmanager
def stuff(name):
print('Opening', name)
yield
print(f'Closing {name}')
View gist:5ded8deeef4175ca0b016b4244e2f2df
https://docs.google.com/presentation/d/1YUT0WPmqJt1tn4MaqWqVctzslT4wuCNHiaok0Ii665o/edit?usp=sharing
@messa
messa / Dockerfile
Last active Nov 11, 2018
now.sh v1 Flask demo
View Dockerfile
FROM alpine
RUN apk add py3-flask py3-gunicorn
COPY hello.py .
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "hello:app"]
@messa
messa / yaml_dump.py
Created Jun 21, 2018
YAML str representer
View yaml_dump.py
import yaml
def yaml_dump(obj):
return yaml.dump(obj, width=120, default_flow_style=False, Dumper=_CustomDumper)
class _CustomDumper (yaml.SafeDumper):
pass
def _str_representer(dumper, data):
style = '|' if '\n' in data else None
View di_container_example.py
# my_app/container.py
from .clients import ShopifyClient
from .model import Model, connect_db
from .util import System
factories = {
'system': lambda cx: System(), # obsahuje wrapper okolo datetime a tak, pro snadnější mockování v testech
'model': lambda cx: Model(db=connect_db(cx['conf'].db), system=cx['system']),
'shopify_client': lambda cx: ShopifyClient(cx['conf'].shopify),
View funkce.py
x = 11
def f():
x = 22
print('uvnitr f:', x)
print(x)
f()
print(x)
# Výstup programu:
#
@messa
messa / Makefile
Last active Nov 15, 2017
Graphviz naučse demo
View Makefile
importy.png: importy.dot
dot -Tpng importy.dot > importy.png
View aws_logger_demo.py
#!/usr/bin/env python3
import boto3
from datetime import datetime
import logging
import socket
from time import time, sleep
logger = logging.getLogger(__name__)
View dependency_container.py
#!/usr/bin/env python3
'''
Inspired by pytest fixtures :)
'''
import argparse
from inspect import signature
import logging
from reprlib import repr as smart_repr
You can’t perform that action at this time.