Skip to content

Instantly share code, notes, and snippets.

View Poorvak's full-sized avatar

Poorvak Kapoor Poorvak

  • Euler Motors
  • Delhi
View GitHub Profile
@Poorvak
Poorvak / lis.py
Created January 8, 2019 02:36
Find the Longest Increasing Subsequence from an array
def populate_incr_subseq_list(arr: list) -> list:
len_of_inp = len(arr)
temp_list = [1] * len_of_inp
for i in range(1, len_of_inp):
for j in range(0, i):
if arr[j] < arr[i]:
temp_list[i] = max(temp_list[1], temp_list[j] + 1)
return temp_list
@Poorvak
Poorvak / reverse_words.py
Created January 7, 2019 04:47
Reverse words in a given string
' '.join(input().split(' ')[::-1])
@Poorvak
Poorvak / check_height_balanced.py
Created January 7, 2019 04:32
How to determine if a binary tree is height-balanced?
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def get_height(root: Node) -> int:
if root is None:
return 0
@Poorvak
Poorvak / migrate-redis.py
Created March 9, 2018 07:29 — forked from thomasst/migrate-redis.py
Migrate Redis data on Amazon ElastiCache
"""
Copies all keys from the source Redis host to the destination Redis host.
Useful to migrate Redis instances where commands like SLAVEOF and MIGRATE are
restricted (e.g. on Amazon ElastiCache).
The script scans through the keyspace of the given database number and uses
a pipeline of DUMP and RESTORE commands to migrate the keys.
Requires Redis 2.8.0 or higher.
@Poorvak
Poorvak / sysctl.conf
Created February 19, 2018 09:49 — forked from kgriffs/sysctl.conf
Linux Web Server Kernel Tuning
# Configuration file for runtime kernel parameters.
# See sysctl.conf(5) for more information.
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for
# an explanation about some of these parameters, and instructions for
# a few other tweaks outside this file.
# Protection from SYN flood attack.
net.ipv4.tcp_syncookies = 1
@Poorvak
Poorvak / mongodb-s3-backup.sh
Created February 16, 2018 07:04 — forked from eladnava/mongodb-s3-backup.sh
Automatically backup a MongoDB database to S3 using mongodump, tar, and awscli (Ubuntu 14.04 LTS)
#!/bin/sh
# Make sure to:
# 1) Name this file `backup.sh` and place it in /home/ubuntu
# 2) Run sudo apt-get install awscli to install the AWSCLI
# 3) Run aws configure (enter s3-authorized IAM user and specify region)
# 4) Fill in DB host + name
# 5) Create S3 bucket for the backups and fill it in below (set a lifecycle rule to expire files older than X days in the bucket)
# 6) Run chmod +x backup.sh
# 7) Test it out via ./backup.sh
@Poorvak
Poorvak / postgres-to-es.py
Created July 20, 2017 09:22
Index data from Postgres to ElasticSearch using the arguments.
#!/usr/bin/python
import math
import argparse
import traceback
import psycopg2
import psycopg2.extras
import elasticsearch
@Poorvak
Poorvak / prime_numbers.cpp
Created June 27, 2017 04:29
Prime Number program in (N*log(pow 1/2)N) complexity
#include <iostream>
#include <vector>
using namespace std;
void generatePrime(int N) {
vector <int> arrayList;
vector <int> :: iterator i;
arrayList.push_back(2);
for( int i=3; i<=N; i+=2 ) {
bool isPrime = true;
@Poorvak
Poorvak / ner-tags.ipynb
Created June 8, 2017 07:26
NER Term Frquency
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Poorvak
Poorvak / dataset.ipynb
Created May 30, 2017 09:41
Jupyter notebook for dataset cleaning task
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.