Skip to content

Instantly share code, notes, and snippets.

Dan Vanderkam danvk

Block or report user

Report or block danvk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danvk
danvk / gql.py
Created Feb 28, 2019
Pretty-print GeoJSON in a slightly more compact way by putting coordinates on one line.
View gql.py
#!/usr/bin/env python3
"""Pretty-print GeoJSON in a slightly more compact way by putting coordinates on one line.
Compare:
[
[
37.23423,
79.23423
],
View example5-inferkeys.tsx
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: {
View example5-inferpick.ts
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"
});
View example5-pick.ts
const INIT_VIEW: Pick<MapProps, 'center'|'zoom'|'pitch'|'bearing'|'style'> = {
center: [-73.991284, 40.741263],
zoom: [14.5],
pitch: [45],
bearing: [-17.6],
style: "mapbox://styles/mapbox/streets-v9"
};
View example5-partial.tsx
const INIT_VIEW: Partial<Props> = {
center: [-73.991284, 40.741263],
zoom: [14.5],
pitch: [45],
bearing: [-17.6],
};
export function render(): JSX.Element {
return (
<Map
View example5-props.ts
export interface Props {
 style: string | MapboxGl.Style;
 center?: [number, number];
 zoom?: [number];
 maxBounds?: MapboxGl.LngLatBounds | FitBounds;
 fitBounds?: FitBounds;
 fitBoundsOptions?: FitBoundsOptions;
 bearing?: [number];
 pitch?: [number];
 containerStyle?: React.CSSProperties;
View example5.tsx
import * as React from 'react';
import ReactMapboxGl from 'react-mapbox-gl';
const Map = ReactMapboxGl({
accessToken: '....',
});
export function render(): JSX.Element {
return (
<Map
View example4-interface.ts
interface Order {
 what: Product;
 how: 'bitcoin' | 'usd';
}
const order: Order = {
 what: 'Macbook Air',
 how: 'bitcoin'
};
purchase(order.what); // ok
View example4-typecast.ts
const order = {
  what: 'Macbook Air' as Product, // or "as 'MacbookAir'"
  how: 'bitcoin'
};
purchase(order.what); // ok
View ex3.js
const order = {
 what: 'Macbook Air',
 how: 'bitcoin'
};
order.what = 'Lenovo'; // valid
You can’t perform that action at this time.