This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
Construct a tarball from a blob summary | |
''' | |
import argparse | |
import tarfile | |
import ruamel.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env/python3 | |
import hashlib | |
import sys | |
import tarfile | |
with tarfile.open(fileobj=sys.stdin.buffer, mode='r|') as tf: | |
for member in tf: | |
if member.isfile(): | |
with tf.extractfile(member) as mf: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _DEFAULT_SOURCE | |
#define _GNU_SOURCE | |
#include <dirent.h> | |
#include <err.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
/* Compile with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def corange(end): | |
i = 0 | |
while i < end: | |
v = yield i | |
if isinstance(v, int): | |
end = v | |
i += 1 | |
for i in (r := corange(10)): | |
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EVENS = object() | |
STOP = object() | |
class CM(): | |
def __init__(self, n=10): | |
print('__init__() called') | |
self.n = n | |
self._it = iter(range(n)) | |
self._evens = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import re | |
import dateparser | |
def fudge_datetime(s: str, now: datetime.datetime = None) -> datetime.datetime: | |
""" | |
Return a best guess datetime for the free-form string s, relative to now. | |
>>> fudge_datetime("Christmas Day 2020") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
from dataclasses import dataclass | |
from typing import NamedTuple | |
import pyperf | |
@dataclass | |
class DataclassPet: | |
legs: int | |
noise: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import re | |
class timedelta(datetime.timedelta): | |
def __format__(value, format_spec): | |
if not format_spec: | |
return str(value) | |
pattern = re.compile(r'%([WdDhHmMsSuUT%])') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import multiprocessing | |
import pprint | |
import sys | |
import psutil | |
print("Before", flush=True) | |
pprint.pprint([(p.pid, p.status(), ' '.join(p.cmdline())) for p in psutil.Process().children()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
class S(collections.UserList): | |
def __mul__(self, other): | |
if isinstance(other, S): | |
return S([(a, b) for a in self for b in other]) | |
return super().__mul__(other) | |
def __add__(self, other): | |
if isinstance(other, S): |