Skip to content

Instantly share code, notes, and snippets.

Avatar

Petr Messner messa

View GitHub Profile
@messa
messa / asyncio_ssl_example.py
Created Jun 26, 2015
Python asyncio + SSL TCP client/server example
View asyncio_ssl_example.py
#!/usr/bin/env python3
import asyncio
import multiprocessing
import os
import ssl
from time import sleep
port = 9000
@messa
messa / aiohttp_request_id_logging.py
Last active Mar 17, 2021
Aiohttp request_id logging
View aiohttp_request_id_logging.py
# BTW. I have created a library for this: https://github.com/messa/aiohttp-request-id-logging
from aiohttp import web
from aiohttp.web_log import AccessLogger
import asyncio
from asyncio import CancelledError
from contextvars import ContextVar
import logging
import os
import secrets
@messa
messa / demo.py
Last active Feb 1, 2021
MongoDB pymongo bulk update all documents in a collection
View demo.py
#!/usr/bin/env python3
from bson import MinKey
import pymongo
from pymongo import ASCENDING
client = pymongo.MongoClient()
db = client['test']
collection = db['dataset']
@messa
messa / Dockerfile
Last active Jan 25, 2021
Building graph-tool in Docker
View Dockerfile
FROM debian:stretch
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y apt-utils wget bzip2
WORKDIR /src
View replace_line.py
#!/usr/bin/env python3
from argparse import ArgumentParser
from pathlib import Path
def replace_line(path, line_number, text):
if isinstance(text, str):
text = text.encode()
assert isinstance(text, bytes)
View requests_asyncio_example.py
#!/usr/bin/env python3
import asyncio
import logging
from pprint import pprint
from reprlib import repr as smart_repr
import requests
logger = logging.getLogger(__name__)
View aiohttp_example.py
#!/usr/bin/env python3
from aiohttp import ClientSession
import asyncio
import logging
from pprint import pprint
from reprlib import repr as smart_repr
logger = logging.getLogger(__name__)
View rtail.py
#!/usr/bin/env python
"""
Usage:
./rtail.py user@host:path/foo.log bar.log host2:/path/baz.log
"""
import optparse
import os
View 2020_02_20_radky.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View vypocet_lhuty_s_hlubokym_zrusenim.py
from datetime import date, datetime, timedelta
def main():
events = [
ZakladniInterval(dt('2020-01-01'), dt('2030-01-01')),
Prodlouzeni(id=222, roky=3),
Zruseni(id=333, zrusit_id=222),
Zruseni(id=444, zrusit_id=333),
Zruseni(id=555, zrusit_id=444),