Skip to content

Instantly share code, notes, and snippets.

View messa's full-sized avatar

Petr Messner messa

View GitHub Profile
@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__)
@messa
messa / dependency_container.py
Last active September 30, 2017 02:19
Processing engine
#!/usr/bin/env python3
'''
Inspired by pytest fixtures :)
'''
import argparse
from inspect import signature
import logging
from reprlib import repr as smart_repr
export default class PageLayout extends React.Component {
render() {
const {
children, siteTitleH1, mobileView, userAgent,
currentLanguage, enVersionUrl, csVersionUrl,
} = this.props;
let appBar = null;
@messa
messa / stream.py
Created July 19, 2012 19:07
Twitter Streaming API example
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import json
import oauth2 # https://raw.github.com/brosner/python-oauth2/master/oauth2/__init__.py
from pprint import pprint
import urllib2
stream_url = "https://stream.twitter.com/1/statuses/filter.json"
import flask
app = flask.Flask(__name__)
@app.route('/')
def index():
return 'ahoj <img src="/graf">'
@app.route('/graf')
def graf():