Skip to content

Instantly share code, notes, and snippets.

View pavan538's full-sized avatar

Pavan Kumar pavan538

View GitHub Profile
@pavan538
pavan538 / python_json_encoders.py
Last active April 3, 2019 10:19 — forked from simonw/gist:7000493
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (
@pavan538
pavan538 / css-media-queries-cheat-sheet.css
Created February 19, 2019 06:30 — forked from bartholomej/css-media-queries-cheat-sheet.css
CSS Media Query Cheat Sheet (with Foundation)
/*------------------------------------------
Responsive Grid Media Queries - 1280, 1024, 768, 480
1280-1024 - desktop (default grid)
1024-768 - tablet landscape
768-480 - tablet
480-less - phone landscape & smaller
--------------------------------------------*/
@media all and (min-width: 1024px) and (max-width: 1280px) { }
@media all and (min-width: 768px) and (max-width: 1024px) { }
@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'@'%';

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 / 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 '{
@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 / 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 / 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 / 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
- 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')