Skip to content

Instantly share code, notes, and snippets.

View shawnbot's full-sized avatar
🎹

Shawn Allen shawnbot

🎹
View GitHub Profile
@shawnbot
shawnbot / splatta.js
Created November 5, 2012 18:58
grab all of the data from d3
// select everything
var data = d3.selectAll("*")
// filter down to nodes with bound data objects
.filter(function(d) { return typeof d === "object"; })
// attach a reference back to the node on each data object
.each(function(d) { d.__node__ = this; })
// return the list of data objects as an array
.data();
@shawnbot
shawnbot / index.html
Created November 16, 2012 02:53
d3 topological simplification introspection
<!DOCTYPE html>
<html>
<head>
<title>Topological line simplification segments</title>
<script src="http://d3js.org/d3.v2.min.js?v2.10.3"></script>
<script src="simplify.js"></script>
<style type="text/css">
#container {
width: 800px;
@shawnbot
shawnbot / d3-compat.js
Created November 29, 2012 02:00
d3 "mouseenter" and "mouseleave" event support
(function() {
// get a reference to the d3.selection prototype,
// and keep a reference to the old d3.selection.on
var d3_selectionPrototype = d3.selection.prototype,
d3_on = d3_selectionPrototype.on;
// our shims are organized by event:
// "desired-event": ["shimmed-event", wrapperFunction]
var shims = {
@shawnbot
shawnbot / leaflet-compact.js
Created March 13, 2013 18:04
A Leaflet TileLayer class for loading "compact" URL schemes.
L.CompactTileLayer = L.TileLayer.extend({
getTileUrl: function(tilePoint) {
this._adjustTilePoint(tilePoint);
var col = String("000000" + tilePoint.x).slice(String(tilePoint.x).length),
row = String("000000" + tilePoint.y).slice(String(tilePoint.y).length),
zoom = this._getZoomForUrl();
return this._url
.replace("{z}", zoom)
.replace("{x}", col.slice(0, 3) + "/" + col.slice(3, 6))
.replace("{y}", row.slice(0, 3) + "/" + row.slice(3, 6));
@shawnbot
shawnbot / load-queue.js
Created March 20, 2013 23:50
queue + d3 = asynchronous, parallelized, event-dispatching load queue
var loadQueue = function() {
var q = queue(),
defer = q.defer,
dispatch = d3.dispatch("progress", "complete"),
requests = [];
q.defer = function(load, url) {
return defer(function(callback) {
var req = load(url, function(error, data) {
req.loaded = req.total;
@shawnbot
shawnbot / index.md
Last active August 23, 2023 10:18
Testing web pages with Xcode's iOS Simulator

Finding the Simulator

You can test with the iOS Simulator that comes with Xcode. Navigate to the Xcode app in the Finder, right click and select "Show Package Contents":

screen shot 2013-05-06 at 12 04 27 pm

Then navigate to Contents > Applications, and open the shortcut to "iPhone Simulator" (it may be called "iOS Simulator" depending on which version of Xcode you're running):

screen shot 2013-05-06 at 12 05 45 pm

@shawnbot
shawnbot / ogr2csv.sh
Created July 24, 2013 23:05
A shell script to convert OGR point datasources to CSV, re-projecting to WGS84 and encoding latitude and longitude as Y and X columns, respectively.
#!/bin/sh
ogr2ogr -F CSV -lco GEOMETRY=AS_XY -t_srs EPSG:4326 $2_dir $1
mv $2_dir/*.csv $2
rm -r $2_dir
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
}
.boundary {
@shawnbot
shawnbot / preflight.sh
Created August 3, 2013 00:19
Test pre-flight CORS headers
hostname=http://example.com
url=http://cors-enabled-server.com/path/to/data.json
curl -H "Origin: ${hostname}" -X OPTIONS -H "Access-Control-Request-Method: GET" -I "${url}"
@shawnbot
shawnbot / Makefile
Created August 7, 2013 01:36
Read environment variables from your .env in make tasks.
test:
source .env && echo "my secret key is: $$SECRET_KEY"