Replace hierarchical directories with categories.
/foo
- Contains all files in the category foo
.
/foo/bar
# tail_recurse decorator | |
# decorated function should return its base case, and yield the arguments for | |
# the recursion step (yielded value must be starable) | |
def tail_recurse(f): | |
def inner(*args, **kwargs): | |
ret = f(*args, **kwargs) | |
while True: | |
try: | |
recursion_args = next(ret) |
import re | |
import sys | |
args = sys.argv[1:] | |
def find_dependencies(lines): | |
deps = set() | |
for line in lines: | |
match = re.match('#include "(.*)"', line) | |
if match: |
def twentyone(nums, stack=[]): | |
for index, num in enumerate(nums): | |
new_stack = stack + [num] | |
total = sum(new_stack) | |
if total == 21: | |
yield new_stack | |
elif total < 21: | |
yield from twentyone(nums[index+1:], new_stack) | |
print(list(twentyone([1,9,11,5,6]))) |
def is_prime(n): | |
return all(n % i != 0 for i in range(2, 1 + int(n**0.5))) | |
def get_primes(): | |
n = 2 | |
while True: | |
if is_prime(n): | |
yield n | |
n += 1 |
# Tools | |
def typematcher(*objects): | |
def inner(*types): | |
assert(len(objects) == len(types)) | |
return all(isinstance(obj, typ) for obj, typ in zip(objects, types)) | |
return inner | |
def recursive_construct(f, base, n=0): | |
yield base | |
if n > 0: |
# Type-checked functions in python (!) | |
# This is a terrible idea | |
embeddings = {} | |
def signature(*sigtypes): | |
def decorator(func): | |
def wrapped(*args): | |
types = sigtypes | |
if types[-1] == Ellipsis: |
#!/usr/bin/env python3 | |
import multiprocessing.pool | |
import subprocess | |
ARGS_FILE_NAME = '.youtube-archive' | |
USAGE = """\ | |
Usage: {0} [SEARCH OPTIONS] [-- [DOWNLOAD OPTIONS]] | |
OPTIONS are passed to youtube-dl for finding videos |
import os | |
import re | |
US_DATE_REGEX = re.compile(r'(\d\d)-(\d\d)-(\d\d\d\d)') | |
def parse_name(name): | |
match = US_DATE_REGEX.search(os.path.basename(name)) | |
if match: | |
month, day, year = map(int, match.groups()) |
MIT License
Copyright (c) 2017 Louis Warren
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: