Skip to content

Instantly share code, notes, and snippets.

View ramannanda9's full-sized avatar

Ramandeep Singh ramannanda9

View GitHub Profile
@ramannanda9
ramannanda9 / CMISQueryTest.java
Created February 26, 2015 14:26
CMIS Query with Apache Chemistry and alfresco
import org.apache.chemistry.opencmis.client.api.*;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
@ramannanda9
ramannanda9 / ShowCaseView.java
Last active August 29, 2015 14:18
ShowcaseView Memory leak Fix
/*
* Copyright 2014 Alex Curran
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ramannanda9
ramannanda9 / RateLimitedFetch.java
Created December 11, 2015 01:15
Rate Limiting requests
public static List<Movie> invokeRateLimitedFetch(List<SearchedMovie> searchedMovies,boolean saveFile, File file){
List<Movie> movies=new ArrayList<>();
Observable.zip(Observable.from(searchedMovies),
Observable.interval(2, TimeUnit.SECONDS), (obs,timer)->obs)
.doOnNext(item -> {
Movie movie = movieUtil.getMovieDetails(item.getId());
movies.add(movie);
if(saveFile) {
writeRecordToFile(file, movie);
@ramannanda9
ramannanda9 / word_count.pig
Created March 1, 2016 21:10
PIG script for searching words
input_records = LOAD 'hdfs://quickstart.cloudera:8020/user/cloudera/pig_word_count/input.txt' as(tweet_text:chararray);
filter_words = LOAD 'hdfs://quickstart.cloudera:8020/user/cloudera/pig_word_count/filter_words.txt' as (filter_word:chararray);
input_records = FOREACH input_records GENERATE REPLACE(tweet_text,'([^a-zA-Z\\s]+)',' ') as tweet_text;
tokenize_words = FOREACH input_records GENERATE flatten(TOKENIZE(LOWER(tweet_text))) as word;
--INEFFICIENT BUT NECCESSARY to print filtered_word
cleanedData = JOIN filter_words by LOWER((filter_word)) FULL, tokenize_words by LOWER(word);
--REMOVE NON MATCHIN WORDS EXCEPT THE ONE IN WHICH THE FILTER WORD IS NOT NULL
filtered_data = FILTER cleanedData by ((word IS NULL and filter_word IS NOT NULL ) or word matches LOWER(filter_word) ) ;
grouped_words = GROUP filtered_data by filter_word;
--GROUP THEM BY group key and only count when the word is not empty, Since null is not counted so it works
@ramannanda9
ramannanda9 / analytic.sql
Created July 20, 2016 01:17
analytic function
select empno, deptno, row_number() over (partition by deptno order by 1) sequence_num from scott.emp;
@ramannanda9
ramannanda9 / max_salary.sql
Created October 5, 2016 01:04
Max Salary by Department
select e.ename, e.sal, d.dname from emp e,dept d where e.sal in (select max(e.sal) from emp e group by deptno) and e.deptno=d.deptno
@ramannanda9
ramannanda9 / NWayMerge.scala
Last active June 18, 2017 02:26
Some Scala Transpose Experiments.
import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer
case class Priceable(id: String,measure:String,value: Double)
val results=Seq(
Priceable("$APPL","PV",311.0),
Priceable("$APPL","Growth",3.0),
Priceable("$IBM","PV",100),
Priceable("$IBM","Growth",0.5),
@ramannanda9
ramannanda9 / filter.scala
Last active July 31, 2017 19:51
filter in scala
def filter[K](arr: List[K], f: K => Boolean): List[K] = arr match {
case Nil => arr
case list: List[K] => if (f(list.head)) list.head :: filter(list.tail, f) else filter(list.tail, f)
}
val listToFilter = 2 :: 5 :: Nil
listToFilter.filter(_ > 2)
@ramannanda9
ramannanda9 / MaxSumInTree.java
Created July 31, 2017 19:58
Get maximum independent branch sum
public class MaxSumInTree{
int left(int i) {
return (2 * i + 1);
}
int right(int i) {
return (2 * i + 2);
}
long findMax(int n, String tree) {
@ramannanda9
ramannanda9 / TailRecursionFilter.scala
Created July 31, 2017 20:09
Filter with Tail Recursion
def filter[K](list: List[K], f: K => Boolean): List[K] = {
@tailrec
def filterRec(list: List[K], f: K => Boolean): List[K] = list match {
case Nil => list
case list: List[K] => if (f(list.head)) filterRec(list.head :: list.tail, f) else filterRec(list.tail, f)
}
filterRec(list, f)
}
val listToFilter = 2 :: 5 :: Nil