Skip to content

Instantly share code, notes, and snippets.

View messa's full-sized avatar

Petr Messner messa

View GitHub Profile
@messa
messa / sifra.py
Created May 30, 2011 18:46
Python example - decryption of simple substitution cipher using recursion
#!/usr/bin/env python
from StringIO import StringIO
import unittest
import sys
sys.setrecursionlimit(4000)
def resolve(ciphertext, allWords):
@messa
messa / Dockerfile
Last active May 25, 2023 00:32
Building graph-tool in Docker
FROM debian:stretch
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y apt-utils wget bzip2
WORKDIR /src
@messa
messa / demo.py
Last active September 19, 2022 03:32
MongoDB pymongo bulk update all documents in a collection
#!/usr/bin/env python3
from bson import MinKey
import pymongo
from pymongo import ASCENDING
client = pymongo.MongoClient()
db = client['test']
collection = db['dataset']
#!/usr/bin/env python3
from argparse import ArgumentParser
from asyncio import run, get_running_loop, sleep, create_task
from logging import getLogger
from pathlib import Path
from dnslib import DNSRecord, DNSHeader, DNSQuestion, RR, A
logger = getLogger(Path(__file__).with_suffix('').name)
@messa
messa / openssl.conf
Last active April 12, 2022 04:52
Sample OpenSSL configuration for local CA; see my CA guide: https://github.com/messa/tips/blob/master/OpenSSL.md
[ ca ]
default_ca = CA_default
[ CA_default ]
dir = /XXX/root-ca
certs = $dir/certs
crl_dir = $dir/crl
new_certs_dir = $dir/newcerts
database = $dir/index.txt
serial = $dir/serial
@messa
messa / asyncio_ssl_example.py
Created June 26, 2015 12:43
Python asyncio + SSL TCP client/server example
#!/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 March 17, 2021 03:52
Aiohttp request_id logging
# 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
#!/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)
#!/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__)
#!/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__)