def index(): """Hook index.""" if request.method == 'GET': return 'hello, I am app2 - please send me a webhook.' else: return json.dumps( dict(message='App 2 - Message received, sending hook data', status=200, data=random_binary(12)))
def index(): """Hook index.""" if request.method == 'GET': return 'hello, I am app1 - please send me a webhook.' else: return json.dumps(dict( message='App 1 - Message received, sending hook data', status=200, data=random_binary(12)))
return ''.join(binary) def twos_complement(binary): """Conversion algorithm from cs.cornell.edu/~tomf/notes/cps104/twoscomp.html#twotwo""" old = binary binary = ones_complement(binary) ones = binary binary = BaseDataType.increment(''.join(binary)) if DEBUG: print('Complements: one: {}, two: {}, (original: {})'.format( ''.join(ones), binary, ''.join(old))) dec = bin_to_dec(binary) sign, res = ('neg', -dec) if list(binary)[0] == '1' else ( 'pos', dec, ) res_bin = dec_to_bin(res) if DEBUG: print('Final decimal is {}: {} ({})'.format(sign, res, res_bin)) return res_bin if __name__ == '__main__': with Section('Computer organization - one, two\'s complement'): evens = [n for n in range(2, 16) if n % 4 == 0] for _ in range(8): twos_complement(random_binary(choice(evens))) divider(atom='-')
"""A test script for POSTing data to various webhook services.""" # -*- coding: utf-8 -*- __author__ = """Chris Tabor ([email protected])""" DEBUG = True if __name__ == '__main__' else False if DEBUG: from os import getcwd from os import sys sys.path.append(getcwd()) import time from MOAL.helpers.display import Section from MOAL.helpers.text import random_binary import requests if DEBUG: with Section('Webhooks - tester'): while True: time.sleep(2) data = random_binary(64) print('Posting data to :5000 ...') r = requests.post('http://localhost:5000/hook', data=data) print(r.text, r.status_code) print('Posting data to :5001 ...') r = requests.post('http://localhost:5001/hook', data=data) print(r.text, r.status_code)
# -*- coding: utf-8 -*- __author__ = """Chris Tabor ([email protected])""" DEBUG = True if __name__ == '__main__' else False if DEBUG: from os import getcwd from os import sys sys.path.append(getcwd()) import time from MOAL.helpers.display import Section from MOAL.helpers.text import random_binary import requests if DEBUG: with Section('Webhooks - tester'): while True: time.sleep(2) data = random_binary(64) print('Posting data to :5000 ...') r = requests.post('http://localhost:5000/hook', data=data) print(r.text, r.status_code) print('Posting data to :5001 ...') r = requests.post('http://localhost:5001/hook', data=data) print(r.text, r.status_code)
binary = list(binary) for k, digit in enumerate(binary): binary[k] = '1' if digit == '0' else '0' return ''.join(binary) def twos_complement(binary): """Conversion algorithm from cs.cornell.edu/~tomf/notes/cps104/twoscomp.html#twotwo""" old = binary binary = ones_complement(binary) ones = binary binary = BaseDataType.increment(''.join(binary)) if DEBUG: print('Complements: one: {}, two: {}, (original: {})'.format( ''.join(ones), binary, ''.join(old))) dec = bin_to_dec(binary) sign, res = ('neg', -dec) if list(binary)[0] == '1' else ('pos', dec,) res_bin = dec_to_bin(res) if DEBUG: print('Final decimal is {}: {} ({})'.format(sign, res, res_bin)) return res_bin if __name__ == '__main__': with Section('Computer organization - one, two\'s complement'): evens = [n for n in range(2, 16) if n % 4 == 0] for _ in range(8): twos_complement(random_binary(choice(evens))) divider(atom='-')
def _handle(data): """Quick handler to help with nested tuple comprehensions -- arguments are not easily passed using `map`, so this deals with passing them as *args, since the map function won't do it automatically.""" return prnt(*data) if DEBUG: with Section('Python comprehensions'): prnt( 'Dictionary comprehension', { 'data': { 'human_to_robot': {dm.random_dna(): txt.random_binary(4) for _ in range(4)}, 'robot_to_human': {txt.random_binary(4): dm.random_dna() for _ in range(4)} } }) prnt('List comprehension', [x**2 for x in range(10) if x % 2 == 0]) prnt('List comprehension - nested', [[x**y for x in range(1, 4) if x % 2 == 0] for y in range(1, 8)]) wtf = [[_nested(min=x), _nested(max=y)] for x, y in enumerate(range(1, 10))] print_h2('List comprehensions - triple nested') ppr(wtf)