Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Kishan Mehta kishan3

🎯
Focusing
View GitHub Profile
@kishan3
kishan3 / array_flatten.py
Last active Nov 6, 2018
Flatten input list of lists given by user and out put a flattened list.
View array_flatten.py
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
kishan3 / fibonacci.py
Created May 30, 2017
Find sum of n fibonacci numbers various methods.
View fibonacci.py
class Fibonacci(object):
"""docstring for Fibonacci"""
fib_cache = {}
def fib_memoization(self, n):
if n in fib_cache:
return fib_cache[n]
else:
if n < 2:
fib_cache[n] = n
else:
@kishan3
kishan3 / stacks.py
Created May 30, 2017
Optimized stack implementation which give minimum element from stack in O(1) time.
View stacks.py
class Stack(object):
"""docstring for Stack"""
def __init__(self):
self.stack = []
self.min_stack = []
def push(self, x):
if self.isEmpty():
self.stack.append(x)
self.min_stack.append(x)
@kishan3
kishan3 / rabbitmq_aws_setup.md
Created Mar 20, 2017
Set up rabbitmq on aws instances.
View rabbitmq_aws_setup.md

SSH to aws instance.

Install rabbitmq-server:

echo "deb http://www.rabbitmq.com/debian/ testing main"  | sudo tee  /etc/apt/sources.list.d/rabbitmq.list > /dev/null

wget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc

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
[program:myworker]
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