Skip to content

Instantly share code, notes, and snippets.

View popovichN's full-sized avatar

Nadja Popovich popovichN

View GitHub Profile
function getRandomColor () {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color
}
@popovichN
popovichN / gist:18c0b0f409f5de8fa28464e000d96f8f
Last active July 10, 2025 23:06
NYT state abbreviations
const states = [
{"name":"Alabama","abbrev":"Ala."},
{"name":"Alaska","abbrev":"Alaska"},
{"name":"Arizona","abbrev":"Ariz."},
{"name":"Arkansas","abbrev":"Ark."},
{"name":"California","abbrev":"Calif."},
{"name":"Colorado","abbrev":"Colo."},
{"name":"Connecticut","abbrev":"Conn."},
{"name":"Delaware","abbrev":"Del."},
{"name":"District of Columbia","abbrev":"D.C."},
@popovichN
popovichN / component.html
Last active February 21, 2017 22:52
Bar chart for Svelte Repl
<!-- responsive bar chart -->
<div class='chart'>
<h2>US birthrate by year</h2>
<svg ref:svg>
<g transform='translate(0,0)'>
<g class='axes'>
@popovichN
popovichN / component.html
Last active February 21, 2017 22:52
Area chart for Svelte Repl
<!-- responsive area chart -->
<div class='chart'>
<h2>US birthrate by year</h2>
<svg ref:svg>
<g transform='translate(0,0)'>
<g class='axes'>
<!-- y axis -->
@popovichN
popovichN / component.html
Last active February 21, 2017 22:52
Line chart for Svelte Repl
<!-- basic line chart -->
<div class='chart'>
<h2>US birthrate by year</h2>
<svg style='width: {{width}}px; height: {{height}}px;'>
<g transform='translate(0,0)'>
<defs>
<pattern id="hash" width="6" height="6" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
<rect width="3" height="6" transform="translate(0,0)" fill="#ccc"></rect>
</pattern>
</defs>
@popovichN
popovichN / months lookup
Last active March 21, 2016 22:07
months lookup
const months = {
0: { 'month': 'January', 'abbrev': 'Jan'},
1: { 'month': 'February', 'abbrev': 'Feb'},
2: { 'month': 'March', 'abbrev': 'Mar'},
3: { 'month': 'April', 'abbrev': 'Apr'},
4: { 'month': 'May', 'abbrev': 'May'},
5: { 'month': 'June', 'abbrev': 'Jun'},
6: { 'month': 'July', 'abbrev': 'Jul'},
7: { 'month': 'August', 'abbrev': 'Aug'},
8: { 'month': 'September', 'abbrev': 'Sep'},
@popovichN
popovichN / Election 2016: primary or caucus state?
Last active March 21, 2016 22:08
Which states hold primaries and which ones use a caucus system?
[
{"state_abbrev":"AL","state_name":"Alabama","type_dem":"primary","type_rep":"primary"},
{"state_abbrev":"AK","state_name":"Alaska","type_dem":"caucus","type_rep":"caucus"},
{"state_abbrev":"AZ","state_name":"Arizona","type_dem":"primary","type_rep":"primary"},
{"state_abbrev":"AR","state_name":"Arkansas","type_dem":"primary","type_rep":"primary"},
{"state_abbrev":"CA","state_name":"California","type_dem":"primary","type_rep":"primary"},
{"state_abbrev":"CO","state_name":"Colorado","type_dem":"caucus","type_rep":"caucus"},
{"state_abbrev":"CT","state_name":"Connecticut","type_dem":"primary","type_rep":"primary"},
{"state_abbrev":"DC","state_name":"District of Columbia","type_dem":"primary","type_rep":"convention"},
{"state_abbrev":"DE","state_name":"Delaware","type_dem":"primary","type_rep":"primary"},
@popovichN
popovichN / states lookup
Last active March 17, 2019 16:58
State fips and abbreviations (JSON)
[
{"name":"Alabama","abbrev":"AL","fips":"01"},
{"name":"Alaska","abbrev":"AK","fips":"02"},
{"name":"Arizona","abbrev":"AZ","fips":"04"},
{"name":"Arkansas","abbrev":"AR","fips":"05"},
{"name":"California","abbrev":"CA","fips":"06"},
{"name":"Colorado","abbrev":"CO","fips":"08"},
{"name":"Connecticut","abbrev":"CT","fips":"09"},
{"name":"Delaware","abbrev":"DE","fips":"10"},
{"name":"District of Columbia","abbrev":"DC","fips":"11"},
@popovichN
popovichN / State codes to TopoJSON ids
Created October 28, 2014 18:58
no need to re-write over and over...
var state = function () {
if (foo == "AL"){ return "1"}
if (foo == "AK"){ return "2"}
if (foo == "AZ"){ return "4"}
if (foo == "AR"){ return "5"}
if (foo == "CA"){ return "6"}
if (foo == "CO"){ return "8"}
if (foo == "CT"){ return "9"}
if (foo == "DE"){ return "10"}
if (foo == "FL"){ return "12"}