Skip to content

Instantly share code, notes, and snippets.

View benjchristensen's full-sized avatar

Ben Christensen benjchristensen

View GitHub Profile
@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 / 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 / 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;
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 / 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();
/**
* 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 / 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;
@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 21:26
Line graph over time with multiple data points using SVG and d3.js
<html>
<head>
<title>Line graph over time with multiple data points using SVG and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
body {
font-family: "Helvetica Neue", Helvetica;
}
/* tell the SVG path to be a thin blue line without any area fill */
@benjchristensen
benjchristensen / index.html
Last active December 7, 2023 13:39
Interactive Line Graph (D3)
<!--
* 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
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.