Instantly share code, notes, and snippets.

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:
#
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
View gist:371afb36fb2527353c398649911c989b
export default class PageLayout extends React.Component {
render() {
const {
children, siteTitleH1, mobileView, userAgent,
currentLanguage, enVersionUrl, csVersionUrl,
} = this.props;
let appBar = null;
View flask_matplotlib_demo.py
import flask
app = flask.Flask(__name__)
@app.route('/')
def index():
return 'ahoj <img src="/graf">'
@app.route('/graf')
def graf():
View fizzbuzz.py
either = lambda a, b: lambda i: a(i) or b(i)
plus = lambda a, b: lambda i: a(i) + b(i)
div = lambda n: lambda i: i % n == 0
iff = lambda c, a, b: lambda i: a(i) if c(i) else b(i)
nothing = lambda x: ''
itself = lambda x: x
const = lambda x: lambda i: x
# some hints how it works :)
View bst_check.py
# from HackerRank.com
""" Node is defined as
class node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
"""
def check_binary_search_tree_(root, lower_bound=None, upper_bound=None):
if not root: