Skip to content

Instantly share code, notes, and snippets.

chriswhong / config.js
Created December 1, 2022 23:11
Mapbox Scrollytelling Example with Linestring Animation
window.testCallback = () => {
let startTime;
const duration = 10000;
const frame = (time) => {
if (!startTime) startTime = time;
const animationPhase = (time - startTime) / duration;
// Reduce the visible length of the line by using a line-gradient to cutoff the line
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
chriswhong / intakeq-bulk-download.js
Last active March 22, 2022 14:30
Iterates over the list of intakes in IntakeQ web UI, downloading each as a PDF.
// Bulk download of IntakeQ forms
// This script will iterate over the list of intakes in IntakeQ, downloading
// each as a PDF. It also pulls the customer's name from the list and uses it
// to create the filename
// this script does not paginate. To use navigate to a list of intakes, open
// developer tools, paste into the console, press enter
// if you have more than one page, manually navigate to the next page and repeat
// select all table row elements
chriswhong /
Created July 7, 2021 20:57
qri transform for storing mta elevator statuses
load("encoding/", "csv")
load("encoding/", "json")
load("", "http")
def download(ctx):
# send an http get request to the elevator outages page
raw = http.get('').body()
data = json.loads(raw)
stations = data['Stations']
chriswhong / gist:ff86b482273ce20cc8dc2391a6b30c4c
Created May 11, 2020 16:47
Pulling a Qri versioned dataset from the distributed web into a pandas dataframe (python)
# an example of pulling in a CSV string from a local qri repo,
# and parsing it into a dataframe with pandas.read_csv()
import pandas as pd
import subprocess
from io import StringIO
# this Qri class should eventually have all the methods we would need for reading,
# writing, pushing, pulling, committing, etc.
class Qri:
chriswhong / gist:93ed4660ff23fdf483b41654290f0b18
Created April 7, 2020 17:57
Socrata Download URL generates different files when accessed multiple times
## Problem
When troubleshooting another bug at, we noticed that hitting the same download URL from the NYC Open Data portal (powered by Socrata) generated csv files with different md5 hashes. This was causing our version control software to consider the csv "changed". On further investigation, the actual data was the same, but the ordering of the rows was different. This is likely due to the fact that the files are being generated on the fly from a database query (PostgreSQL in the case of Socrata open data portals) returning unpredictable row orders when no `ORDER BY` is specified in the query.
To reproduce:
- curl the same download URL several times and save to csv, such as this one for popular baby names:
$curl > 0.csv
$curl > 1.csv
chriswhong / convert csv with WKT to GeoJson
Last active March 5, 2020 13:19
How to parse a CSV with a well-known text geometry column and convert to geojson FeatureCollection with the 'wellknown' package
// Use papa parse to download and parse a CSV
Papa.parse('data/nyc_zoning_lots.csv', {
download: true,
header: true,
complete: ({ data }) => {
// transform array of objects to geojson FeatureCollection
const FC = {
type: 'FeatureCollection',
features: => { // map csv rows to geojson features
const geometry = wellknown.parse(row.geom) // WKT to geojson geometry
chriswhong /
Created February 28, 2020 17:55
Using ogr2ogr to load a CSV into Postgres

The absolute easiest way to get a CSV into a postgresql table is to use ogr2ogr with AUTODETECT_TYPE=YES.

I learned a while back that this is what cartoDB uses to import your CSV into postgis (with a lot of other parameters added)

ogr2ogr -f PostgreSQL PG:"host=localhost user=postgres dbname=postgres password=password"  docs.csv -oo AUTODETECT_TYPE=YES
chriswhong / Qmf6Vfs78CeKHsWus2gXjBkvha93acBXN3FB7DtEFha4oj.csv
Created January 23, 2020 14:57
NYC Plaza Program Sites from Qri Dataset chriswhong/nyc_plaza_program_sites@/ipfs/Qmf6Vfs78CeKHsWus2gXjBkvha93acBXN3FB7DtEFha4oj.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 13 columns, instead of 9. in line 4.
Albee Square Plaza,BK02,,C,25200,Dekalb Ave,Bond Street,Fulton Mall,Fulton Mall Improvement Association,,-73.983171,40.689973,
Ave C Plaza,BK12,,D,5600,McDonald Ave,Avenue C,Church Ave,Kensington Stewards,,-73.979094,40.640571,
Brooklyn Plaza,BK02,,B,50000,Jay Street,High Street,Manhattan Bridge,DOT,,-73.986569,40.699203,
Cadman Plaza East,BK02,,,,Cadman Plaza East,Tillary St,Johnson St,Down