import asyncio
import threading
def worker():
second_loop = asyncio.new_event_loop()
execute_polling_coroutines_forever(second_loop)
return
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
from __future__ import division | |
import string | |
import math | |
tokenize = lambda doc: doc.lower().split(" ") | |
document_0 = "China has a strong economy that is growing at a rapid pace. However politically it differs greatly from the US Economy." | |
document_1 = "At last, China seems serious about confronting an endemic problem: domestic violence and corruption." | |
document_2 = "Japan's prime minister, Shinzo Abe, is working towards healing the economic turmoil in his own country for his view on the future of his people." | |
document_3 = "Vladimir Putin is working hard to fix the economy in Russia as the Ruble has tumbled." |
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
from functools import reduce | |
def is_balanced_partition(arr): | |
total = reduce(lambda x, y: x+y , arr) | |
if total % 2 != 0: | |
return False |
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 below code will get both responses in parallel. | |
import asyncio | |
import requests | |
@asyncio.coroutine | |
def main(): | |
loop = asyncio.get_event_loop() | |
future1 = loop.run_in_executor(None, requests.get, 'http://www.google.com') | |
future2 = loop.run_in_executor(None, requests.get, 'http://www.google.co.uk') |
Cascading Types
- Persist: save or persist operations cascade to related entities
- Merge: means that related entities are merged, when the owner entity is merged
- Refresh: does the same thing for refresh() operation
- Remove: removes all the entities association with this setting, when the owining entity is deleted.
- Detach: detach all related entities, if a manual detach occurs.
- All: shorthand of all related entities.
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
data = o.to_mongo() | |
o_id = data.pop('_id', None) | |
if o_id: | |
data['id'] = str(o_id) | |
data.pop('_cls', None) | |
return data |
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
curl -XPOST http://localhost:9200/test/articles/1 -d '{ | |
"content": "The quick brown fox" | |
}' | |
curl -XPOST http://localhost:9200/test/articles/2 -d '{ | |
"content": "What does the fox say?" | |
}' | |
curl -XPOST http://localhost:9200/test/articles/3 -d '{ | |
"content": "The quick brown fox jumped over the lazy dog" | |
}' | |
curl -XPOST http://localhost:9200/test/articles/4 -d '{ |
Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups
command.
- List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe
Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.
- Reset the consumer offset for a topic (preview)
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
## installation openldap with backend mysql | |
sudo apt update && sudo apt upgrade -y && sudo reboot | |
sudo apt install mysql-server unixodbc make gcc libmysqlclient-dev unixodbc-dev groff ldap-utils | |
## mysql login as root | |
sudo mysql -u root | |
CREATE DATABASE ldap | |
CREATE USER 'ldap'@'%' IDENTIFIED BY 'S3cureP4ssw0rd$'; | |
GRANT ALL PRIVILEGES ON ldap.* TO 'ldap'@'%'; |