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
-- Go.hs - Go Simulation | |
-- Author: Ben Simner | |
-- | |
-- A little incomplete Go simulator | |
module Go where | |
import qualified Data.Map as M | |
import Text.Read (readMaybe) | |
--import Debug.Trace (trace) --debugging |
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 python3 | |
''' | |
A Proper DocString | |
This does orbital stuff using PyQt5 | |
Now with real gravity! | |
Author: Ben Simner | |
Date: 2015-08-11 | |
''' |
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 random | |
import abc | |
class ArbyMeta(abc.ABCMeta): | |
_ARBYS = {} | |
def __init__(self, *args, **kwargs): | |
pass | |
def __new__(mcls, name, bases, namespace, _subtype=None): |
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
def f(n): | |
yield from g(n) | |
return n | |
def g(n): | |
for i in range(n): | |
yield i | |
i = g(2) | |
print(next(i)) # 0 |
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
def deep_tee(iterator, n=2): | |
it = iter(iterator) | |
gen = (x for x in range(1)) | |
gen_t = type(gen) | |
deques = [collections.deque() for _ in range(n)] | |
def gen(d): | |
while True: | |
if not d: | |
try: | |
v = next(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
import math | |
import collections | |
def pairs(n=2): | |
if n > 2: | |
initial_pair = pairs(n-1) | |
d = {} | |
if n == 1: | |
i = 0 |
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 | |
import os | |
import sys | |
import math | |
from bdb import Bdb | |
def trace(fName): | |
with open(fName, 'r') as f: | |
program = f.readlines() |
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
/* Atomic reference counter | |
* Example taken from Derek: http://www.mpi-sws.org/~dreyer/talks/talk-dagstuhl16.pdf | |
*/ | |
shared bool free; | |
shared int count; | |
thread bool f; | |
thread int c; |
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 itertools | |
class LazyStream: | |
'''This is a stream with 2 operations | |
> head | |
> tail | |
''' | |
_sentinal = object() | |
def __init__(self, iterator): |
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 C(type): | |
class __call__: | |
def __init__(*args): | |
print('__init__C', args) | |
def __call__(*args): | |
print('__call__C', args) | |
class D(type): | |
class __call__(metaclass=C): |
OlderNewer