This file contains hidden or 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 heapq | |
class EventReactor(object): | |
"""Processes a set of EventStream and executes their events in order.""" | |
def __init__(self): | |
self.time = 0.0 # Current time | |
self.events = [] # Holds (time, event function, stream) tuples in a heapq | |
def add_stream(self, stream): | |
"""Adds an event stream to the reactor. |
This file contains hidden or 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 prefetch_refprops(entities, *props): | |
fields = [(entity, prop) for entity in entities for prop in props] | |
ref_keys = set(prop.get_value_for_datastore(x) for x, prop in fields) | |
ref_keys.discard(None) | |
ref_entities = dict((x.key(), x) for x in db.get(ref_keys)) | |
for (entity, prop), ref_key in zip(fields, ref_keys): | |
prop.__set__(entity, ref_entities[ref_key]) | |
return entities |
This file contains hidden or 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
char data[10]; | |
for(int i = 0; i < 9; i++) | |
data[i] = Serial.read(); | |
data[9] = '\0'; | |
int r, g, b; | |
sscanf(data, "%3x%3x%3x", &r, &g, &b); | |
// r, g and b now contain the color values |
This file contains hidden or 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
// Flags for the direction register | |
#define FLAG_M1_CCW 0 | |
#define FLAG_M1_CW 1 | |
#define FLAG_M2_CCW 2 | |
#define FLAG_M2_CW 3 | |
// Flags for the inopts register | |
#define FLAG_PULLUP_I1 0 | |
#define FLAG_PULLUP_I2 1 | |
#define FLAG_INVERT_I1 2 |
This file contains hidden or 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
+V----------------+ | |
| # # # < | |
| # # # # # ######| | |
| # # # # # | | |
| # # # # ########| | |
| # # # # # | | |
| # # # # # ######| | |
| # # # | | |
|######## ####### | | |
| | |
This file contains hidden or 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
<ns0:kml xmlns:ns0="http://www.opengis.net/kml/2.2"> | |
<ns0:Document> | |
<ns0:Style id="BasicStyle"> | |
<ns0:BalloonStyle> | |
<ns0:text>$[description]</ns0:text> | |
</ns0:BalloonStyle> | |
<ns0:IconStyle> | |
<ns0:color>FFFFFFFF</ns0:color> | |
<ns0:scale>1.1</ns0:scale> | |
<ns0:hotSpot x="0.5" xunits="fraction" y="0" yunits="fraction" /><ns0:Icon> |
This file contains hidden or 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
application: zip-site | |
version: main | |
runtime: python | |
api_version: 1 | |
handlers: | |
- url: /.* | |
script: main.py |
This file contains hidden or 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 bisect | |
class NFA(object): | |
EPSILON = object() | |
ANY = object() | |
def __init__(self, start_state): | |
self.transitions = {} | |
self.final_states = set() | |
self._start_state = start_state |
This file contains hidden or 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 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] |
This file contains hidden or 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 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)): |