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 / 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);
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 / 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 = [];
.on("data", function(data) { body.push(data); })
.on("end", function() { callback(null, body.join("")); })
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;
setInterval(function() {
key("keydown", 37);
key("keypress", 37);
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" "">
<plist version="1.0">
<string>Comma-Separated Values</string>
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 / 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 / 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
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.