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(): | |
queue = multiprocessing.Queue(-1) | |
listener = multiprocessing.Process( | |
target=listener_process, args=(queue,)) | |
listener.start() | |
# set up main logger after listener | |
worker_configurer(queue) | |
main_logger = logging.getLogger('main') | |
main_logger.info('Logging from main') |
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(): | |
queue = multiprocessing.Queue(-1) | |
# set up main logger following example from work_process | |
worker_configurer(queue) | |
main_logger = logging.getLogger('main') | |
listener = multiprocessing.Process( | |
target=listener_process, args=(queue,)) | |
listener.start() |
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 logging | |
import logging.handlers | |
import multiprocessing | |
from time import sleep | |
from random import random, randint | |
# Almost the same as the demo code, but added `console_handler` to directly | |
# read logging info from the console | |
def listener_configurer(): |
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
# comment out logger configuration for worker process | |
def worker_process(queue): | |
# worker_configurer(queue) | |
for i in range(3): | |
sleep(random()) | |
innerlogger = logging.getLogger('worker') | |
innerlogger.info(f'Logging a random number {randint(0, 10)}') |
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
# logger configuration uncommented in worker_process | |
def worker_process(queue): | |
worker_configurer(queue) | |
for i in range(3): | |
sleep(random()) | |
innerlogger = logging.getLogger('worker') | |
innerlogger.info(f'Logging a random number {randint(0, 10)}') | |
# logger configuration commented out in main |
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 logging | |
from logging import handlers | |
from time import sleep | |
def listener_configurer(): | |
root = logging.getLogger() | |
file_handler = handlers.RotatingFileHandler('mptest.log', 'a', 300, 10) | |
console_handler = logging.StreamHandler() | |
formatter = logging.Formatter('%(asctime)s %(processName)-10s %(name)s %(levelname)-8s %(message)s') |
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 requests | |
credential_provider_endpoint = 'https://<your_credentials_provider_endpoint>/role-aliases/iot-s3-access-role-alias/credentials' | |
device_cert_path = '<path_to_device_cert>' | |
device_private_key_path = '<path_to_device_private_key>' | |
resp = requests.get( | |
credential_provider_endpoint, | |
headers={'x-amzn-iot-thingname': 'TestThing'}, | |
cert=(device_cert_path, device_private_key_path), |
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 boto3 | |
import requests | |
def obtain_temporary_credentials() -> Tuple[str, str, str]: | |
"""Obtain temporary credentials from AWS IoT device certificate and private key.""" | |
credential_provider_endpoint = 'https://<your_credentials_provider_endpoint>/role-aliases/iot-s3-access-role-alias/credentials' | |
device_cert_path = '<path_to_device_cert>' | |
device_private_key_path = '<path_to_device_private_key>' |
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
""" | |
Original question: | |
You have three $20 dollar bills, five $10 dollar bills, two $5 dollar bills, and five $1 dollar bills. | |
How many ways can you make change for a $100 dollar bill? | |
""" | |
def find_ways(num_bills, pos_bills, money): | |
""" | |
DP solution. dp is an array of array of array. In the out-most array, index | |
represents money, and the content is an array of array, which represents |
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 React, {PureComponent} from 'react'; | |
import { | |
View, | |
Text, | |
TouchableHighlight, | |
TouchableOpacity, | |
} from 'react-native'; | |
class Demo extends PureComponent { | |
constructor(props) { |
OlderNewer