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 RequestLoggingMiddleware(MiddlewareMixin): | |
def process_response(self, request, response): | |
msg = '{} - {}'.format( | |
request.get_full_path(), | |
response.status_code) | |
if response.status_code > 299 and response.status_code < 400: | |
msg = '{} - {}'.format(msg, response.url) | |
print(msg) |
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
""" | |
Readings: | |
https://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html | |
https://github.com/boto/boto3/blob/develop/boto3/examples/s3.rst#list-top-level-common-prefixes-in-amazon-s3-bucket | |
To get only leaf directories instead of all: https://gist.github.com/wontonst/c8c06730d13e004de390e67f593be763 | |
""" | |
import boto3 |
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
""" | |
Readings: | |
https://docs.aws.amazon.com/AmazonS3/latest/dev/ListingKeysHierarchy.html | |
https://github.com/boto/boto3/blob/develop/boto3/examples/s3.rst#list-top-level-common-prefixes-in-amazon-s3-bucket | |
To get all subdirectories instead of only leaf: https://gist.github.com/wontonst/fd2b03dd4b5ac656cc264fe70a7d37bd | |
""" | |
import boto3 |
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
# http://code.activestate.com/recipes/577558-interleave-bits-aka-morton-ize-aka-z-order-curve/ | |
def part1by1(n): | |
n&= 0x0000ffff | |
n = (n | (n << 8)) & 0x00FF00FF | |
n = (n | (n << 4)) & 0x0F0F0F0F | |
n = (n | (n << 2)) & 0x33333333 | |
n = (n | (n << 1)) & 0x55555555 | |
return n |
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
# This is an exercise written by Roy Zheng based on the "Writing Idiomatic Python" book. | |
# Take a look at my blog post here [INSERT] for the full exercise. | |
class Tank: | |
def __init__(self, armor, penetration, armor_type): | |
self.armor = armor | |
self.penetration = penetration | |
self.armor_type = armor_type | |
if not (armor_type == 'chobham' or armor_type == 'composite' or armor_type == 'ceramic'): | |
raise Exception('Invalid armor type %s' % (armor_type)) |