Skip to content

Instantly share code, notes, and snippets.

@ejb
ejb / .gitignore
Created May 15, 2018 — forked from starcalibre/.gitignore
Fast Interactive Canvas Scatterplot
View .gitignore
.idea/
*.iml
@ejb
ejb / .block
Last active Jul 18, 2019
Structuring D3 code with ES6 classes
View .block
license: mit
@ejb
ejb / celebrate.js
Last active May 3, 2017
Fill an element with celebratory (financial) emojis. As seen on http://www.wsj.com/graphics/has-the-dow-hit-20000-yet/
View celebrate.js
function celebrate(el) {
if (doesSupportEmoji() === false) {
// browser does not support emoji, provide a fallback if you like
return;
}
var can = document.createElement('canvas');
var ctx = can.getContext('2d');
@ejb
ejb / .block
Last active Aug 2, 2016
Structuring D3 v4 code with constructor functions
View .block
license: mit
@ejb
ejb / perftest.js
Created Jun 30, 2016
Performance test: Loops versus array methods
View perftest.js
// This script should be run with Node.js
var short = generateDummy(100);
var med = generateDummy(10000);
var long = generateDummy(1000000);
console.info('Big loop:');
test(short, bigLoop);
test(med, bigLoop);
@ejb
ejb / .block
Last active Nov 15, 2020
Structuring D3 code with constructor functions
View .block
license: mit
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
.chapter-illo {
width: 100%;
}
@ejb
ejb / clickAnywhereElse.js
Created Dec 29, 2014
Tiny jQuery plugin for attaching a click event to everything except for the specified element (and its children). To use, just paste clickAnywhereElse.js into your JavaScript file.
View clickAnywhereElse.js
// Written by Elliot Bentley, inspired by http://stackoverflow.com/a/3028037
$.fn.clickAnywhereElse = function(callback) {
var className = '.'+this.attr('class').replace(/ /g,'.');
$('html').click(function(event){
if ( !$(event.target).closest( className ).length ) {
callback();
}
});
};
View m3.js
var json = 'http://wsjgraphics.cartodb.com/api/v2/viz/8e5d6502-c098-11e3-8209-0edbca4b5057/viz.json';
m3({
mapId: 'nmap',
json: json,
center_lat: 49,
center_lon: 36,
zoom: 5,
maxZoom: 7,
minZoom: 4,