Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View messa's full-sized avatar

Petr Messner messa

View GitHub Profile
@messa
messa / cykly.py
Created April 11, 2019 17:59
Pyladies opakovani 2019-04-11
def ruzne_ctverce():
for delka_strany in 2, 5, 7:
ctverec(delka_strany, symbol='O')
def ctverec(n, symbol='X'):
for cislo_radku in range(n):
for cislo_sloupce in range(n):
if (
@messa
messa / aiohttp_graphql_server_minimal_example.py
Created January 13, 2019 13:24
Aiohttp GraphQL server example
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,
import asyncio
from contextlib import contextmanager, asynccontextmanager, AsyncExitStack
@contextmanager
def stuff(name):
print('Opening', name)
yield
print(f'Closing {name}')
https://docs.google.com/presentation/d/1YUT0WPmqJt1tn4MaqWqVctzslT4wuCNHiaok0Ii665o/edit?usp=sharing
@messa
messa / Dockerfile
Last active November 11, 2018 13:14
now.sh v1 Flask demo
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 June 21, 2018 14:42
YAML str representer
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
# 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),
x = 11
def f():
x = 22
print('uvnitr f:', x)
print(x)
f()
print(x)
# Výstup programu:
#
@messa
messa / Makefile
Last active November 15, 2017 09:54
Graphviz naučse demo
importy.png: importy.dot
dot -Tpng importy.dot > importy.png
#!/usr/bin/env python3
import boto3
from datetime import datetime
import logging
import socket
from time import time, sleep
logger = logging.getLogger(__name__)