Skip to content

Instantly share code, notes, and snippets.


Petri Savolainen petri

View GitHub Profile
petri /
Created Nov 27, 2020
test example
def test_cmdline_logging_info(caplog, capsys):
retv = tnefparse.cmdline.tnefparse(('-l', 'INFO', '-rb', 'tests/examples/rtf.tnef'))
assert not retv
stdout, _ = capsys.readouterr()
assert len(stdout) == 593
assert caplog.record_tuples == [
('tnefparse', logging.INFO, 'Skipping checksum for performance'),
def tnefparse(argv=None):
petri /
Last active Sep 28, 2020
generic helper awaitable to synchronize awaiters chronologically on a first-come first-served basis
class bouncer(Awaitable):
"serve awaiters on a first-come first-served basis"
queue = []
def __init__(self):
def caller(self):
petri /
Last active Sep 27, 2020
a first come, first served queing predicate for asyncio Condition
class my_turn:
"""a first come, first served coordinator predicate for
asyncio.Condition.wait_for(predicate); could also do away
the 'caller' by just hardcoding it to the current task
queue = []
def __init__(self, caller):
type(self).queue.insert(0, caller)
petri / gist:46bb6b8eac8ea5b8f01c90e7414d7951
Last active Sep 27, 2020 — forked from HQJaTu/gist:345f7147065f1e10587169dc36cc1edb
Python asyncio ordering test - single-connection multiplex version with asyncio.Queue
View gist:46bb6b8eac8ea5b8f01c90e7414d7951
#!/usr/bin/env python3
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python
# Proof-of-Concept for
# Do Python asyncio Streams maintain order over multiple writers and readers?
import sys
import argparse
petri /
Created Apr 26, 2020
Get all ordered n-size splices of a sequence in Python
def splice(sequence, size):
"return a list of all ordered splices of given size"
ss = len(sequence)
return [sequence[i:i+size] for i in range(0, ss-size+1)]
petri / hfst.rb
Last active Dec 9, 2018
hfst homebrew recipe
View hfst.rb
class Hfst < Formula
desc "Helsinki Finite-State Technology (library and application suite)"
homepage ""
url ""
sha256 "1ce90956d7c91d75e7c141e3852504b02728672239746858a141ccfae1712d19"
depends_on "automake"
depends_on "autoconf"
depends_on "libtool"
depends_on "bison"
petri /
Last active Oct 22, 2018
Common disambiguated country names
An attempt to produce a good enough list of commonly understandable country names
from pycountry straight-jacket names. Thus country names produced are without
prefixes such as "Republic of", and are also disambiguated from one another
(British & US Virgin Islands and Republic & Democratic Republic of Congo).
People living in the two countries both known as Congo call their country
either Congo-Kinshasa or Congo-Brazzaville, ie. adding the name of the capital;
we use that convention as an incremental means for additional disambiguation.
Also, liberty is taken to call Lao People's Democratic Republic just Laos, and
use the commonly known names North and South Korea, rather than the official
View gist:83ff7a07b0ab7f5a86d82ded33fd32c4
code {
background-color: red !important;
color: blue;
border: solid thin gray;
petri /
Last active Jul 11, 2018 — forked from Zireael-N/
Python script that calculates SHA1, SHA256, MD5 checksums of a given file. Similar to what you might accomplish with eg. ”openssl dgst -sha512 -binary | base64”
import hashlib
import os
import sys
if len(sys.argv) < 2:
sys.exit('Usage: %s filename' % sys.argv[0])
if not os.path.exists(sys.argv[1]):

Keybase proof

I hereby claim:

To claim this, I am signing this object: