Skip to content

Instantly share code, notes, and snippets.

View danvk's full-sized avatar

Dan Vanderkam danvk

View GitHub Profile
@danvk
danvk / sprite-custom-layer.tsx
Created October 1, 2019 18:00
Mapbox custom layer which renders multiple models in a THREE.js scene
import MapboxGL, {LngLatLike, MercatorCoordinate} from 'mapbox-gl';
import React, {useEffect, useState} from 'react';
import {withMap} from 'react-mapbox-gl/lib-esm/context';
import {FeatureCollection} from 'geojson';
import * as THREE from 'three';
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader';
export interface SpritePaint {
gltfPath: string;
@danvk
danvk / index.html
Created March 30, 2018 14:22
Mapbox GL JS update with joined JSON
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Update a choropleth layer by zoom level</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.js'></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
@danvk
danvk / parser.test.ts
Created December 6, 2023 03:13
Lisp Parser
import { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts";
import { parseLisp, tokenize } from "./parser.ts";
Deno.test("tokenizer", () => {
const input = "(first (list 1 (+ 2 3) 9))";
assertEquals(
[...tokenize(input)],
["(", "first", "(", "list", 1, "(", "+", 2, 3, ")", 9, ")", ")"],
);
@danvk
danvk / README.md
Created June 20, 2022 23:03
Pruning a transitive type dependency for TypeScript

Pruning a transitive type dependency for TypeScript

See [Stack Overflow: How can I completely hide an irrelevant directory of type declarations from TypeScript?][1].

This is mostly interesting as a template for using paths to prune the set of files considered by tsc when building a project.

Solution tsconfig.json:

{
@danvk
danvk / tsp.geojson
Created June 1, 2023 00:17
An optimal route through the Catskills 3500 High Peaks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danvk
danvk / expression.test.ts
Created October 28, 2019 15:33
TypeScript API for Mapbox GL Style Expressions
import {Expression} from './expression';
describe('Expression', () => {
it('should work with constants', () => {
expect(Expression.parse(0).evaluate(null!)).toEqual(0);
expect(Expression.parse(10).evaluate(null!)).toEqual(10);
});
it('should add', () => {
expect(Expression.parse(['+', 1, 2]).evaluate(null!)).toEqual(3);
});
@danvk
danvk / slide.gpx
Created February 19, 2023 15:55
Winter Hike on Slide (Does GitHub support GPX?)
<?xml version="1.0"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1" creator="AllTrails.com" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<name><![CDATA[Slide Mountain Winter Hike]]></name>
<desc><![CDATA[Sunny day for a winter hike. The trail was quite icy on the way up and we were happy to have our spikes. By the time we came down enough ice had melted that we took them off.]]></desc>
<link href="http://www.alltrails.com">
<text>AllTrails, LLC</text>
</link>
<bounds minlat="41.99887" minlon="-74.42762" maxlat="42.00864" maxlon="-74.38516"/>
</metadata>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danvk
danvk / README.md
Created February 23, 2021 14:47
type-coverage repro

Type Coverage Repro

See plantain-00/type-coverage#83

$ yarn type-coverage --detail --ignore-catch --ignore-unread -p tsconfig.json
yarn run v1.22.4
$ /Users/danvk/code/type-coverage-toy/node_modules/.bin/type-coverage --detail --ignore-catch --ignore-unread -p tsconfig.json
6 / 6 100.00%
type-coverage success.

✨ Done in 0.94s.

@danvk
danvk / index.d.ts
Created February 20, 2021 20:38
Reviving the old @types/dygraphs tests
// Type definitions for dygraphs 2.1
// Project: http://dygraphs.com
// Definitions by: Dan Vanderkam <https://github.com/danvk>
// Martin Badin <https://github.com/martin-badin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="google.visualization" />
declare namespace dygraphs {
type DataArray = Array<Array<number | Date | null>>;