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 re | |
import sys | |
from collections import defaultdict | |
from pathlib import Path | |
import inspect | |
def run(f, argv = None, *, converters = None): | |
""" | |
Usage: | |
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 re | |
from pathlib import Path | |
def main(): | |
dir = Path('.') | |
for pi in dir.glob('**/*.asm'): | |
po = Path(str(pi).replace('.asm', '.hack')) | |
assemble(pi, po) | |
def assemble(pi, po): |
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
# Aaronson's Sentence | |
# https://oeis.org/A005224 | |
import re | |
import collections | |
from num2words import num2words | |
l = 1 | |
q = collections.deque() | |
def emit(txt): |
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
""" | |
Filter sharing convolution: https://arxiv.org/abs/1612.02575 | |
Excl. bias, has MNP+PS parameters (vs. MNS for regular conv). | |
""" | |
import functools | |
from keras import backend as K | |
from keras import activations, initializations, regularizers, constraints | |
from keras.engine import Layer, InputSpec |
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
class CaptureQueries(object): | |
""" | |
Context manager that captures queries executed by the specified connection. | |
Mostly copied from django.test.utils.CaptureQueriesContext. | |
""" | |
def __init__(self, connection = None): | |
if connection is None: | |
from django import db | |
connection = db.connection | |
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 project import urls | |
def main(): | |
for x in sorted(map(combine, list_urls(urls.urlpatterns))): | |
print x | |
def list_urls(urllist): | |
for entry in urllist: | |
if hasattr(entry, 'url_patterns'): | |
for x in list_urls(entry.url_patterns): |
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
class Box<T> { constructor(public value: T) {} } | |
class A {} | |
class B { foo() {} } | |
var bb : Box<B> = new Box<B>(null); | |
// This typechecks (it shouldn't; T is used both in a co- and contra-variant position, so it's invariant)... | |
var ba : Box<A> = xb; | |
ba.value = new A(); |
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 re import _MAXCACHE, _cache | |
from timeit import timeit | |
setup = ''' | |
from re import compile | |
def create_regex(n): | |
return compile(r'^(a*b*|a+c*|b*|c*)a*b*c*(a*|(b*|c*)){:03}$'.format(n)) | |
def run(n): |
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 threading import Thread | |
from time import sleep, time | |
from random import choice, random | |
from jinja2.utils import LRUCache | |
class MyLRUCache(LRUCache): | |
def __getitem__(self, key): | |
self._wlock.acquire() | |
try: |
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 itertools import izip, imap | |
from fractions import Fraction, gcd | |
def main(): | |
for x in rationals(): | |
print x | |
def rationals(): | |
yield Fraction() | |
NewerOlder