Skip to content

Instantly share code, notes, and snippets.

View clhenrick's full-sized avatar

Chris Henrick clhenrick

View GitHub Profile
@clhenrick
clhenrick / async-task-handler-generic.ts
Created January 30, 2024 18:57
Example of using a TypeScript generic type in a function's parameter and return type
// MyType is a generic that we can pass different types when calling handleAsyncTask()
const handleAsyncTask = async function<MyType> (asyncFn: () => Promise<MyType | string>) : Promise<[boolean, MyType | undefined]> {
const result = await asyncFn();
if (typeof result === 'string') {
return [true, undefined];
}
return [false, result];
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@clhenrick
clhenrick / to-title-case.js
Created June 28, 2022 21:38
JS function to convert strings to title case and ignore certain reserved words such as "a", "an", etc.
function toTitleCase(string) {
const convertTitleCase = (str) => `${str.charAt(0)}${str.toLowerCase().slice(1)}`
const reservedWords = new Set(["a", "an", "at", "in"]);
return string
.split(" ")
.map((s) => {
if (reservedWords.has(s)) {
return s.toLowerCase();
}
return convertTitleCase(s);
#!/bin/bash
set -e
# dependencies:
# - youtube-dl: https://ytdl-org.github.io/youtube-dl/
# - ffmpeg: https://ffmpeg.org/
# make sure youtube-dl dep exists
if ! command -v youtube-dl &> /dev/null
then
@clhenrick
clhenrick / Fips.ts
Created January 7, 2021 23:13
TypeScript class for handling FIPS codes from U.S. Census data; code credit: @kkatzen, @aaronsn
// Code Credit: @kkatzen, @aaronsn
// https://github.com/SatcherInstitute/health-equity-tracker/blob/master/frontend/src/utils/madlib/Fips.ts
export const USA_DISPLAY_NAME = "the United States";
// Fake FIPS code used to represent totals in USA for convenience
export const USA_FIPS = "00";
class Fips {
code: string;
@clhenrick
clhenrick / script.js
Last active October 23, 2020 15:26
Persisting the removal of annoying stuff from web pages
// In Chrome devtools, create live expressions for each of these code blocks
// https://developers.google.com/web/tools/chrome-devtools/console/live-expressions
// Now when you visit a page, no more annoying thing that will bother you!
// The annoying thing contains this text
const textToSearchFor = "foo"
// Filtering by searching for the above text here but you could filter other ways too
function filterFn(node) {
return node.textContent.includes(textToSearchFor);
@clhenrick
clhenrick / nyc_421a.sql
Last active December 26, 2019 20:29
Create table statement for NYC properties with 421a tax exemption status, using data from https://github.com/toolness/nyc-421a-xls
DROP TABLE IF EXISTS nyc_421a;
CREATE TABLE nyc_421a (
years numeric,
borough_name varchar,
borough numeric,
neighborhood varchar,
building_class_category varchar,
tax_class_at_present varchar,
block numeric,
@clhenrick
clhenrick / get_assembly_districts.sh
Created December 3, 2019 02:15
California Assembly Districts GeoJSON using ogr2ogr
#!/usr/bin/env bash
URI="https://services1.arcgis.com/sTaVXkn06Nqew9yU/ArcGIS/rest/services/Political_Boundaries_Feb2016/FeatureServer/1/query?&outfields=*&f=geojson&where=objectid%20is%20not%20null"
ogr2ogr -f GeoJSON ca_assembly_districts.json $URI OGRGeoJSON
@clhenrick
clhenrick / .block
Created May 8, 2019 22:04
D3 Scatterplot without data join
license: mit
@clhenrick
clhenrick / .block
Created May 7, 2019 23:19
Simple Scatterplot with d3@5
license: mit