Skip to content

Instantly share code, notes, and snippets.

View benjchristensen's full-sized avatar

Ben Christensen benjchristensen

View GitHub Profile
@benjchristensen
benjchristensen / index.html
Created May 2, 2012 19:37
Line Graph with Dual-scaled Axes using SVG and d3.js
<html>
<head>
<title>Line Graph with Dual-scaled Axes using SVG and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke-width: 1;
fill: none;
}
@benjchristensen
benjchristensen / index.html
Created May 2, 2012 19:34
Simple Line Graph using SVG and d3.js
<html>
<head>
<title>Simple Line Graph using SVG and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke: steelblue;
stroke-width: 1;
fill: none;
/**
* A mock for the java.util.Timer.schedule() method that allows manually incrementing time
* so as to have deterministic unit tests.
*/
private static class MockTimer implements ScheduledTimer {
private final ArrayList<ATask> tasks = new ArrayList<ATask>();
@Override
public synchronized void schedule(TimerTask task, int delay, int period) {
@benjchristensen
benjchristensen / TestRandom.java
Created January 5, 2012 17:33
Simple performance test of Math.random() for comparing machines
public class TestRandom {
public static void main(String args[]) {
long start = System.currentTimeMillis();
for (int i = 0; i < 100000000; i++) {
Math.random();
}
System.out.println("Math.random() Time: " + (System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
package com.mealbalance.ws;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@benjchristensen
benjchristensen / index.html
Created December 16, 2011 22:45
Dynamic Stacked Bar Chart using d3.js
<html>
<head>
<title>Dynamic Stacked Bar Chart using d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
rect.a {
fill: green;
}
rect.b {
fill: orange;
@benjchristensen
benjchristensen / index.html
Created December 13, 2011 19:34
Animated Circle using d3.js
<html>
<head>
<title>Animated Circle Using d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
</head>
<body>
<table>
<tr>
<td>
@benjchristensen
benjchristensen / Money.java
Created December 7, 2011 07:44
Money.java
import static java.math.BigDecimal.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
@benjchristensen
benjchristensen / JavadocFilter.java
Created November 30, 2011 20:29
Doclet for filtering public classes from Javadoc
import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import com.sun.javadoc.Doc;
import com.sun.javadoc.DocErrorReporter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import junit.framework.TestCase;
import org.junit.Test;