Skip to content

Instantly share code, notes, and snippets.

View danvk's full-sized avatar

Dan Vanderkam danvk

View GitHub Profile
@danvk
danvk / results.json
Created February 9, 2020 15:58
Top GitHub repos by stars
{
"search": {
"repositoryCount": 704279,
"edges": [
{ "node": { "nameWithOwner": "freeCodeCamp/freeCodeCamp", "stargazers": { "totalCount": 308427 } } },
{ "node": { "nameWithOwner": "996icu/996.ICU", "stargazers": { "totalCount": 249062 } } },
{ "node": { "nameWithOwner": "vuejs/vue", "stargazers": { "totalCount": 156364 } } },
{ "node": { "nameWithOwner": "facebook/react", "stargazers": { "totalCount": 143121 } } },
{ "node": { "nameWithOwner": "tensorflow/tensorflow", "stargazers": { "totalCount": 140562 } } },
{ "node": { "nameWithOwner": "twbs/bootstrap", "stargazers": { "totalCount": 138369 } } },
@danvk
danvk / repos-with-stars.graphql
Created February 9, 2020 15:56
Getting a list of repos with starcount from GitHub
query {
search(query: "is:public stars:>15", type: REPOSITORY, first:100) {
repositoryCount
edges {
node {
... on Repository {
nameWithOwner
stargazers {
totalCount
}
def make_angle_map(station_loc, asteroids):
d = defaultdict(list)
x, y = station_loc
for a in asteroids:
ax, ay = a
angle = math.atan2(y - ay, ax - x)
d2 = (x - ax) ** 2 + (y - ay) ** 2
d[angle].append((d2, a))
for angle, pairs in d.items():
d[angle] = [*sorted(pairs)]
@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 / .gitignore
Last active April 14, 2020 14:32
Repro of texture issue for MapboxGL and THREE.js
token.js
@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 / dom-errors.ts
Created September 25, 2019 15:45
Errors surfaced in DOM code (for Effective TypeScript)
function handleDrag(eDown: Event) {
const targetEl = eDown.currentTarget;
targetEl.classList.add('dragging');
// ~~~~~~~ Object is possibly 'null'.
// ~~~~~~~~~ Property 'classList' does not exist on type 'EventTarget'.
const dragStart = [
eDown.clientX, eDown.clientY
// ~~~~~~~ 'clientX' does not exist on 'Event'.
// ~~~~~~~ 'clientY' does not exist on 'Event'.
];
@danvk
danvk / gql.py
Created February 28, 2019 21:08
Pretty-print GeoJSON in a slightly more compact way by putting coordinates on one line.
#!/usr/bin/env python3
"""Pretty-print GeoJSON in a slightly more compact way by putting coordinates on one line.
Compare:
[
[
37.23423,
79.23423
],
const inferKeys = <V extends {}>() => <K extends string>(x: Record<K,V>): Record<K,V> => x;
const INIT_VIEW = inferKeys<Partial<MapProps>>()({
nyc: {
center: [-73.991284, 40.741263],
zoom: [14.5],
pitch: [45],
bearing: [-17.6],
},
sf: {
const inferPick = <V extends {}>() => <K extends keyof V>(x: Pick<V, K>): Pick<V, K> => x;
const INIT_VIEW = inferPick<MapProps>()({
center: [-73.991284, 40.741263],
zoom: [14.5],
pitch: [45],
bearing: [-17.6],
style: "mapbox://styles/mapbox/streets-v9"
});