Skip to content

Instantly share code, notes, and snippets.

View pavan538's full-sized avatar

Pavan Kumar pavan538

View GitHub Profile
@pavan538
pavan538 / tfpdf.py
Created October 19, 2018 16:21 — forked from bllchmbrs/tfpdf.py
TF IDF Explained in Python Along with Scikit-Learn Implementation
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."
@pavan538
pavan538 / balanced_partition.py
Created November 9, 2018 03:31
Partitioning problem: Arbitrary list of integers of any length and in any order Determine if the list is partitionable or not. A partitioned list is one where it can be split into 2 lists with equal sum. Enumerate the list of cases to solve to minimize execution time and provide the Order of the algorithm Provide code showing the implementation …
from functools import reduce
def is_balanced_partition(arr):
total = reduce(lambda x, y: x+y , arr)
if total % 2 != 0:
return False
- 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')
@pavan538
pavan538 / asyncio.md
Last active November 26, 2018 15:14
python asyncio
import asyncio
import threading


def worker():
    second_loop = asyncio.new_event_loop()
    execute_polling_coroutines_forever(second_loop)
    return
@pavan538
pavan538 / hibernates.md
Last active November 28, 2018 06:53
All About Hibernates

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.
@pavan538
pavan538 / somegist.py
Created December 16, 2018 13:31 — forked from dhesson/somegist.py
Code fragment for a MongoEngine query result item to serializable JSON dictionary.
data = o.to_mongo()
o_id = data.pop('_id', None)
if o_id:
data['id'] = str(o_id)
data.pop('_cls', None)
return data
@pavan538
pavan538 / metatags.html
Created December 26, 2018 13:18 — forked from MicBrain/metatags.html
The list of useful meta tags used in HTML5 documents.
<html>
<head>
<!--Recommended Meta Tags-->
<meta charset="utf-8">
<meta name="language" content="english">
<meta http-equiv="content-type" content="text/html">
<meta name="author" content=”Rafayel Mkrtchyan”>
<meta name="designer" content=”Rafayel Mkrtchyan”>
<meta name="publisher" content=”Rafayel Mkrtchyan”>
@pavan538
pavan538 / create_index.sh
Created January 9, 2019 13:20 — forked from bonzanini/create_index.sh
Elasticsearch/Python test
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.

  1. 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.

  1. Reset the consumer offset for a topic (preview)
@pavan538
pavan538 / ubuntu-bionic-openldap-mysql.sh
Created February 4, 2019 12:20 — forked from mahirrudin/ubuntu-bionic-openldap-mysql.sh
OpenLDAP with MySQL Backend - Ubuntu 18.04
## 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'@'%';