Skip to content

Instantly share code, notes, and snippets.

View shawnbot's full-sized avatar
🎹

Shawn Allen shawnbot

🎹
View GitHub Profile
@shawnbot
shawnbot / lib.js
Created August 27, 2015 18:59
ES6 module weirdness
export default function foo() {
return 'foo';
};
export function bar() {
return 'bar';
};
@shawnbot
shawnbot / README.md
Last active August 29, 2015 13:56
Uniformly scaled geo thumbnails

This example shows how to use d3 to create uniformly scaled geographic feature thumbnails. There are two interesting features of SVG at play here:

  1. The viewBox attribute is used to "zoom in" to the individual states.
  2. The use element is used to redraw a common background states path into each thumbnail, reducing DOM overhead.

The other nice thing here is that we didn't have to define the SVG elements'

@shawnbot
shawnbot / README.md
Created February 27, 2014 21:14
Geo thumbnails (Mercator)

This tweak to my original example uses a Mercator projection rather than Albers USA, which straightens out many of the state borders and puts Alaska and Hawaii in their right places.

Good call, Jeremy Stucki!

@shawnbot
shawnbot / casualties.tsv
Created August 3, 2014 00:49
Gaza casualties
First name Second name Third name Fourth name Fifth name Tribe Consolidated tribe Gender Age Death location Death date Ground offensive?
Naji Jamal al-Fajm al-Fajm al-Fajm M 26 Han Younis 7/22/2014 1
Ebtehal Ibrahim ar-Remahi ar-Remahi ar-Remahi F - Deir al-Balah 7/22/2014 1
Yousef Ibrahim ar-Remahi ar-Remahi ar-Remahi M - Deir al-Balah 7/22/2014 1
Eman Ibrahim ar-Remahi ar-Remahi ar-Remahi F - Deir al-Balah 7/22/2014 1
Salwa abu-Mneifi abu-Mneifi abu-Mneifi F - Han Younis 7/22/2014 1
Salwa abu-Mneifi abu-Mneifi abu-Mneifi F - Han Younis 7/22/2014 1
Abdullah Ismael al-Baheessy al-Baheessy al-Baheessy M 26 Deir al-Balah 7/22/2014 1
Mos’ab Saleh Salama Salama Salama M 18 Han Younis 7/22/2014 1
Ibrahim Nasr Haroun Haroun Haroun M 37 Nusseirat 7/22/2014 1
@shawnbot
shawnbot / README.md
Last active August 29, 2015 14:13
Progressive ARIA tabs in D3

swagger-static

This document is largely superceded by the swagger-static repo, where I'm now planning a project. GitHub won't notify me of comments here, so if you want to get in touch please comment on or file an issue. Thanks!

Background

At 18F we're implementing [Swagger]-compliant APIs to make them more accessible and facilitate simpler documentation. Unfortunately, the only generally accepted way of exposing human-readable Swagger API documentation is [SwaggerUI], a client-side JavaScript library with some serious issues:

  1. Because all SwaggerUI-based documentation is rendered at runtime, search engines are [theoretically] unable to crawl their contents.
  2. Tight coupling with jQuery and a [long list of dependencies](https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html#L10-L2
@shawnbot
shawnbot / async.js
Created February 12, 2015 23:49
asyncdammit
function noreallygimmeasyncdammit(sync) {
return function() {
var args = [].slice.call(arguments),
next = args.pop();
try {
var value = sync.apply(this, args);
} catch (err) {
return next(err);
}
next(null, value);
@shawnbot
shawnbot / charts.html
Last active August 29, 2015 14:15
chart tooltip Jinja macros
{% macro series(bars, value_key, tooltip=None) %}
<div class="chart-series chart-series--vertical">
{% for bar in bars %}
<div class="chart-series__bar" data-value="{{ bar[value_key] }}">
{% if tooltip %}
<div class="chart-series__bar__tooltip">
<div class="chart-series__bar__tooltip__content">
{{ tooltip(bar) }}
</div>
</div>

Stateful Checkboxes

This quick little hack creates a global function named checkboxes() that uses [localStorage] to remember the state of checkboxes on the host page. Usage:

var boxes = checkboxes({
    // the checkbox selector (always prefixed with 'input[type=checkbox]')
    selector:   '.stateful',
    // the storage engine (only 'localStorage' is supported here)
    storage:    'localStorage',
 // the prefix for all storage keys