Skip to content

Instantly share code, notes, and snippets.

@kishan3
kishan3 / array_flatten.py
Last active November 6, 2018 13:22
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):
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 10:26
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]
else:
if n < 2:
fib_cache[n] = n
else:
@kishan3
kishan3 / stacks.py
Created May 30, 2017 08:00
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():
self.stack.append(x)
self.min_stack.append(x)
@kishan3
kishan3 / rabbitmq_aws_setup.md
Created March 20, 2017 13:19
Set up rabbitmq on aws instances.

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
# 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]:
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
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