Skip to content

Instantly share code, notes, and snippets.

View ankurpshah's full-sized avatar
:bowtie:
Focusing

Ankur Shah ankurpshah

:bowtie:
Focusing
View GitHub Profile
@ankurpshah
ankurpshah / OSM_Overlay_Demo
Last active December 14, 2015 17:39
Map Control Example
<!DOCTYPE html>
<html>
<head>
<title>Google Mapathon 2013</title>
<meta content="en" http-equiv="content-language">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en&key=AIzaSyDZ82d3j-OqU8JHoU8JSAz-gJFty9ERrao"></script>
<script type="text/javascript">
#!/usr/bin/perl
#
# Pre-commit hook for running checkstyle on changed Java sources
#
# To use this you need:
# 1. checkstyle's jar file somewhere
# 2. a checkstyle XML check file somewhere
# 3. To configure git:
# * git config --add checkstyle.jar <location of jar>
# * git config --add checkstyle.checkfile <location of checkfile>
@ankurpshah
ankurpshah / mutablestate
Created July 27, 2013 08:30
Mutable state example
public class Customer {
// No setter method
private final List<Order> orders;
public List<Order> getOrders() { return orders; }
public Customer(...) {...}
}
@ankurpshah
ankurpshah / ooactionlistener
Created July 27, 2013 08:38
Objecte Oriented Actionlistener
package functions;
import java.awt.*;
import java.awt.event.*;
class HelloButtonApp2 {
private final Button button = new Button();
}
public HelloButtonApp2() {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Hello There: event received: " + e);
@ankurpshah
ankurpshah / functionalactionlistener
Created July 27, 2013 08:40
Functional Actionlistener
package functions;
public interface Function1Void<A> {
void apply(A a);
}
@ankurpshah
ankurpshah / java8lambda
Created July 27, 2013 08:45
Java 8 Lambda example
public FunctionalHelloButtonApp() {
button.addActionListener(
#{ ActionEvent e -> System.out.println("Hello There: event received: "+e) }
);
}
@ankurpshah
ankurpshah / recursivetreetraversal
Created July 27, 2013 09:05
Recursive tree traversal
package functions;
import static org.junit.Assert.*;
import org.junit.Test;
public class RecursionTest {
static class Tree {
// public fields for simplicity
public final Tree left; // left subtree
public final Tree right; // right subtree
public final int value; // value at this node
public Tree(Tree left, int value, Tree right) {
@ankurpshah
ankurpshah / lazydatastructure
Created July 27, 2013 09:09
Infinite data structure with Lazy data structure with tail recursion
package math;
import static datastructures2.ListModule.*;
public class NaturalNumbers {
public static final int ZERO = 0;
public static int next(int previous) { return previous + 1; }
public static List<Integer> take(int count) {
return doTake(emptyList(), count);
}
private static List<Integer> doTake(List<Integer> accumulator, int count) {
if (count == ZERO)
@ankurpshah
ankurpshah / declarativeVsImperative
Created July 27, 2013 09:12
Declarative and imperative Factorial program
package math;
public class Factorial {
public static long declarativeFactorial(int n) {
assert n > 0 : "Argument must be greater than 0";
if (n == 1) return 1;
else return n * declarativeFactorial(n-1);
}
public static long imperativeFactorial(int n) {
assert n > 0 : "Argument must be greater than 0";
long result = 1;
@ankurpshah
ankurpshah / functionalnone
Created July 27, 2013 09:19
Functional Null
package option;
public final class None<T> extends Option<T> {
public static class NoneHasNoValue extends RuntimeException {}
public None() {}
public boolean hasValue() { return false; }
public T get() { throw new NoneHasNoValue(); }
@Override
public String toString() { return "None"; }
@Override
public boolean equals(Object other) {