Skip to content

Instantly share code, notes, and snippets.

@gabhi
gabhi / sql.md
Last active April 9, 2016 21:50
SQL

####top nth salary

SELECT * FROM one as A WHERE ( n ) = ( SELECT COUNT(DISTINCT(b.salary)) FROM one as B WHERE B.salary >= A.salary )

SELECT DISTINCT(a.salary) FROM employee a WHERE 2 = (SELECT COUNT( DISTINCT(b.salary) )FROM employee b WHERE a.salary <= b.salary ) ;

2nd highest salary

@gabhi
gabhi / YahooDataGrabber.py
Created March 31, 2016 05:20
Simple scripts to bulk download historical data from Yahoo! Finance
#!/usr/bin/env python
import csv
import Queue
import threading
import ystockquote as ys
def gen_info_list(tickers, start, end):
'''
@gabhi
gabhi / search pid and kill process script
Created March 20, 2016 22:15
search pid and kill process script
ps -ef | grep cassandra | grep -v grep | awk '{print $2}' | xargs kill -9
@gabhi
gabhi / thankyou.py
Created March 16, 2016 04:58 — forked from naiquevin/thankyou.py
Python script to thank people who sent birthday wishes on facebook
import sys
from urllib import urlencode
import requests
from urlparse import urlparse, parse_qs
from random import choice
import re
self_id = None # your facebook id here
utc_bday = None # utc timestamp of your birthday
@gabhi
gabhi / SingleSellProfit.python
Created March 9, 2016 23:29
SingleSellProfit.python
# Let min = arr[0]
# For k = 1 to length(arr):
# If arr[k] < min, set min = arr[k]
# If profit < arr[k] - min, set profit = arr[k] - min
#
# This is short, sweet, and uses only O(n) time and O(1) memory. The beauty of
# this solution is that we are quite naturally led there by thinking about how
# to update our answer to the problem in response to seeing some new element.
# In fact, we could consider implementing this algorithm as a streaming
# algorithm, where at each point in time we maintain the maximum possible
@gabhi
gabhi / GrepProcessIdProcessFromJava.java
Created February 27, 2016 05:57
Grep ProcessId for Process From Java
import org.zeroturnaround.exec.ProcessExecutor;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
* Created by agaikwad on 2/26/16.
*/
public class GrepProcessIdProcessFromJava {
@gabhi
gabhi / save_tweets_to_mongo_db_fromstreaming_twitter_api.py
Created February 22, 2016 07:23
python script to save tweets from streaming search api to mongodb
import json
import pymongo
import tweepy
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
@gabhi
gabhi / pascal.java
Created February 21, 2016 17:51
Generating Pascal's triangle using recursion
import java.util.Scanner;
public class PascalTriangle {
public static void print(int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(pascal(i, j) + " ");
}
System.out.println();
@gabhi
gabhi / clean_docker.sh
Created September 2, 2015 22:58
clean docker all images
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)