--- | --- | --- | --- |
---|---|---|---|
Array | Backtracking | BFS | Binary |
Binary Search | Binary Search Tree | Dynamic Programming | Graph |
Math | Memoization | Stack & Queue | String |
Binary Tree | DFS | Union Find | [Divide & Conquer](https://leetcode.com/list?selectedList=96zejf |
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 quantity(storage_name): | |
def getter(instance): | |
return instance.__dict__[storage_name] | |
def setter(instance, value): | |
if value > 0: | |
instance.__dict__[stoage_name] = value | |
raise ValueError() | |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 CartItem: | |
def __init__(self, weight): | |
self.weight = weight | |
def get_weight(self): | |
return self.__weight | |
def set_weight(self, val): | |
if val > 0: | |
self.__weight = val |
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 Record: | |
def __init__(self, **kwargs): | |
self.__dict__.update(kwargs) | |
def __eq__(self, other): | |
if isinstance(other, Record): | |
return self.__dict__ = other.__dict__ | |
return NotImplement | |
class DatabaseMissingError(RuntimeError): |
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 FrozenJSON: | |
"""A read-only facade for nevigating a JSON-like object""" | |
def __init__(self, mapping): | |
self.__data = dict(mapping) | |
def __getattr__(self, name): | |
if hasattr(self.__data, name): | |
return getattr(self.__data, name) | |
else: |
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
@asyncio.coroutine | |
def init(loop, address, port): | |
"""Yield a server for event loop to drive""" | |
app = aiohttp.web.Application(loop=loop) | |
# you should consider make `home` a corutine to prevent blocking | |
app.router.add_route('GET', '/', home) | |
handler = app.make_handler() | |
# create_server brings up the server, using handler as the protocol handler and binding it to address and port | |
server = yield from loop.create_server(handler, address, port) | |
retrun server.sockets[0].getsockname() |
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 main(addr='127.0.0.1', port=2323): | |
port = int(port) | |
loop = asyncio.get_event_loop() | |
server_coro = asyncio.start_server(handle_quries, address, port, loop=loop) | |
# Drive server_coro to bring up the server | |
server = loop.run_until_complete(server_coro) | |
host = server.sockets[0].getsockname() | |
print(f'Serving on {host}. Hit CTRL-C to stop.') | |
try: |
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 sys | |
import asyncio | |
@asyncio.coroutine | |
def spin(): | |
write, flush = sys.stdout.write, sys.stdout.flush | |
for char in itertools.cycle('|/-\\'): | |
msg = char + ' loading ...' | |
write(msg) | |
flush() |
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 sys | |
import threading | |
class Signal: | |
stop = False | |
def spin(signal): | |
write, flush = sys.stdout.write, sys.stdout.flush # create alias | |
for char in itertools.cycle('|/-\\'): | |
msg = char + ' loading ...' |