Skip to content

Instantly share code, notes, and snippets.

Justin Palmer caged

Block or report user

Report or block caged

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
@caged
caged / svg-to-png.js
Created Jan 27, 2013
Convert SVG's to PNGs. This works OK if the SVG's styles are inline. The SVG element must contain an xmlns attribute. Webkit also requires you specify a font size on `text` elements.
View svg-to-png.js
var svg = document.getElementById('graph'),
xml = new XMLSerializer().serializeToString(svg),
data = "data:image/svg+xml;base64," + btoa(xml),
img = new Image()
img.setAttribute('src', data)
document.body.appendChild(img)
@caged
caged / d3-server.js
Last active Jul 9, 2019
Directly render and serve d3 visualizations from a nodejs server.
View d3-server.js
// Start `node d3-server.js`
// Then visit http://localhost:1337/
//
var d3 = require('d3'),
http = require('http')
http.createServer(function (req, res) {
// Chrome automatically sends a requests for favicons
// Looks like https://code.google.com/p/chromium/issues/detail?id=39402 isn't
// fixed or this is a regression.
@caged
caged / graphite.md
Created Mar 3, 2012
Installing Graphite on OS X Lion
View graphite.md

This is a general overview (from memory) of the steps I used to install graphite (http://graphite.wikidot.com) on OS X Lion. I think the steps are in order but YMMV. Please fork and fix if you find an error.

Install Python 2.7.2

brew install python

Check your env

$ python --version
View keybase.md

Keybase proof

I hereby claim:

  • I am caged on github.
  • I am caged (https://keybase.io/caged) on keybase.
  • I have a public key ASBSVYNed5hAUR9evtZAZiOmAKi0Mg40LlXoSEWlX2e0hAo

To claim this, I am signing this object:

@caged
caged / README.md
Last active Nov 16, 2018 — forked from mbostock/.block
Using d3-tip to add tooltips to a d3 bar chart
@caged
caged / scale.rb
Created Nov 22, 2012
Linear scale interpolation in Ruby based on d3.js's implementation
View scale.rb
# Returns a lambda used to determine what number is at t in the range of a and b
#
# interpolate_number(0, 500).call(0.5) # 250
# interpolate_number(0, 500).call(1) # 500
#
def interpolate_number(a, b)
a = a.to_f
b = b.to_f
b -= a
lambda { |t| a + b * t }
View flow-no.js
class A extends Component {
handleSomeEvent = (value: string) => {
/* do stuff */
}
render() {
return <B onSubmit={this.handleSomeEvent} />
}
}
@caged
caged / index.html
Last active Apr 5, 2018
Plot vector points on a cropped raster image with d3.js
View index.html
<!doctype html>
<meta charset="utf-8">
<body>
<style media="screen">
body {
margin: 0;
}
.supermarket {
fill: red;
View places.topo.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@caged
caged / d3-multi-line.js.coffee
Created Dec 30, 2011
d3.js line chart with multiple lines and points
View d3-multi-line.js.coffee
$ ->
version = Number(document.location.hash.replace('#', ''))
data = [[3,7,9,1,4,6,8,2,5], [5,2,3,4,9,6,4,6,8]]
[pt, pl, pr, pb] = [20, 20, 20, 20] # padding
w = 800 - (pl + pr)
h = 300 - (pt + pb)
max = d3.max(data, (d) -> d3.max(d))
# Scales
x = d3.scale.linear().domain([0, data[0].length - 1]).range [0, w]
You can’t perform that action at this time.