Skip to content

Instantly share code, notes, and snippets.

View vijaysharmay's full-sized avatar
💭
I may be slow to respond.

Vijay Yellepeddi vijaysharmay

💭
I may be slow to respond.
View GitHub Profile
@vijaysharmay
vijaysharmay / bobp-python.md
Created November 9, 2015 09:17 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@vijaysharmay
vijaysharmay / rateLimitDecorator.py
Created September 25, 2015 07:16 — forked from gregburek/rateLimitDecorator.py
Rate limiting function calls with Python Decorators
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0:
@vijaysharmay
vijaysharmay / batching an iterable
Created September 24, 2015 05:30
Batching an Iterable
import time
from itertools import islice
def batch(batch_size,batch_frequency):
def wrapper(func):
def batch_sizing(iterable):
for i in range(0,len(iterable),batch_size):
new = func(islice(iterable,i,i+batch_size))
time.sleep(batch_frequency)
return new
@vijaysharmay
vijaysharmay / gist:e736b8b70e85359d54fb
Last active August 29, 2015 14:27
Vim Configuration
" enable syntax highlighting
syntax enable
" Color Scheme
set t_Co=256
colorscheme monokai
" show line numbers
set number
@vijaysharmay
vijaysharmay / gist:57710a5f7ef9e411912f
Last active August 29, 2015 14:17
Assumes the host details are stored in userdetails.json
from fabric.api import *
import os,json
from os.path import expanduser
env.forward_agent = True
USER_DETAILS = os.path.join(expanduser('~'),'userdetails.json')
def commit(message):
local('git add .')
local('git commit -m "' + message + '"')
@vijaysharmay
vijaysharmay / gist:520c3c4187ce4fb08d68
Created March 10, 2015 19:02
Python Interview Question #1
# Given a two dictionaries empdesig and empdet containing details about employees and managers in a key value pair - print a hierarchical tree
# empdesig = {'Simha': 'Khan', 'Khan': '', 'Vijay': 'Simha', 'Sai': 'Khan', 'Kiran': 'Kiran'}
# empdet = {'Simha': 'Khan', 'Khan': '', 'Vijay': 'Simha', 'Sai': 'Khan', 'Kiran': 'Kiran'}
# If an employee has manager null(like Khan) or has manager as himself - then they are board members and have no bosses.
for emp,mgr in empdesig.items():
new[emp] = {key:'' for key,value in empdesig.items() if value == emp}
for k,v in new.items():
@vijaysharmay
vijaysharmay / gist:6fd8d1c40ea2dab469a9
Created November 28, 2014 08:43
Create SSH Key for Azure
# Create a new pair
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem
chmod 600 myPrivateKey.key
# Create from existing pair
openssl req -x509 -key ~/.ssh/id_rsa -nodes -days 365 -newkey rsa:2048 -out myCert.pem
@vijaysharmay
vijaysharmay / gist:8e8e67052e288783457f
Created September 9, 2014 04:44
postgres list of tables and dbs
This lists databases:
SELECT datname FROM pg_database
WHERE datistemplate = false;
This lists tables in the current database
SELECT table_schema,table_name
FROM information_schema.tables
ORDER BY table_schema,table_name;
"""Splay tree
Logan Ingalls <log@plutor.org>
Sept 3, 2012
Note that I only implemented insert and find. Delete is trivial,
and isn't the interesting part of splay trees. Some of these
algorithms would be simpler, but I chose to do this without parent
links from the tree nodes.
Example output on my desktop computer:
@vijaysharmay
vijaysharmay / simple.conf
Created July 22, 2014 18:08
Sample Supervisor Conf
[program:hippe]
directory = /home/vijay/Desktop/hippo/hippolite/
user = vijay
command = /home/vijay/Desktop/hippo/hippolite/deploy.sh