Skip to content

Instantly share code, notes, and snippets.

difflib
textwrap
datetime
calendar
collections (not collections.abc)
heapq
bisect
array
pprint
enum
import functools
def debug(message="*** DEBUG"):
def wrapper(func):
@functools.wraps(func)
def inner(*p, **kw):
print(message)
return func(*p, **kw)
return inner
return wrapper
def foo_printer(foo)
def inner():
print(foo)
return inner
printer = foo_printer("foo!")
printer() # prints foo
@tritium21
tritium21 / dupe.py
Last active November 28, 2018 08:01
the jankiest deduper that actually works
#!/usr/bin/env python3
from argparse import ArgumentParser, ArgumentTypeError
from collections import defaultdict
from hashlib import sha3_224 as sha3
from itertools import chain
from pathlib import Path
from re import split
def keep_input(default, dupe):
while True:
import datetime
import math
import sys
def main(argv):
try:
goal = int(argv[1])
current = float(argv[2])
except:
return f"Usage: {argv[0]} <goal:int> <current:int>"
@tritium21
tritium21 / atomic_file.py
Created February 26, 2018 02:21
Is this insane?
import contextlib
import ctypes
import os
import os.path
import shutil
import sys
import tempfile
@contextlib.contextmanager
Get-ChildItem -Path . -Recurse -Directory`
| Where-Object {(Get-ChildItem -Attributes Hidden, !Hidden $_.FullName | Measure-Object | %{$_.Count}) -eq 0}`
| Remove-Item
import json
import datetime
class DateTimeDecoder(json.JSONDecoder):
def __init__(self, *args, **kargs):
json.JSONDecoder.__init__(
self,
object_hook=self.dict_to_object,
*args,
**kargs
import asyncio
import aiohttp
URLS = [
"https://google.com",
"https://github.com",
"https://example.org",
]
DONE = {}
import asyncio
import aiohttp
URLS = [
"https://google.com",
"https://github.com",
"https://example.org",
]
DONE = {}