Skip to content

Instantly share code, notes, and snippets.

View arunma's full-sized avatar

Argon arunma

  • Singapore
View GitHub Profile
@arunma
arunma / MonadsTesting.scala
Last active August 29, 2015 14:15
Monads Example - for comprehensions
object MonadsTesting {
println("http://stackoverflow.com/questions/14598990/confused-with-the-for-comprehension-to-flatmap-map-transformation")
//> http://stackoverflow.com/questions/14598990/confused-with-the-for-comprehens
//| ion-to-flatmap-map-transformation
val some=Some ("hello") //> some : Some[String] = Some(hello)
some.flatMap(str=>Some(str+"x")) //> res0: Option[String] = Some(hellox)
@arunma
arunma / QuickSort.java
Created August 15, 2012 11:26
QuickSort
package me.rerun;
import java.util.Arrays;
public class QuickSort {
public static void quickSort (Comparable comparableArray[], int lowIndex, int highIndex){
//at least one item must exist in the array
if (lowIndex>=highIndex){
@arunma
arunma / ExecutorSubmit.java
Created September 15, 2012 18:58
Thread Pool Executor using submit()
package me.rerun.incubator;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
@arunma
arunma / ExecutorInvokeAll.java
Created September 15, 2012 18:55
Thread Pool Executor using invokeAll()
package me.rerun.incubator;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;
@arunma
arunma / RunnableAdapter.java
Created September 15, 2012 19:20
FutureTask Runnable Adapter
static final class RunnableAdapter<T> implements Callable<T> {
final Runnable task;
final T result;
RunnableAdapter(Runnable task, T result) {
this.task = task;
this.result = result;
}
@arunma
arunma / InfixToValue.groovy
Created October 14, 2012 16:04
Infix expression evaluator - multiple digits
/**
* Only basic arithmetic operators are supported. However, could easily be
* extended to support any binary operators
*
* This program is not an infix to postfix converter. However, this program does the following
*
* 1) Evaluates a non-parenthesized infix expression and drives it to a final value
* 2) Does not support parentheses
* 3) Supports multiple digits as operands
* 4) Empty space allowed
@arunma
arunma / InfixToValueParenthesis.groovy
Created October 16, 2012 17:30
Infix expression evaluator with parentheses - multiple digits
/**
* Only basic arithmetic operators are supported. However, could easily be
* extended to support any binary operators
*
* This program is not an infix to postfix converter. However, this program does the following
*
* 1) Evaluates a parenthesized or non-parenthesized infix expression and drives it to a final value
* 2) Supports parentheses
* 3) Supports multiple digits as operands
* 4) Empty space allowed
@arunma
arunma / DeepEquals.java
Created November 4, 2012 17:08
Arrays.deepEquals vs Arrays.equals
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.util.Arrays;
import org.testng.annotations.Test;
public class DeepEquals {
@arunma
arunma / MergeSort
Created May 31, 2013 12:19
Merge Sort
package com.sorting.merge;
import static com.sorting.insert.SortUtils.less;
public class MergeSort {
public Comparable[] sort(Comparable[] items) {
sort (items,new Comparable[items.length], 0, items.length-1);
@arunma
arunma / InsertionSort.java
Created May 31, 2013 12:18
Insertion Sort
package com.sorting.insert;
import static com.sorting.insert.SortUtils.*;
public class InsertionSort {
public Comparable[] sort(Comparable[] items) {
for (int i=0;i<items.length;i++){
for (int j=i;j>0;j--){