Skip to content

Instantly share code, notes, and snippets.

View RandomEtc's full-sized avatar
🦕

Tom Carden RandomEtc

🦕
View GitHub Profile
@RandomEtc
RandomEtc / README.mkd
Created September 28, 2010 00:11
smooth panning and zooming for polymaps
@RandomEtc
RandomEtc / csv2html.js
Created February 11, 2012 19:06
Quick node.js script to convert a CSV file to HTML
// first of all make sure we have enough arguments (exit if not)
if (process.argv.length != 5)
{
console.error("Usage: node csv2html.js input.csv template.ejs output.html")
console.error();
console.error("Outputs the given template for each row in the given input.")
console.error("Uses the first row of the CSV as column names in the template.")
process.exit(1);
}
@RandomEtc
RandomEtc / mongo_import.js
Created September 15, 2011 16:04
use node.js to copy from one mongo db to another
var url = require('url'),
mongodb = require('mongodb');
var sourceUrl = 'mongodb://user:pass@host:port/db',
targetUrl = 'mongodb://user:pass@host:port/db',
collectionName = 'my_awesome_collection';
function openDbFromUrl(mongoUrl, cb) {
var dbUrl = url.parse(mongoUrl),
dbName = dbUrl.pathname.slice(1), // no slash
@RandomEtc
RandomEtc / escaped-json.js
Created May 11, 2012 05:18
Extra escapey JSON encoding for node.js
// preserve Twitter's style of JSON string encoding...
// escape higher value unicode (lowercase hex)
// escape < and > (uppercase hex)
// escape / in strings (\/)
// hugs! https://gist.github.com/1306986
// http://stackoverflow.com/questions/4901133/json-and-escaping-characters
function escapedStringify(s, emit_unicode) {
var json = JSON.stringify(s);
return emit_unicode ? json : json.replace(/\//g,
function(c) {
@RandomEtc
RandomEtc / tile.js
Created November 9, 2010 01:25
shape rendering in nodejs with LearnBoost's node-canvas
// node.js geo polygon map tile rendering!
// requires https://github.com/learnboost/node-canvas and GeoJSON data files
// e.g.
// data from naturalearthdata.com converted to GeoJSON with GDAL's ogr2ogr
// or from datasf.org, reprojected too:
// ogr2ogr -f GeoJSON sfbay.js sfbay.shp -t_srs EPSG:4326
var Canvas = require('./vendor/node-canvas/lib/canvas'),
http = require('http'),
fs = require('fs');
@RandomEtc
RandomEtc / albers.js
Created July 14, 2010 23:18
An Albers Equal Area Conic projection in javascript, for protovis.
/*
An Albers Equal Area Conic projection in javascript, for protovis.
For centering the contiguous states of the USA in a 800x400 div, I used:
var scale = pv.Geo.scale(albers(23, -96, 29.5, 45.5))
.range({ x: -365, y: -375 }, { x: 1200, y: 1200 });
http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html
@RandomEtc
RandomEtc / 1-make-key
Created September 16, 2011 16:35
generating SSL keys and Certificate Signing Requests for Heroku / Nginx / RapidSSL
Key was generated using:
tom% openssl genrsa -des3 -out example.com.key 2048
Generating RSA private key, 2048 bit long modulus
....+++
..........................................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase for example.com.key:
Verifying - Enter pass phrase for example.com.key:
%tom
@RandomEtc
RandomEtc / .gitignore
Last active July 11, 2018 04:42
D3 Australia Conformal Conic
australian-states.json
ne_10m_admin_1_states_provinces_lakes.geojson
ne_10m_admin_1_states_provinces_lakes.geojson.gz
@RandomEtc
RandomEtc / README.md
Last active May 9, 2017 19:24
D3 Bar Chart Update Pattern
@RandomEtc
RandomEtc / README.md
Last active February 12, 2017 15:39
Advanced object constancy.

Fine-grained control of randomly entering and exiting things in D3.js, for impeccable object constancy. Adapted from an example co-authored with Mike Bostock.