def insert_all(max_records): people = [random_person() for n in range(max_records)] prnt('Records to create:', people) for person in people: # Don't need this prop for our example schema. del person['address'] db_session.add(Person(**person))
def insert_all(max_records): people = [random_person() for n in range(max_records)] prnt('Records to create:', people) for person in people: # Don't need this prop for our example schema. del person['address'] db_session.add(Person(**person))
print(f) print(neg * f) # Bind all once print_h2('Applicative functors, partial applications and compositions') bound1 = add2 * pm.List(*range(2)) & pm.List(*range(2)) # Bind all a second time bound2 = add_ten_to * pm.List(*range(2)) & bound1 ppr(bound2) ppr(num_and_ranges(10)) assert negafy(*range(10)) == neg * monoid_range(10) # Combining Functors * 4 names = pm.List(*[random_person()['name'] for _ in range(4)]) f1 = foofix * names f2 = foofix * f1 f3 = foofix * f2 f4 = foofix * f3 print(f1) print(f2) print(f3) print(f4) assert f4[0].startswith('FOO_FOO_FOO_FOO_') print_h2('Monads') f = monoid_range(4) >> monoid_range(4) ppr(neg * f) print(pm.Just(9) >> pm.Just(10))
def _random_person(): person = random_person() return {'name': person['name']}
# topics = ['foo', 'bar', 'quux', 'foo.bar', 'foo.bar.*'] topics = ['main-topic'] consumer = KafkaConsumer('main-topic', group_id='my_group', bootstrap_servers=['localhost:9092']) if DEBUG: # http://kafka-python.readthedocs.org/en/latest/usage.html to use kafka # See .sh scripts at: # http://kafka.apache.org/08/documentation.html#quickstart # instance and send/receive messages. with Section('Kafka - via kafka-py'): # PRODUCER - typically living somewhere else beside the consumer, # running in parallel. for topic in topics: for i in range(10): producer.send_messages(topic, '{}'.format(random_person())) # Also works with command line message sending: # Typing into the console after running the below command will cause the # arguments to be sent to the queue, and processed. # They will also be visible here when read by the consumer in python. # bin/kafka-console-producer.sh --broker-list \ # localhost:9092 --topic main-topic # CONSUMER for message in consumer: print("{}:{}:{}: key={} value={}".format( message.topic, message.partition, message.offset, message.key, message.value))
topics = ['main-topic'] consumer = KafkaConsumer('main-topic', group_id='my_group', bootstrap_servers=['localhost:9092']) if DEBUG: # http://kafka-python.readthedocs.org/en/latest/usage.html to use kafka # See .sh scripts at: # http://kafka.apache.org/08/documentation.html#quickstart # instance and send/receive messages. with Section('Kafka - via kafka-py'): # PRODUCER - typically living somewhere else beside the consumer, # running in parallel. for topic in topics: for i in range(10): producer.send_messages(topic, '{}'.format(random_person())) # Also works with command line message sending: # Typing into the console after running the below command will cause the # arguments to be sent to the queue, and processed. # They will also be visible here when read by the consumer in python. # bin/kafka-console-producer.sh --broker-list \ # localhost:9092 --topic main-topic # CONSUMER for message in consumer: print("{}:{}:{}: key={} value={}".format(message.topic, message.partition, message.offset, message.key, message.value))
print(f) print(neg * f) # Bind all once print_h2('Applicative functors, partial applications and compositions') bound1 = add2 * pm.List(*range(2)) & pm.List(*range(2)) # Bind all a second time bound2 = add_ten_to * pm.List(*range(2)) & bound1 ppr(bound2) ppr(num_and_ranges(10)) assert negafy(*range(10)) == neg * monoid_range(10) # Combining Functors * 4 names = pm.List(*[random_person()['name'] for _ in range(4)]) f1 = foofix * names f2 = foofix * f1 f3 = foofix * f2 f4 = foofix * f3 print(f1) print(f2) print(f3) print(f4) assert f4[0].startswith('FOO_FOO_FOO_FOO_') print_h2('Monads') f = monoid_range(4) >> monoid_range(4) ppr(neg * f) print(pm.Just(9) >> pm.Just(10))