Skip to content

Instantly share code, notes, and snippets.

@brianfoody
brianfoody / Slicing Pizza
Last active May 30, 2020 03:46
Slicing Pizza
{times(3).map(i => (
<Line
key={`crosshair_${i}`}
x1={calculateEdgePoint(i * 60)[0]}
y1={calculateEdgePoint(i * 60)[1]}
x2={calculateEdgePoint(i * 60 + 180)[0]}
y2={calculateEdgePoint(i * 60 + 180)[1]}
stroke="black"
strokeOpacity="0.2"
strokeWidth="0.5"
const radarData = [
{ label: "Acceleration", value: 86 },
{ label: "Agility", value: 58 },
{ label: "Clutch", value: 60 },
{ label: "Speed", value: 85 },
{ label: "Stamina", value: 60 },
{ label: "Strength", value: 90 }
];
const calculateEdgePointFn = (center: number, radius: number) => (
degree: number,
scale: number = 1
): Point => {
const degreeInRadians = degToRadians(degree);
const degreeInRadiansY = degToRadians(svgY(degree));
return [
center + Math.cos(degreeInRadians) * radius * scale,
center + Math.sin(degreeInRadiansY) * radius * scale
];
@brianfoody
brianfoody / Polygon Radar Chart
Last active May 30, 2020 03:30
Polygon Radar Chart
<Polygon
stroke={"#50E2C2"}
strokeWidth={1.2}
fill={"#50E2C2"}
fillOpacity={0.9}
points={`${radarData.map((r, i) => {
const edgePoint = calculateEdgePoint(i * 60, r.value / 100);
return `${edgePoint[0]},${edgePoint[1]}`;
})}`}
/>
@brianfoody
brianfoody / SvgRadarChart.tsx
Last active August 24, 2023 08:23
SVG Radar Chart in React Native
import React, { useMemo } from "react";
import { View } from "react-native";
import { degToRadians } from "src/components/OrbitLogo";
import Svg, { Circle, Line, Polygon } from "react-native-svg";
import times from "lodash.times";
type RadarData = {
value: number;
label: string;
};
@brianfoody
brianfoody / fnc.py
Last active June 17, 2020 12:46
Python Typing
import dataclasses as dc
from typing import List
import fnc
@dc.dataclass(frozen=True)
class User:
id: float
name: str
email: str
@brianfoody
brianfoody / fnc2.py
Created June 17, 2020 12:43
"Spread" Syntax - assign dataclass to new variable and update
import dataclasses as dc
from typing import List
@dc.dataclass(frozen=True)
class User:
id: float
name: str
email: str
active: bool
@brianfoody
brianfoody / lambda_handler.py
Last active June 25, 2020 01:22
Pydantic Lambda Validation
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, validator
from random import randint
from typing import List
from re import search
"""
Add this to your mypy.ini
@brianfoody
brianfoody / Cognito.ts
Created June 28, 2020 10:42
Cognito Mapping
const smsNotificationZones = {
"eu-central-1": "eu-west-1",
"eu-west-1": "eu-west-1",
};
@brianfoody
brianfoody / async_play.py
Last active July 8, 2020 02:35
Typed Asynchronous Python
from influxdb import InfluxDBClient
from influxdb.resultset import ResultSet
import pandas as pd
from typing import Any, List, Optional
import os
client: InfluxDBClient