Skip to content

Instantly share code, notes, and snippets.

View mynameisfiber's full-sized avatar

Micha Gorelick mynameisfiber

View GitHub Profile
@mynameisfiber
mynameisfiber / multigram_search.py
Last active August 29, 2015 14:10
MultigramSearch looks up instances of ngrams within a target text
#!/usr/bin/env python2.7
"""
>>> import multigram_search
>>> mgs = multigram_search.MultigramSearch([("a", "b", "c"), ("o", "c", "z"),
('z','y')])
>>> list(mgs.intersection("hello world you a b c foo".split(" ")))
[['a', 'b', 'c']]
@mynameisfiber
mynameisfiber / limited_cache.py
Created February 4, 2013 21:11
Simple dictionary caching object that limits the number of cached entries beingstored.
"""
Simple dictionary caching object that limits the number of cached entries being
stored.
Micha Gorelick - http://micha.gd/
"""
from collections import OrderedDict
class LimitedCache(OrderedDict):
def __init__(self, maxsize=250):
import re
def check_winner(board,row=4):
try:
return re.search(r"([^.|])(\1{%d}|%s)"%(row-1,"|".join(r"(.{%d}\1){%d}"%(len(a[0])+d,row-1) for d in range(-1,2))), "|".join("".join(x) for x in a)).group()[0]
except:
return "No one"
if __name__ == "__main__":
a = [