Skip to content

Instantly share code, notes, and snippets.

View Arachnid's full-sized avatar

Nick Johnson Arachnid

View GitHub Profile
from google.appengine.api import urlfetch
from google.appengine.api import xmpp
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import xmpp_handlers
import base64
import feedparser
import logging
class LazyRef(object):
def __init__(self, fullname):
self.fullname = fullname
self.ref = None
def __call__(self, *args, **kwargs):
if not self.ref:
modulename, objname = self.fullname.rpartition('.')
module = __import__(modulename, globals(), locals())
self.ref = module.__dict__[objname]
class DomainDispatchMiddleware(object):
def __init__(self, domain_apps, default_app):
"""Constructor.
Args:
domain_apps: A list of (regexp, application) tuples to dispatch to based on domain.
default_app: An app to run if no domain matches.
"""
self.domain_apps = domain_apps
self.default_app = default_app
application: filehangar
version: live
runtime: python
api_version: 1
handlers:
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
import csv
import heapq
import math
class Skyland(object):
def __init__(self, name, location):
self.name = name
self.location = location
self.neighbours = []
Aleut 30835 28010 5
ALPHA 1 27699 32516 8
ALPHA 2 32260 31402 1
ALPHA 3 29747 33441 8
ALPHA 4 31722 34644 7
ALPHA 5 32234 27853 5
ALPHA 6 31295 30871 3
ALPHA 7 35735 33825 5
ALPHA 8 33335 33005 3
ALPHA 9 28490 33645 8
def find_room_plans(plan, depth):
if depth == 0:
return [plan]
prev = plan[-1]
heads = [x[0] for x in prev]
ret = []
perms = []
unique_permutations(heads, perms)
for perm in perms:
if any(x[0] == y[0] for x,y in zip(heads, perm)):
def batch_get_lists(lists):
key_set = set()
for l in lists:
key_set.update(l)
all_keys = list(key_set)
all_entities = db.get(all_keys)
entity_dict = dict(zip(all_keys, all_entities))
return [[entity_dict[x] for x in l] for l in lists]
import bisect
class NFA(object):
EPSILON = object()
ANY = object()
def __init__(self, start_state):
self.transitions = {}
self.final_states = set()
self._start_state = start_state
application: zip-site
version: main
runtime: python
api_version: 1
handlers:
- url: /.*
script: main.py