Skip to content

Instantly share code, notes, and snippets.

# if you can easily fit it in less than one and a half tweets, I don't think it
# deserves to be called a "project"
from string import ascii_uppercase as u, ascii_lowercase as l; c = lambda m, n: ''.join((chr((ord(c)-97+n)%26+97) if c in l else chr((ord(c)-65+n)%26+65)) if c in l+u else c for c in m)
@zackmdavis
zackmdavis / bear_hunt.py
Last active May 7, 2017 01:33
bear hunt
from collections import OrderedDict
OBSTACLES = OrderedDict([('grass', ("long, wavy", "swishy-swashy")),
('a river', ("deep, cold", "splash-splosh")),
('mud', ("thick, oozy", "squelch-squerch")),
('a forest', ("big, dark", "stumble-trip"))])
def hunting_anthem():
print("We're going on a bear hunt, &c.")
# Alison asks—
#
# once i have a dictionary mapping one thing to a list of things
# how do i generate tuples of the one thing to each of the things in the list
# of the things it is mapped to
# e.g. { a : [ (1, 2), (2, 4) ], b : [ (3, 5), (7, 9) ] }
# to [(a, 1, 2), (a, 2, 4), (b, 3, 5), (b, 7, 9)]
# My reply—
from typing import Optional, TypeVar
T = TypeVar('T')
U = TypeVar('U')
def option_map(arg: Optional[T], fn: Callable[[T], U]) -> Optional[U]:
if arg is not None:
return fn(arg)
else:
return None
def outer():
def inner():
print(p)
p = 1
inner()
outer()
@zackmdavis
zackmdavis / rustc_build_failure.txt
Created June 20, 2018 04:46
rustc fails to build
zmd@ReflectiveCoherence:~/Code/rust$ RUST_BACKTRACE=full ./x.py test src/test/ui --bless --stage 1 --jobs 10
Updating only changed submodules
Submodules updated in 0.03 seconds
Finished dev [unoptimized] target(s) in 0.22s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Finished release [optimized] target(s) in 0.18s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Finished release [optimized] target(s) in 0.17s
Copying stage0 test from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
@zackmdavis
zackmdavis / rustc_build_failure_redux.txt
Created June 20, 2018 04:50
rustc fails to build, again
zmd@ReflectiveCoherence:~/Code/rust$ RUST_BACKTRACE=full ./x.py test --stage 1
Updating only changed submodules
Submodules updated in 0.03 seconds
Finished dev [unoptimized] target(s) in 0.20s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Finished release [optimized] target(s) in 0.18s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 tool tidy (x86_64-unknown-linux-gnu)
Finished release [optimized] target(s) in 0.17s
tidy check
@zackmdavis
zackmdavis / possibilities.py
Created August 12, 2018 04:36
generate structs to exercise the explicit-outlives-requirements lint
import itertools
test = ""
signatures = set()
specs = []
def bound_type(bound):
if bound.startswith("'"):
return "lifetime"
@zackmdavis
zackmdavis / power.md
Last active May 11, 2019 19:10
power ponies siege code

Power Ponies siege code zaYk3hKfpxv1N0WeZxgpcvU3RZ5nGCly5r+YVxyNxPv1N0WeZxgpcvU3RZ5nGCly9TdFnmcYKXLmv5hXHI3E+/U3RZ5nGCly9TdFnmcYKXL1N0WeZxgpcua/mFccjcT7kAIMhvHUIvMo+vz/0H+jaWjMZJmJJJdCS+gXGtWFwOMDc07AAAkoiZIyY5MUj991ikbJKirP1vlAfvSDor9b6V7bg/EyaWsLFDW5zKqYMkCnb1pW2VPEhGfPqLOnGxZy/vWpSOjM81nHUZikE9djdA==