Skip to content

Instantly share code, notes, and snippets.

@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 / gist:2b39fdd74dfde98d6b11
Created August 21, 2014 21:08
ardendertat collection
Source: http://www.ardendertat.com/2012/01/09/programming-interview-questions/
The complete list of all my programming interview question articles with pointers to original posts. There are 28 questions in total, and since 28 is a perfect number (as Donald Knuth also mentioned) I decided that’s a good place to stop.
1. Array Pair Sum
Given an integer array, output all pairs that sum up to a specific value k.
2. Matrix Region Sum
Given a matrix of integers and coordinates of a rectangular region within the matrix, find the sum of numbers falling inside the rectangle. Our program will be called multiple times with different rectangular regions from the same matrix.
@gabhi
gabhi / gist:5a0b6f53fd7a1b7550c1
Created June 20, 2014 01:21
Find if given pattern is present in given matrix java
package cccc;
public class PatternInMatrix {
static boolean used[][];
public static boolean findPattern(char[][] matrix, int nRow, int nCol, char[] pattern) {
used = new boolean[nRow][nCol];
for (int i = 0; i < nRow; i++)
for (int j = 0; j < nCol; j++) {
@gabhi
gabhi / gist:11484e4a08f46fe3bbb7
Created March 27, 2015 07:26
Algorithm for Determining Tic Tac Toe Game Over/winner
public class TripleT {
enum State{Blank, X, O};
int n = 3;
State[][] board = new State[n][n];
int moveCount;
void Move(int x, int y, State s){
if(board[x][y] == State.Blank){
@gabhi
gabhi / gist:9959221
Created April 3, 2014 17:47
Sample test case to test POST method for express js REST API
//Following test case assumes you have express js server running at port 5000 and has api /api/login
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var winston = require('winston');
describe('Routing', function() {
var url = 'http://localhost:5000';
@gabhi
gabhi / gist:11243437
Created April 24, 2014 06:16
Levenshtein Edit Distance Algorithm in Java
public static int distance(String s1, String s2){
int edits[][]=new int[s1.length()+1][s2.length()+1];
for(int i=0;i<=s1.length();i++)
edits[i][0]=i;
for(int j=1;j<=s2.length();j++)
edits[0][j]=j;
for(int i=1;i<=s1.length();i++){
for(int j=1;j<=s2.length();j++){
int u=(s1.charAt(i-1)==s2.charAt(j-1)?0:1);
edits[i][j]=Math.min(
@gabhi
gabhi / gist:a750694548cf29297ce5
Created September 18, 2014 01:00
LongestCompoundWord
public class LongtCompoundWord {
public static void main(String[] args) {
String words[] = { "cat", "cats", "catsdogcats", "catxdogcatsrat", "dog", "dogcatsdog", "hippopotamuses",
"rat", "ratcat", "ratcatdog", "ratcatdogcat" };
// ratcatdogcat
System.out.println("Longest Compound word : " + longestCompundWord(words));
}
private static String longestCompundWord(String[] words) {
@gabhi
gabhi / gist:3be6e3d1ba49e78bcf81b349a78c34e8
Created December 29, 2020 19:24 — forked from rkuzsma/gist:b9a0e342c56479f5e58d654b1341f01e
Example Kubernetes yaml to pull a private DockerHub image
Step by step how to pull a private DockerHub hosted image in a Kubernetes YML.
export DOCKER_REGISTRY_SERVER=https://index.docker.io/v1/
export DOCKER_USER=Type your dockerhub username, same as when you `docker login`
export DOCKER_EMAIL=Type your dockerhub email, same as when you `docker login`
export DOCKER_PASSWORD=Type your dockerhub pw, same as when you `docker login`
kubectl create secret docker-registry myregistrykey \
--docker-server=$DOCKER_REGISTRY_SERVER \
--docker-username=$DOCKER_USER \
@gabhi
gabhi / gist:10442618
Created April 11, 2014 05:41
linked list implementation
public class LinkedList {
private ListNode firstNode;
private ListNode lastNode;
private int size;
/**
* For the no-args constructor, the data and next will be null (empty list)
*/
public LinkedList() {
@gabhi
gabhi / bogglesolver.java
Last active October 19, 2020 00:53
boggle solver java
package com.interview.graph;
import java.util.HashSet;
import java.util.Set;
/**
* http://www.careercup.com/question?id=14942063
*/
public class Boggle {