Skip to content

Instantly share code, notes, and snippets.

@bewest
bewest / README.md
Created December 11, 2012 17:42 — forked from mbostock/.block
d3.geo.tile
@bewest
bewest / README.md
Created December 11, 2012 17:37 — forked from mbostock/.block
L*a*b* and HCL color spaces

D3 2.10 adds support for CIE L*a*b* and HCL. These perceptually-motivated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L*a*b* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post How To Avoid Equidistant HSV Colors and Drew Skau’s post Dear NASA: No More Rainbow Color Scales, Please.

You can create L*a*b* or HCL colors directly using d3.lab or d3.hcl. For example:

var steelblue = d3.lab(52, -4, -32);
var steelblue = d3.hcl(-97, 32, 52);

You can also convert from RGB or HSL. This is useful for creating brighter or darker colors with uniform changes in perception:

@bewest
bewest / index.html
Created December 11, 2012 05:50 — 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; }
@bewest
bewest / node-on-ec2-port-80.markdown
Created October 17, 2012 07:21 — forked from kentbrew/node-on-ec2-port-80.md
How I Got Node.js Talking on EC2's Port 80

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

}).listen(80);
@bewest
bewest / snippet.py
Created October 9, 2012 07:13 — forked from n-west/gist:3857129
decode chunk modifications
def decode_chunk(chunk):
"""
Experiment: decode a chunk!
<snip>
"""
# give ourselves a copy of this record as a bytearray to sanitize things a bit.
record = bytearray(chunk)
if chunk == 0x1f:
try:
print hex(record)

Rename some files

find the files like this: find ./ -type f -name "*.mp3"

Pipe them into a loop: help read help while

body {
font-family: Helvetica, Verdana
}
p {
padding: 7px 10px;
}
#demo {
border: 1px solid #999;
}
@bewest
bewest / index.html
Created January 6, 2012 17:19 — forked from mbostock/.block
d3.geo.tiler
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://github.com/mbostock/d3/raw/v1.8.4/d3.js"></script>
<script type="text/javascript" src="https://github.com/mbostock/d3/raw/v1.8.4/d3.geo.js"></script>
<script type="text/javascript" src="https://github.com/simplegeo/polymaps/raw/v2.4.0/polymaps.js"></script>
<script type="text/javascript" src="tiler.js"></script>
<style type="text/css">
@import url("http://github.com/simplegeo/polymaps/raw/v2.4.0/examples/example.css");
@bewest
bewest / index.html
Created September 2, 2011 02:30 — forked from stepheneb/index.html
D3 Example: spline, zoom and pan
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Spline + Pan</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<style type="text/css">
body {
font: 13px sans-serif;
}