Skip to content

Instantly share code, notes, and snippets.

View anupsavvy's full-sized avatar

Anup anupsavvy

  • Northwestern University
  • Chicago
View GitHub Profile
@anupsavvy
anupsavvy / DataSource.java
Last active December 14, 2015 00:19
Singleton Class
public class DataSource {
private Connection connection = null;
private static DataSource datasource = null;
// private constructor
private DataSource(){
connection = getConnection();
}
// method to get an instance.
@anupsavvy
anupsavvy / Search.java
Created February 20, 2013 19:42
Given a sorted array of integers array and an integer key, return the index of the first instance of key in the array. If key is not present in array, you should return -1. For example, given the array [-10, -2, 1, 5, 5, 8, 20] and key 5, you should return the index 3. Your solution should be a binary search, that is, it should run in O(log n) t…
public class Search{
private int binarySearch(int arr[], int key){
if(arr == null)
throw new RuntimeException("Null array found");
int l = 0; // lower limit
int h = arr.length - 1; // upper limit
int m;
@anupsavvy
anupsavvy / gist:6983050
Created October 14, 2013 22:08
1) Find the maximum sum possible from picking a contiguous subsequence of an array. [-1, 5, 6, -2, 20, -50, 4] What is the largest sum of contiguous elements available in this list?
public int largestSum(int[] A){
if(A.length == 0) return 0;
if(A.length == 1) return A[0];
int max = Integer.MIN_VALUE;
int curr = 0;
for(int i = 0; i < A.length; i++){
@anupsavvy
anupsavvy / 19.json
Last active August 29, 2015 13:57
Stacked bar-charts on time scale.
[
[
{
"time": "0",
"y": 0
},
{
"time": "1",
"y": 0
},
@anupsavvy
anupsavvy / sdword2vec.py
Created October 9, 2015 16:39
Load science direct articles and create doc2vec vectors for each one of them.
#coding:utf-8
# Author: Anup Sawant
# Purpose: Doc2vec vectors of Science Direct Articles
# Created: 9/21/2015
import sys
import os
import pandas as pd
from pandas import Series, DataFrame