Skip to content

Instantly share code, notes, and snippets.

View nautilytics's full-sized avatar

Nautilytics nautilytics

View GitHub Profile
@nautilytics
nautilytics / deploy_to_gh_pages.yml
Created September 16, 2020 20:34
Deploy a React application to Github Pages
name: Build and Deploy a React application to GitHub-Pages
on:
push:
branches:
- master
jobs:
build-and-deploy-to-gh-pages:
runs-on: ubuntu-latest
@nautilytics
nautilytics / api-query.js
Last active September 16, 2020 22:21
Using Redis to cache API calls (Node.js)
const rp = require('request-promise');
const { to } = require('await-to-js');
const crypto = require('crypto');
const redisClient = require('./redis-client');
/**
* Execute an API call
* @param {String} uri API URI
* @param {Number} ttl Expiration of cache in seconds
*/
@nautilytics
nautilytics / intersection_queries.sql
Created September 16, 2020 17:42
Intersection queries for zip codes and counties within congressional districts
COPY (
SELECT JSON_AGG(f) FROM (
SELECT s.stusps || '-' || cd.cd116fp AS id, ARRAY_AGG(z.zcta5ce10) AS zip_codes
FROM cb_2018_us_cd116_500k cd
INNER JOIN cb_2018_us_zcta510_500k z
ON ST_Intersects(cd.geom,z.geom)
JOIN cb_2018_us_state_500k s ON cd.statefp = s.statefp
GROUP BY s.stusps || '-' || cd.cd116fp
) f)
TO '/Users/christopherlanoue/Documents/congressional_zip_code_lookup.json';
@nautilytics
nautilytics / index.js
Last active August 19, 2020 16:43
Use Labella for placing labels on a vertical axis
import labella from 'labella';
let points = [];
const force = new labella.Force()
.nodes(points.map((d) => new labella.Node(d.y, 15, d))) // 15 is label height/spacing
.compute();
points = points.map((d) => {
const matchingNode = force.nodes().find((node) => node.data.id === d.id);
return {
...d,
@nautilytics
nautilytics / counties-10m-filtered.json
Last active August 6, 2020 18:01
Filter 10M Topojson Counties to not include American Samoa, USVI, Guam, and Mariana Islands - and remove "nation" and "states" objects
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nautilytics
nautilytics / mapshaper.txt
Last active August 6, 2020 17:51
Filter 10M Topojson States to not include Alaska, Hawaii, American Samoa, USVI, Guam, and Mariana Islands, and Puerto Rico - and remove "nation" object
# Remove Alaska (02), Hawaii (15), Puerto Rico (72), American Samoa (60), United States Virgin Islands (78), Guam (66), and Commonwealth of the Northern Mariana Islands (69)
filter 'FID != "02"'
// [filter] Retained 55 of 56 features
filter 'FID != "15"'
// [filter] Retained 54 of 55 features
filter 'FID != "72"'
// [filter] Retained 53 of 54 features
$ filter 'FID != "60"'
[filter] Retained 52 of 53 features
@nautilytics
nautilytics / index.sh
Last active July 28, 2020 16:46
Retrieve place names with population (.e00) and put into a Postgres database
# Retrieve data from https://water.usgs.gov/GIS/metadata/usgswrd/XML/places.xml#stdorder
# curl https://water.usgs.gov/GIS/dsdl/places.e00.gz
# put the data into "Web Mercator" projection
PRJ="EPSG:4326"
DB=gis_db
# The original files were coverages, so I have to know something about
# what I want to transfer. For example for this file I want only LAB
# ogrinfo places.e00
@nautilytics
nautilytics / README.md
Last active October 26, 2020 21:15
An automated approach to retrieving Census Place shape-files for every state and inserting into a Postgres database

Census Tracts - Clipped by State

Screen Shot 2020-10-26 at 5 12 21 PM

Census Tracts - Extending to Ocean

@nautilytics
nautilytics / index.jsx
Created May 15, 2020 01:14
An example of using an SVG mask to effectively handle mousing over an area chart
import React from 'react';
import {area as d3_area, curveBasis} from 'd3-shape';
const AreaChart = ({data, xScale, yScale, selectedItem, setSelectedItem, barWidth = 0}) => {
// Set up an area chart generator
const area = d3_area()
.curve(curveBasis)
.x(d => d.x)
.y0(d => d.y0)
@nautilytics
nautilytics / intersection-query.sql
Last active April 14, 2020 19:02
Retrieve a FeatureCollection of affected counties joined with wind speed data for Hurricane Sandy
SELECT ROW_TO_JSON(fc) AS json_out FROM (
SELECT 'FeatureCollection' AS type,
ARRAY_TO_JSON(ARRAY_AGG(f)) AS features
FROM (
SELECT 'Feature' AS type,
ST_AsGeoJSON(c.geom)::json AS geometry,
ROW_TO_JSON((
SELECT l FROM (
SELECT r.radii,
r.synoptime,