Skip to content

Instantly share code, notes, and snippets.

View nkabrown's full-sized avatar

Nathan Brown nkabrown

View GitHub Profile
@nkabrown
nkabrown / document-height.js
Created April 5, 2016 18:17
document height dimension
// jquery's method to get total document height dimensions
const height = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight,
document.documentElement.scrollHeight, document.documentElement.offsetHeight);
@nkabrown
nkabrown / index.html
Last active March 29, 2016 15:59
d3 date icons
<!DOCTYPE html>
<meta charset="utf-8">
<title>D3 Date</title>
<style>
.dates {
margin-left: 200px;
}
}
.entry-date {
@nkabrown
nkabrown / dedupe.js
Created March 22, 2016 15:14
dedupe arrays in javascript
// deduplicate array of primitives
let deduped = arr.filter((el, i, arr) => arr.indexOf(el) === i);
// or
deduped = Array.from(new Set(arr));
// deduplicate array of ojects using a hash table
function dedupe(arr) {
let hashTable = {};
return arr.filter(function(el) {
@nkabrown
nkabrown / index.html
Last active March 15, 2016 19:42
d3 date icons
<!DOCTYPE html>
<meta charset="utf-8">
<title>D3 date</title>
<link href='https://fonts.googleapis.com/css?family=Fira+Sans' rel='stylesheet' type='text/css'>
<style>
.date-row {
margin-left: 100px;
}
.date-area {
@nkabrown
nkabrown / explanation.js
Last active March 14, 2016 19:53
replace label with explanation on hover
// function to replace label with label's explanation on hover.
function mouseover() {
const s = d3.select(this)[0][0];
s.innerHTML = 'true positive rate';
s.className = 'explanation';
}
function mouseout() {
const s = d3.select(this)[0][0];
s.innerHTML = 'Sensitivity';
@nkabrown
nkabrown / index.html
Last active March 4, 2016 15:03
d3 geojson map of allegheny county pa polling stations
<!DOCTYPE html>
<meta charset="UTF-8">
<title>D3 GeoJSON</title>
<style>
html,
body {
background-color: #000;
}
</style>
<div class="container">
@nkabrown
nkabrown / index.html
Last active March 3, 2016 14:18
d3 contour map
<!DOCTYPE html>
<meta charset="UTF-8">
<title>D3 Contour Map</title>
<style>
html,
body {
background: #000;
}
.container {
@nkabrown
nkabrown / lastChild.js
Last active March 1, 2016 14:48
a way to access and style last child elements with d3 and DOM web api
// a workaround to apply style properties to only one element of a collection of elements in a d3 selection
d3.select('.container-div')
.selectAll('div')
.data(data)
.enter().append('div')
.attr('class', 'contained-divs')
// show last child element on hover
.on('mouseover', function(d) {
var s = d3.select(this)[0][0],
s0 = s.lastChild;
@nkabrown
nkabrown / index.html
Last active April 7, 2018 04:25
d3 triangles
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.container {
width: 90%;
}
.triangle-grid {
width: 315px;
height: 315px;
margin: 0 auto;
@nkabrown
nkabrown / actantial-model.md
Last active February 22, 2016 20:12
modeling narrative structure