Skip to content

Instantly share code, notes, and snippets.

View ramannanda9's full-sized avatar

Ramandeep Singh ramannanda9

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / TypefaceUtil.java
Last active August 29, 2015 14:07
Override fonts application wide in android.
package com.blogspot.ramannanda.apps.simplyread.utils;
import android.content.Context;
import android.graphics.Typeface;
import android.renderscript.Font;
import android.util.Log;
import java.lang.reflect.Field;
public class TypefaceUtil {
@ramannanda9
ramannanda9 / LDAPOperations.java
Created September 22, 2014 18:31
This utility class can be used to integrate with IAM Fortress SDK
package com.blogspot.ramannanda.security.fortress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import oracle.adf.share.logging.ADFLogger;
@ramannanda9
ramannanda9 / CustomBindingDefHolder
Created July 7, 2014 07:29
Holds attribute and binding definitions
package com.blogspot.ramannanda.demos.validationapp.view.backing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.el.ELContext;
import javax.faces.context.FacesContext;