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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
</head> | |
<body> | |
<div>Transferring an array</div> | |
<button id='bPopulate' onclick='populateArray()'>Populate Array</button> | |
<button id='bSend' onclick='sendArray()'>Send Array</button> | |
<div id='output'></div> |
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
#!/bin/bash | |
#================= | |
# commands: | |
# volume : get volume | |
# volume [0,100] : set volume, unmute | |
# volume [up|down] : step volume up or down by small pct, unmute | |
# volume mute : toggle mute | |
# volume muted : exit 0/print true if muted, else exit 0/print false | |
#================= |
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
""" | |
# First argument to the function should be the next | |
# object to invoke (next_handler below) | |
class EventHandler(object): | |
def __init__(self, name): | |
self.name = name | |
def handle(self, next_handler, event, data): | |
print("ENTER: Handler {} Event {}".format(self.name, event)) |
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
""" | |
Why is __call__ a special case? | |
https://docs.python.org/3.4/reference/datamodel.html#object.__getattribute__ | |
> Note: This method may still be bypassed when looking up special methods as the result of implicit invocation via language syntax or built-in functions. See Special method lookup. | |
> In addition to bypassing any instance attributes in the interest of correctness, implicit special method lookup generally also bypasses the __getattribute__() method even of the object’s metaclass | |
""" | |
class Chain(object): |
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 build_index(*fields): | |
'''each arg is (field_name, length) tuple''' | |
index = type('Index', (object,), {}) | |
start = 0 | |
for field, offset in fields: | |
s = slice(start, start + offset) | |
setattr(index, field, s) | |
start += offset | |
return index |
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
SUMMARY | |
============================= | |
bartell's gift card | |
toothpaste | |
thermos | |
soap dish | |
chapstick | |
tictacs | |
shower gel | |
shaving cream |
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
"[name] is [age:int] years old." -> "(?<name>[^ ]) is [(?<age>\d+) years old \." | |
---------------------------------------- | |
Examples | |
"search [service]/[region] [metric]" | |
"search (?<service>[^ ^/]+)/(?<region>[^ ]+) (?<metric>[^ ]+)" | |
"stock (?<name>[^ ]) (?<op>((<|>|=)=?)) (?<value>[^ ]+)" |
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
API Scaffolding | |
Plan: Create a stack for re-use when rapidly building out APIs featuring authentication, authorization, throttling, versioning, structures. API specification should be language agnostic so SDK creation is reasonable in non-python languages. | |
Server Stack: | |
-- custom API specification -- | |
API parser | |
marshmallow | |
-- application layer -- |
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
""" | |
Generate a mapping of a list of objects by the given attr. | |
""" | |
def index(objects, attr): | |
return {getattr(obj, attr): obj for obj in objects} | |
# Example | |
class Person(object): |
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
# Single hash key, multiple filters | |
# ================================= | |
# Pure condition syntax, no **kwargs overloading | |
# ---------------------------------------------- | |
q = engine.query(Forum) | |
.key(Forum.name == "S3") | |
.filter(Forum.subscribers > MIN_SUBSCRIBERS, | |
Forum.views >= MIN_VIEWS) |