Skip to content

Instantly share code, notes, and snippets.


Kishan Mehta kishan3

View GitHub Profile
kishan3 /
Last active Nov 6, 2018
Flatten input list of lists given by user and out put a flattened list.
import ast
import sys
import unittest
def flatten(items):
"""Generator for thwoing our items from list of lists."""
for x in items:
if isinstance(x, list):
for sub_x in flatten(x):
View Remove local branches not tracked on remote
git checkout master && git pull origin master && git fetch -p && git branch -d $(git branch --merged | grep master -v)
kishan3 /
Created May 30, 2017
Find sum of n fibonacci numbers various methods.
class Fibonacci(object):
"""docstring for Fibonacci"""
fib_cache = {}
def fib_memoization(self, n):
if n in fib_cache:
return fib_cache[n]
if n < 2:
fib_cache[n] = n
kishan3 /
Created May 30, 2017
Optimized stack implementation which give minimum element from stack in O(1) time.
class Stack(object):
"""docstring for Stack"""
def __init__(self):
self.stack = []
self.min_stack = []
def push(self, x):
if self.isEmpty():
kishan3 /
Created Mar 20, 2017
Set up rabbitmq on aws instances.

SSH to aws instance.

Install rabbitmq-server:

echo "deb testing main"  | sudo tee  /etc/apt/sources.list.d/rabbitmq.list > /dev/null


sudo apt-key add rabbitmq-signing-key-public.asc
View Python:- Merge Two Arrays in Decending order
# n = size of array1
# m = size of array2
def merge(array1, array2, n , m):
x = 0
y = 0
result = []
k = 0
while (x < n) and (y < m):
if array1[x] > array2[y]:
View Put Django RQ under supervisor.
1. Assuming you have already installed supervisor.
If not simply do:
sudo pip install supervisor
2. create a file under path : /etc/supervisor/conf.d/<filename.conf>/
- sudo touch /etc/supervisor/conf.d/<filename.conf>/
- content
command= /path/to/your/virtualenv/bin/rqworker
stdout_logfile = /var/log/redis_log/redis.log
View install redis and configure.txt
sudo apt-get install redis-server
# Configure redis to use sockets
sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig
# Disable Redis listening on TCP by setting 'port' to 0
sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf
# Enable Redis socket for default Debian / Ubuntu path
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf