Skip to content

Instantly share code, notes, and snippets.

@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;
}
@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 / 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-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 / 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 / material-ui-override.tsx
Created May 22, 2020 18:34
A demonstration of how to override the default Material UI component style using useStyles
import React, { FC, useMemo } from 'react';
import { TextField, withStyles } from '@material-ui/core';
import { useStyles } from './form.styles';
export const Form: FC = () => {
const classes = useStyles();
const StyledTextField = useMemo(
() => {
return withStyles({
root: {
@Jon20111
Jon20111 / material-table-wrapper.tsx
Created July 17, 2020 15:41
Material-Table example
import React, { FC, useState } from "react";
import MaterialTable from "material-table";
import DeleteIcon from "@material-ui/icons/Delete";
import SearchIcon from "@material-ui/icons/Search";
import SaveIcon from "@material-ui/icons/Save";
import { Button } from "@material-ui/core";
import { useStyles } from './material-table-wrapper.styles';
interface Column {
@Jon20111
Jon20111 / basic material-table
Created July 18, 2020 01:23
basic material-table
import React, { useState } from "react";
import "./styles.css";
import MaterialTable from "material-table";
export default function App() {
const [data, setData] = useState([
{ name: "Jon", job: "Software Dev", age: 29 }
]);
return (
<div className="App">
<h1>Material-Table Demo</h1>
actions={[
{
icon: () => <SaveIcon />,
tooltip: "Save User",
onClick: (event, rowData) => alert("You saved " + rowData.name)
}
]}
components={{
Action: props => (
<Button
onClick={event => props.action.onClick(event, props.data)}
color="primary" variant="text"
style={{ textTransform: "none" }}
size="small"
>
Save
</Button>