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
@dataclass | |
class Curried: | |
f: Callable | |
def __call__(self, *args, **kwargs): | |
f = partial(self.f, *args, **kwargs) | |
try: | |
signature(f).bind() | |
except TypeError: | |
return type(self)(f) | |
else: |
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 product | |
def score(self, other): | |
first = len([speg for speg, opeg in zip(self, other) if speg == opeg]) | |
return first, sum([min(self.count(j), other.count(j)) for j in 'ABCDEF']) - first | |
possible = [''.join(p) for p in product('ABCDEF', repeat=4)] | |
results = [(right, wrong) for right in range(5) for wrong in range(5 - right) if not (right == 3 and wrong == 1)] | |
def solve(scorefun): |
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 threading | |
from time import perf_counter as time | |
import random | |
from statistics import median, stdev | |
results = {'thread': [], 'call': []} | |
end = 0 | |
def inside(): | |
global end |
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
-- defdef.lua | |
-- default definitions for lua | |
-- By Robin Wellner (gvx) | |
-- I hereby waive copyright and related or neighboring rights to this work | |
-- See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/> | |
-- Evaluate truth like in Python | |
function is_true (arg) | |
if arg == '' or arg == 0 then |
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
#!/usr/bin/env python | |
# coding=utf-8 | |
# <a class="btn btn-default pull-right" href="https://gist.github.com/TylerShaw/48ead56c19ce905ac513"><i class="fa fa-git"></i> Download the gist here!</a> | |
# Py2Md started as a little project to do the magical "self documenting code". After thinking about it, I realized self documenting code is great, but it's really not the point. | |
# Commenting code properly, if only better, is the point. | |
# This script evolved from me wanting to code better. I often look at other peoples code, or even old code I've written, and it takes me a few minutes to even figure out what each section is doing. | |
# This will hopefully solve that, not only by forcing me to comment code better, but to publish my code with decent comments. | |
# This script reads in a python file (either itself, or anything it's | |
# imported into) and converts the python file into a markdown file. It |
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
last = None | |
with open('index.txt') as f: | |
for line in f: | |
new = int(line.decode('utf-8').split('\t', 1)[0]) | |
if last is not None: | |
if last - new > 1: | |
if last - new == 2: | |
print new + 1 | |
else: |
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 veri import Verified | |
class Something(metaclass=Verified): | |
# a single type | |
some_int = int | |
some_str = str | |
# a 'struct' using tuples | |
some_tuple = (int, int, str) | |
# a list of integers |
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 Alias(object): | |
def __init__(self, initial): | |
self._set = {initial} | |
self.initial = initial | |
def add(self, alias): | |
self._set.add(alias) | |
def merge(self, other): | |
self._set.update(other._set) | |
def __iter__(self): | |
return iter(self._set) |
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 sys | |
vowels = set('aeiouy') | |
consonants = set('bcdfghjklmnpqrstvwxz') | |
impossible_digraphs = ['aa', 'bg', 'bh', 'bk', 'bq', 'bw', 'bx', 'bz', 'cb', 'cf', 'cg', 'cj', 'cm', 'cp', 'cv', 'cw', 'cx', 'cz', 'dx', 'dz', 'fc', 'fd', 'fg', 'fj', 'fk', 'fn', 'fp', 'fq', 'fv', 'fw', 'fx', 'fz', 'gc', 'gj', 'gk', 'gq', 'gv', 'gx', 'gz', 'hj', 'hk', 'hq', 'hv', 'hx', 'hz', 'ij', 'iy', 'jb', 'jc', 'jd', 'jf', 'jg', 'jh', 'jj', 'jk', 'jl', 'jm', 'jn', 'jp', 'jq', 'jr', 'js', 'jt', 'jv', 'jw', 'jx', 'jy', 'jz', 'kq', 'kv', 'kx', 'kz', 'lj', 'lx', 'md', 'mj', 'mk', 'mq', 'mx', 'mz', 'pg', 'pj', 'pq', 'pv', 'px', 'pz', 'qa', 'qb', 'qc', 'qd', 'qe', 'qf', 'qg', 'qh', 'qi', 'qj', 'qk', 'ql', 'qm', 'qn', 'qo', 'qp', 'qq', 'qr', 'qs', 'qt', 'qv', 'qw', 'qx', 'qy', 'qz', 'rx', 'sx', 'sz', 'tq', 'tx', 'uj', 'uq', 'uw', 'uy', 'vb', 'vc', 'vd', 'vf', 'vg', 'vh', 'vj', 'vk', 'vl', 'vm', 'vn', 'vp', 'vq', 'vr', 'vs', 'vt', 'vv', 'vw', 'vx', 'vz', 'wj', 'wk', 'wp', 'wq', 'wv', 'ww', 'wx', 'wz', 'xb', 'xf', 'xg', 'xj', 'xk', 'xm', |
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
%{ | |
#include "units.tab.c" | |
%} | |
%option noyywrap | |
int -?[0-9]+ | |
%% | |
[ \t] /*empty*/ |