Skip to content

Instantly share code, notes, and snippets.

@nrabinowitz
nrabinowitz / gist:75611aea890afe21b234
Created October 3, 2014 19:57
Git branch and status color in prompt
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver="[$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')]"
@nrabinowitz
nrabinowitz / progsvc.php
Created August 6, 2011 04:19
Mock PHP service for timemap.js progressive loading
<?
// get timestamps
$start = strtotime($_GET['start']);
$end = strtotime($_GET['end']);
$cb = $_GET['callback'];
// start data
echo "$cb([";
@nrabinowitz
nrabinowitz / index.html
Created October 31, 2011 20:43 — forked from njvack/index.html
Beeswarm plot with gravity and collisions
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Beeswarm plot - collision detection</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js"></script>
</head>
<body>
@nrabinowitz
nrabinowitz / index.html
Created March 14, 2012 05:24
Histogram with a normal distribution
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Histogram</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.min.js"></script>
<style type="text/css">
body {
margin: 3em;
}
@nrabinowitz
nrabinowitz / .gitignore
Created April 22, 2012 23:10 — forked from karmi/.gitignore
Life Expectancy Slope Graph [WIP]
.DS_Store
@nrabinowitz
nrabinowitz / index.html
Created September 7, 2012 16:22 — forked from stepheneb/index.html
D3 Example: zoom, pan, and axis rescale
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>One Graph</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<script type="text/javascript" src="simple-graph.js"></script>
<style type="text/css">
body { font: 13px sans-serif; }
rect { fill: #fff; }
@nrabinowitz
nrabinowitz / README.md
Created December 9, 2012 20:51
Raster geocoding with D3.js

This demonstrates raster-based reverse geocoding using canvas and D3.js. Geocoding is based on the color of the pixel at a given projected position. Note that the canvas is only shown here for the sake of explanation and debugging - this would in fact probably work faster if the canvas was not attached to the document at all.

The biggest remaining issue here is precision, which depends on:

  • the size of the canvas, and
  • the projection used.

Determining the optimum size based on the accuracy of your data is left as an exercise for the reader. Edge cases will also fail here, generally returning null - one option might be to stroke neighborhoods in a color, and then return an "uncertain" value for any non-grayscale pixel.

<html></html>
@nrabinowitz
nrabinowitz / fitProjection.js
Created February 7, 2012 00:46
D3 function for fitting a projection to geodata
function fitProjection(projection, data, box, center) {
// get the bounding box for the data - might be more efficient approaches
var left = Infinity,
bottom = -Infinity,
right = -Infinity,
top = Infinity;
// reset projection
projection
.scale(1)
.translate([0, 0]);
["832003fffffffff","832002fffffffff","83201cfffffffff","83201dfffffffff","83200efffffffff","832001fffffffff","832000fffffffff","832006fffffffff","832015fffffffff","832011fffffffff","83201efffffffff","832018fffffffff","832019fffffffff","83200afffffffff","832008fffffffff","83200cfffffffff","83202afffffffff","832005fffffffff","832004fffffffff","832031fffffffff","832033fffffffff","832014fffffffff","832010fffffffff","832013fffffffff","8320adfffffffff","83201afffffffff","83201bfffffffff","8320e6fffffffff","8320e4fffffffff","83200bfffffffff","832009fffffffff","83200dfffffffff","83202bfffffffff","832028fffffffff","83202efffffffff","832023fffffffff","832022fffffffff","832035fffffffff","832030fffffffff","832032fffffffff","832189fffffffff","832016fffffffff","832012fffffffff","8320acfffffffff","8320a8fffffffff","8320a9fffffffff","8320f4fffffffff","8320f5fffffffff","8320e2fffffffff","8320e0fffffffff","8320e5fffffffff","832056fffffffff","832054fffffffff","832072fffffffff","832076fffffffff","832029fffffffff","83202dffffffff