Skip to content

Instantly share code, notes, and snippets.

View benjchristensen's full-sized avatar

Ben Christensen benjchristensen

View GitHub Profile
@benjchristensen
benjchristensen / http_client.py
Created May 23, 2012 15:43
Common HTTP Client Functions for Python CLI
import argparse
import os
import sys
import urllib2
import json
import collections
# initialize the argParser with common arguments such as environment
def initArgParser(scriptDescription):
parser = argparse.ArgumentParser(description=scriptDescription)
@benjchristensen
benjchristensen / index.html
Created May 23, 2012 16:35
Javascript Scope Test
<!doctype html>
<html lang="en">
<head>
<title>Javascript Scope Test</title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
@benjchristensen
benjchristensen / index.html
Created May 28, 2012 03:28
Issue 655 Example
<html>
<head>
<title>Interactive Line Graph</title>
<!--<script src="http://d3js.org/d3.v2.js"></script>-->
<script src="https://raw.github.com/mbostock/d3/8fe5b945ed7f4867b13a257d424dd29b1dd37e13/d3.v2.js"></script>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="sample_data.js"></script>
<script src="line-graph.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
<style>
@benjchristensen
benjchristensen / d3.v2.patched.js
Created June 5, 2012 16:54
Issue 655 Example (Patch)
// patched version of d3.v2.js
// bug report that this patches is at https://github.com/mbostock/d3/issues/655
(function(){if (!Date.now) Date.now = function() {
return +new Date;
};
try {
document.createElement("div").style.setProperty("opacity", 0, "");
} catch (error) {
var d3_style_prototype = CSSStyleDeclaration.prototype,
@benjchristensen
benjchristensen / d3.v2.patched.js
Created June 5, 2012 16:59
Issue 655 Example (Patch) Without Custom Formatting
// patched version of d3.v2.js
// bug report that this patches is at https://github.com/mbostock/d3/issues/655
(function(){if (!Date.now) Date.now = function() {
return +new Date;
};
try {
document.createElement("div").style.setProperty("opacity", 0, "");
} catch (error) {
var d3_style_prototype = CSSStyleDeclaration.prototype,
@benjchristensen
benjchristensen / index.html
Created June 5, 2012 17:03
Issue 655 Example Without Custom Formatting
<html>
<head>
<title>Interactive Line Graph</title>
<!--<script src="http://d3js.org/d3.v2.js"></script>-->
<script src="https://raw.github.com/mbostock/d3/8fe5b945ed7f4867b13a257d424dd29b1dd37e13/d3.v2.js"></script>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="sample_data.js"></script>
<script src="line-graph.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
<style>
@benjchristensen
benjchristensen / index.html
Created June 5, 2012 17:44
Issue 655 Fix #2
<html>
<head>
<title>Issue 655</title>
<script src="https://github.com/benjchristensen/d3/raw/fix-log-ticks/d3.v2.js"></script>
</head>
<body>
<a href="https://github.com/mbostock/d3/issues/655">D3.js Issue 655</a>
<p>
Testing this code:
@benjchristensen
benjchristensen / FuturesA.java
Last active November 13, 2022 18:34
FuturesA.java Simple example of using Futures.
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class FuturesA {
public static void run() throws Exception {
@benjchristensen
benjchristensen / FuturesA-snippet.java
Created January 30, 2013 05:54
Snippet of FuturesA.java (https://gist.github.com/4670979) Simple example of using Futures.
ExecutorService executor = new ThreadPoolExecutor(4, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>());
Future<String> f1 = executor.submit(new CallToRemoteServiceA());
Future<String> f2 = executor.submit(new CallToRemoteServiceB());
System.out.println(f1.get() + " - " + f2.get());
@benjchristensen
benjchristensen / FuturesB.java
Last active December 19, 2024 23:11
FuturesB.java Example of using Futures for nested calls showing how it blocks inefficiently.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;