Skip to content

Instantly share code, notes, and snippets.

@Jon20111
Jon20111 / DropElse
Created May 1, 2020 21:23
DropElse
const jobDescription = (language, jobRoll) => {
if(language === 'javascript' && jobRoll === 'developer'){
return 'Cool Cat';
}
return 'Hot Dog';
}
@Jon20111
Jon20111 / us-topojson-rotate-translate.tsx
Created April 24, 2020 16:37
Rotate and translate points with d3 on a TopoJSON map
import React, { FC, useLayoutEffect, useCallback } from 'react';
import * as d3 from 'd3';
import * as topojson from 'topojson';
import * as statesMap from '../../data/states-albers-10m.json';
import * as cities from '../../data/us-cities.json';
export const USMapRotate: FC = () => {
const projection = d3.geoAlbersUsa().scale(1300).translate([487.5, 305])
const path = d3.geoPath();
@Jon20111
Jon20111 / beginning-map.txt
Last active April 24, 2020 16:38
Beginning component used to add in transitions.
import React, { FC, useLayoutEffect, useCallback } from 'react';
import * as d3 from 'd3';
import * as topojson from 'topojson';
import * as statesMap from '../../data/states-albers-10m.json';
import * as cities from '../../data/us-cities.json';
export const USMapRotate: FC = () => {
const projection = d3.geoAlbersUsa().scale(1300).translate([487.5, 305])
const path = d3.geoPath();
@Jon20111
Jon20111 / us-topojson-with-transitions
Created April 23, 2020 17:50
This gist creates a map component that draws a map of the US and then transitions the US capitals onto the map in a pleasing way.
// @ts-nocheck
import React, { FC, useLayoutEffect, useCallback } from 'react';
import * as d3 from 'd3';
import * as topojson from 'topojson';
import * as statesMap from '../data/states-albers-10m.json';
import * as cities from '../data/us-cities.json';
export const USMap: FC = () => {
const projection = d3.geoAlbersUsa().scale(1300).translate([487.5, 305])
@Jon20111
Jon20111 / utility.tsx
Created April 17, 2020 21:45
Convert 2-Dimension Array to Object
export const twoDimArrayToObject = function(array: string[][]) {
const returnObject: {
[key: string]: string
} = {};
array.forEach((element) => {
returnObject[element[0]] = element[1];
})
return returnObject;
}