Skip to content

Instantly share code, notes, and snippets.

Mike Bostock mbostock

Block or report user

Report or block mbostock

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mbostock
mbostock / dabblet.css
Created Jan 1, 2012
The first commented line is your dabblet’s title
View dabblet.css
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
@mbostock
mbostock / sample-client.js
Created Jan 4, 2012
Cube Metrics Client (Node.js + WebSockets)
View sample-client.js
var websocket = require("websocket");
var client = new websocket.client();
client.on("connect", function(connection) {
var remaining = 762; // based on start, stop, and step
connection.on("message", function(message) {
if (message.type === "utf8") {
if (!--remaining) connection.close();
@mbostock
mbostock / get.js
Created Jul 11, 2012
Read File or HTTP
View get.js
var fs = require("fs"),
http = require("http");
function get(url, callback) {
if (/^http:/.test(url)) {
http.get(url, function(response) {
var body = [];
response
.on("data", function(data) { body.push(data); })
.on("end", function() { callback(null, body.join("")); })
@mbostock
mbostock / index.js
Created Aug 7, 2012
Google Hurdles
View index.js
function key(type, code) {
var e = document.createEvent("Event");
e.initEvent(type, true, true);
e.keyCode = code;
document.getElementById("hplogo").dispatchEvent(e);
}
setInterval(function() {
key("keydown", 37);
key("keypress", 37);
@mbostock
mbostock / CSV.tmLanguage
Created Aug 13, 2012
CSV Syntax Definition
View CSV.tmLanguage
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>csv</string>
</array>
<key>name</key>
<string>Comma-Separated Values</string>
@mbostock
mbostock / index.js
Created Aug 16, 2012
Git-backed Node Blob Server
View index.js
var express = require("express"),
gitteh = require("gitteh"),
path = require("path");
var server = express();
server.get("/", function(request, response) {
gitteh.openRepository(path.join(__dirname, "repository", ".git"), function(error, repository) {
if (error) return response.end(error.toString());
repository.getBlob("9b4b40c2bca67e781930105fa190b9b90235cfe5", function(error, blob) {
@mbostock
mbostock / index.js
Created Aug 29, 2012
Lazy Scale Domain
View index.js
// Create a scale, but don't set the domain until the data is known.
var x = d3.scale.linear()
.range([0, width]);
// Load the data.
d3.json("data.json", function(data) {
// Now we can compute the domain and update the scale.
x.domain([0, d3.max(data)]);
@mbostock
mbostock / cleanup.js
Created Sep 9, 2012
Clean Up for Natural Earth GeoJSON
View cleanup.js
var fs = require("fs");
var roundPrecision = 1e6;
fs.readFile("/dev/stdin", "utf-8", function(error, input) {
var collection = JSON.parse(input);
switch (collection.type) {
case "FeatureCollection": return cleanupFeatureCollection(collection);
case "GeometryCollection": return cleanupGeometryCollection(collection);
default: throw "unknown type: " + collection.type;
View us-boundary.json
{"type":"MultiPolygon","coordinates":[[[[-155.59,20.14],[-155.58,20.13],[-155.57,20.13],[-155.56,20.14],[-155.55,20.14],[-155.53,20.14],[-155.49,20.11],[-155.45,20.11],[-155.34,20.06],[-155.21,20],[-155.17,19.97],[-155.09,19.88],[-155.08,19.87],[-155.08,19.84],[-155.08,19.77],[-155.07,19.74],[-155.06,19.74],[-155.02,19.75],[-154.99,19.74],[-154.98,19.73],[-154.98,19.72],[-154.97,19.67],[-154.96,19.65],[-154.92,19.61],[-154.87,19.59],[-154.79,19.54],[-154.8,19.52],[-154.81,19.5],[-154.82,19.48],[-154.83,19.46],[-154.91,19.42],[-154.92,19.41],[-155.01,19.33],[-155.02,19.33],[-155.05,19.32],[-155.07,19.32],[-155.1,19.3],[-155.17,19.28],[-155.19,19.28],[-155.27,19.28],[-155.29,19.27],[-155.3,19.27],[-155.32,19.25],[-155.35,19.22],[-155.37,19.22],[-155.38,19.21],[-155.4,19.2],[-155.42,19.18],[-155.44,19.17],[-155.49,19.14],[-155.5,19.14],[-155.55,19.1],[-155.55,19.08],[-155.57,19.03],[-155.61,18.97],[-155.63,18.96],[-155.64,18.95],[-155.66,18.93],[-155.67,18.93],[-155.67,18.94],[-155.69,18.96],[-155.71,18.99],[-15
@mbostock
mbostock / projection.js
Created Sep 29, 2012
Projection Contexts
View projection.js
projection.line = function(coordinates, context) {
if (!(n = coordinates.length)) return;
context = radiansAndRotateContext(projectAndTransformContext(context));
var i = 0,
n = coordinates.length,
p = coordinates[0];
context.moveTo(p[0], p[1]);
while (++i < n) context.lineTo((p = coordinates[i])[0], p[1]);
};
You can’t perform that action at this time.