Skip to content

Instantly share code, notes, and snippets.

View abarnert's full-sized avatar

Andrew Barnert abarnert

View GitHub Profile
import functools
import inspect
def implicit_cast(f):
sig = inspect.signature(f)
def cast(param, arg):
typ = sig.parameters[param].annotation
if typ is sig.empty:
return arg
if isinstance(typ, str):
The problem is underspecified.
## Actual contiguus US states
All 48. There's only a handful of constraints (like ME has to be at the start or the end), and you can easily tell by inspection that they aren't going to conflict.
Or, just draw a route by hand, and you'll probably be able to hit 48 on the first try as long as you keep the constraints in mind. Here's my first attempt, from CA to ME mostly going up and back down a column at a time:
CA OR WA
ID UT NV AZ
@abarnert
abarnert / gist:5b4b2ee05c8ca3c283d097970cae9a18
Created June 26, 2019 21:34
Ugly code to redefine ->spam to mean ->eggs
// Compile with clang++ or g++ with -std=c++11
// (Doesn't actually need any C++11 features, just a bit more readable
// with auto, etc.)
#include <iostream>
struct pstatus;
struct status {
int eggs, spam;
import tkinter as tk
from time import *
from random import randint, choice
myInterface = tk.Tk()
s = tk.Canvas(myInterface, width=800, height=800, background="black")
s.pack()
xblock1 = 0
yblock1 = 0
import os
import sys
import time
print('Hi!')
time.sleep(1)
os.execl(sys.executable, sys.executable, *sys.argv)
@abarnert
abarnert / random.diff
Created September 10, 2015 08:01
Patch to `random` module to add `set_default_instance`, rename `Random` to `DeterministicRandom`, and to deprecate calling any functions without first setting a default instance to a `DeterministicRandom`, `SystemRandom`, or other subclass.
diff -r 18802076b52c Lib/random.py
--- a/Lib/random.py Wed Sep 09 22:46:51 2015 -0400
+++ b/Lib/random.py Thu Sep 10 00:58:04 2015 -0700
@@ -49,7 +49,7 @@
"expovariate","vonmisesvariate","gammavariate","triangular",
"gauss","betavariate","paretovariate","weibullvariate",
"getstate","setstate", "getrandbits",
- "SystemRandom"]
+ "SystemRandom","DeterministicRandom"]