Skip to content

Instantly share code, notes, and snippets.

View nautilytics's full-sized avatar

Nautilytics nautilytics

View GitHub Profile
@nautilytics
nautilytics / import.sh
Last active April 10, 2020 16:42
Download and import Hurricane Sandy and US County shapefiles into a PostGIS database using shp2pgsql
#!/bin/bash
# Add US County data to Postgis w/ GIST index
curl https://www2.census.gov/geo/tiger/TIGER2019/COUNTY/tl_2019_us_county.zip --output tl_2019_us_county.zip
mkdir tl_2019_us_county
unzip tl_2019_us_county.zip -d tl_2019_us_county
shp2pgsql tl_2019_us_county/tl_2019_us_county.shp tl_2019_us_county | psql -d gis_db
psql -d gis_db -c "CREATE INDEX tl_2019_us_county_geom_gix ON tl_2019_us_county USING GIST (geom)"
# Add Hurricane Sandy Radii data to Postgis w/ GIST index
@nautilytics
nautilytics / create.sh
Created April 10, 2020 14:10
Create a PostGIS enabled PostgreSQL database
#!/bin/bash
createdb gis_db
psql -d gis_db -c "CREATE EXTENSION postgis"
@nautilytics
nautilytics / create.sh
Created March 31, 2020 13:15
Instructions for getting Hurricane Sandy and US County shapefiles into a PostGIS database to identify affected counties
#!/bin/bash
createdb gis_db
psql -d gis_db -c "CREATE EXTENSION postgis"
@nautilytics
nautilytics / EventController.apxc
Last active March 13, 2020 15:06
Example files for the creation of a React + d3.js application in a Salesforce Sandbox instance
global with sharing class EventController {
public String accountId {get; set;}
public EventController() {}
@RemoteAction
global static List<Event> findEvents(String accountId) {
return [SELECT Type, CreatedDate, Id from Events WHERE WhoId =:accountId];
}
@nautilytics
nautilytics / deploy_staging.yml
Created February 17, 2020 01:49
A Github action for deploying the UK Political Atlas to S3 after a merged pull request
name: Deploy Staging Branch
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
@nautilytics
nautilytics / UK.json
Last active January 12, 2021 17:05
A GeoJSON to PNG converter using D3 for Node
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nautilytics
nautilytics / area-chart-mask.html
Created January 29, 2020 21:48
An SVG Mask for interactive mouse events on an area chart
<svg width="100%" height="100%">
<defs>
<mask
id='mask-for-area-chart'
maskUnits="userSpaceOnUse"
maskContentUnits="userSpaceOnUse">
<path d="M0Z" style="fill: white;">
</path>
</g>
</mask>
@nautilytics
nautilytics / d3-force-layout.js
Created January 21, 2020 18:45
Using d3-force simulation to place points
const calculateLayout = (items, spacing = 0.01) => {
// Calculate a force directed placement for each point
const MAX_STEPS = 300,
STRENGTH = 10,
ALPHA = 0.3;
if (!items.length) return [];
const getY = d => d.y;
const getX = d => d.x;
@nautilytics
nautilytics / d3-quadtree-search.js
Last active January 21, 2020 18:41
A quadtree recursively partitions two-dimensional space into squares, dividing each square into four equally-sized squares.
import {quadtree as d3_quadtree} from "d3-quadtree";
import {search} from "search.js";
// ...
// Create cluster points, i.e. an array of:
// [[cluster_x, cluster_y, [points_to_cluster], ...]
const nodes = [[0, 0, {id: 1, r: 10, name: "node-1"}], [10, 10, {id: 2, r: 10, name: "node-2"}]];
const clusterRange = 80;
const quadtree = d3_quadtree().addAll(nodes);
@nautilytics
nautilytics / d3-transition-angular.html
Created January 2, 2020 16:00
Using d3.transition with Angular
<svg:circle [attr.r.px]="item.r"
[ngClass]="'marker'"
[appSvgTransition]="transition"
[d3-attr]="{cx: item.x, cy: item.y}">
</svg:circle>