Skip to content

Instantly share code, notes, and snippets.

View SureshKL's full-sized avatar

Suresh K L SureshKL

  • Sony India Software Centre Private Limited
  • Bangalore
View GitHub Profile
@SureshKL
SureshKL / demo.gv
Last active March 22, 2019 10:31
Dot Template
# PDF Generate Cmd: dot -Tpdf demo.gv > demo.pdf
# Dot Guide: https://www.graphviz.org/pdf/dotguide.pdf
# Examples:
# https://renenyffenegger.ch/notes/tools/Graphviz/examples/index
#
digraph G {
label = "The Title";
labelloc = "top"; // place the label at the top (b seems to be default)
@SureshKL
SureshKL / git_commands_toc_generator.py
Created March 19, 2019 16:37
[Utility] Git commands TOC Generator
import re
readme_path = r'Useful Git Commands.md'
skip_rules = ('# Useful Git commands',
'# Table of Contents:',
)
def generate_toc(headers):
# Syntax: [git init](#git-init)
@SureshKL
SureshKL / git_commands.md
Last active March 19, 2019 16:35
Useful Git Commands
@SureshKL
SureshKL / concurrent_download.py
Created January 23, 2019 11:55
Python - Single vs Multithreaded download using threading and gevent
import logging
import threading
import gevent
import gevent.monkey
import requests
gevent.monkey.patch_socket()
logging.basicConfig(
@SureshKL
SureshKL / gevent_asynchronous_demo.py
Last active January 23, 2019 11:57
Python: gevent - synchronous/asynchronous execution
import logging
import time
import gevent
logging.basicConfig(
format='%(asctime)s - %(levelname)10s - [%(threadName)s-%(thread)d] - [%(processName)s-%(process)s]- %(message)s',
level=logging.DEBUG)
logger = logging.getLogger(__name__)
@SureshKL
SureshKL / getter.py
Created December 18, 2018 03:48
Attribute Lookup
import sys
class CommonAttributes:
def __init__(self):
self.name = 'common'
class MissingAttributes:
def __init__(self):
@SureshKL
SureshKL / bottle_demo.py
Last active December 28, 2018 09:41
Bottle: Login/Logout/File Upload/Download Demo
"""Bottle framework demonstration
Below items are demonstrated here:
==================================
- Login/Logout using cookies
- File upload/download
- Hooks
- Plugins
- 404 error handling
- Jinja2 template usage
@SureshKL
SureshKL / method_overriding.py
Created December 11, 2018 12:09
Demonstrating method overriding by custom list concatenation
class ListAddition:
def __init__(self, numbers):
self.x = numbers
def __add__(self, other):
return [self.x, other.x]
x = ListAddition([1, 2, 3])
@SureshKL
SureshKL / get_lines.py
Created December 11, 2018 12:04
Get specified no. of lines from file
def get_lines_in_chunks(file_path: str, chunks: int = 1) -> list:
"""Get specified no. of lines from file
:param chunks: No. of lines (Default=1)
:param file_path: Absolute path to file
:return: list of lines from the file
"""
with open(file_path) as f:
def _get_lines(chunks):
return [f.readline() for _ in range(chunks)]
@SureshKL
SureshKL / python_topics.md
Last active December 7, 2018 02:23
Python Topics Quick Reference

Python Important Topics

Fundamentals

  • list
  • tuple
  • dict
  • set
  • frozen set
  • Builtin functions: map, filter, reduce, vars, zip, enumerate
  • lambda