Skip to content

Instantly share code, notes, and snippets.

View dapurv5's full-sized avatar
:atom:

Apurv Verma dapurv5

:atom:
View GitHub Profile
@dapurv5
dapurv5 / Arrays2D.java
Created January 3, 2013 21:55
Arrays2D
/**
* Searches a 2D array sorted by row and col in logarithmic time.
*/
public static boolean contains(int[][] A, int elem){
int R = A.length-1;
int C = A[0].length-1;
return contains(A, elem, 0, R, 0, C);
}
private static boolean contains(int[][] A, int elem, int xmin, int xmax,
@dapurv5
dapurv5 / Graph
Created January 4, 2013 14:21
Sample Graph
"A L:B D"
"B R:A C"
"C L:B D"
"D R:A C"
@dapurv5
dapurv5 / BipartiteMatchingCompute.java
Created January 4, 2013 14:33
Bipartite Matching with Apache Hama
@Override
public void compute(Iterator<TextPair> messages)
throws IOException {
if(isMatched()){
voteToHalt();
return;
}
switch((int)getSuperstepCount() % 4){
@dapurv5
dapurv5 / BipartiteOut
Created January 4, 2013 14:36
Bipartite Output
13/01/04 20:02:32 INFO bsp.BSPJobClient: Running job: job_localrunner_0001
13/01/04 20:02:32 INFO bsp.LocalBSPRunner: Setting up a new barrier for 1 tasks!
13/01/04 20:02:35 INFO bsp.BSPJobClient: Current supersteps number: 13
13/01/04 20:02:35 INFO bsp.BSPJobClient: The total number of supersteps: 13
13/01/04 20:02:35 INFO bsp.BSPJobClient: Counters: 12
13/01/04 20:02:35 INFO bsp.BSPJobClient: org.apache.hama.graph.GraphJobRunner$GraphJobCounter
13/01/04 20:02:35 INFO bsp.BSPJobClient: ITERATIONS=10
13/01/04 20:02:35 INFO bsp.BSPJobClient: MULTISTEP_PARTITIONING=1
13/01/04 20:02:35 INFO bsp.BSPJobClient: INPUT_VERTICES=4
13/01/04 20:02:35 INFO bsp.BSPJobClient: org.apache.hama.bsp.JobInProgress$JobCounter
@dapurv5
dapurv5 / BipartiteOutput
Created January 4, 2013 14:42
BipartiteOutput
Job Finished in 3.337 seconds
A TextPair{MatchVertex=B, Component=L}
B TextPair{MatchVertex=A, Component=R}
C TextPair{MatchVertex=D, Component=L}
D TextPair{MatchVertex=C, Component=R}
@dapurv5
dapurv5 / hello.c
Created January 15, 2013 12:35
jni-demo
#include<stdio.h>
#include<jni.h>
#include "Hello.h"
JNIEXPORT void JNICALL Java_Hello_sayHello(JNIEnv *env, jobject object, jint len){
printf("This is printed from native code\n");
}
@dapurv5
dapurv5 / Hello.java
Created January 15, 2013 12:38
Jni Demo
public class Hello{
static{
System.loadLibrary("Hello");
}
public native void sayHello(int length);
public static void main(String args[]){
String str = "Hello World, JNI";
Hello h = new Hello();
@dapurv5
dapurv5 / Hello.h
Created January 15, 2013 12:39
jni demo
#include <jni.h>
/* Header for class Hello */
#ifndef _Included_Hello
#define _Included_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Hello
@dapurv5
dapurv5 / TwitterStreamOAuth.java
Created May 14, 2013 15:40
Twitter Stream API using Pablo's Scribe library
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TwitterApi;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;
public class TwitterStreamOAuth {
private final static String ACCESS_TOKEN_KEY = "273014559-FevjK1FCxmHqXe1QIPcA4CnHFe6TAsJ0YefpITts";
private final static String ACCESS_TOKEN_SECRET = "PRNXlURgfEcCU6Fs4s7kG9QU6yyhJ8SNzGCDUf1mgI";
@dapurv5
dapurv5 / SpMatrixMult.java
Created May 18, 2013 02:29
Sparse Matrix Multiplication in Map Reduce
/**
* Copyright (c) 2013 Apurv Verma
*/
package org.anahata.hadoop.illustrations;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.anahata.commons.hadoop.io.IntInt;