Skip to content

Instantly share code, notes, and snippets.

View jose-mdz's full-sized avatar

Jose Menendez jose-mdz

View GitHub Profile
@jose-mdz
jose-mdz / Component.tsx
Last active February 1, 2024 01:22
Use Tailwind Screen config in code
import resolveConfig from "tailwindcss/resolveConfig";
import tailwindConfig from "../../tailwind.config";
function Component() {
const fullConfig = resolveConfig(tailwindConfig);
const [horizontal, setHorizontal] = useState<boolean>(
screen && screen.availWidth >= parseInt(fullConfig.theme.screens.sm),
);
// Do something with decision
@jose-mdz
jose-mdz / checker.ts
Last active June 20, 2023 21:34
EvenOdd Checker Background
type ColorTuple = [number, number, number, number];
type BitmapData = [Uint8ClampedArray, number];
interface CheckerPatternParams {
tileSize: number;
colorA: ColorTuple;
colorB: ColorTuple;
}
@jose-mdz
jose-mdz / roundedRect.ts
Created October 13, 2022 18:26
Rounded Rectangle
export function roundRect(
context: CanvasRenderingContext2D,
rectangle: Rectangle,
radius: number | {tl?: number, tr?: number, br?: number, bl?: number} = 5,
fill: boolean,
stroke = false,
) {
const [x, y, width, height] = rectangle.tuple;
const rad = typeof radius === 'number' ?
{tl: radius, tr: radius, br: radius, bl: radius} :
@jose-mdz
jose-mdz / rows_cols.ts
Created October 11, 2022 18:04
Rows & Cols
const getIndex = (row: number, col: number, width: number) => width * row + col;
const getRowCol = (index: number, width: number) => [Math.floor(index / width), index % width];
@jose-mdz
jose-mdz / README.md
Last active October 12, 2024 23:08
Orthogonal Diagram Connector

Orthogonal Connectors

This algorithm returns the points that form an orthogonal path between two rectangles.

How to Use

// Define shapes
const shapeA = {left: 50,  top: 50, width: 100, height: 100};
const shapeB = {left: 200, top: 200, width: 50, height: 100};
@jose-mdz
jose-mdz / README.md
Last active June 23, 2024 08:04
Draw round corners path in JavaScript

Round Corner Path

[x] Tested

Usage

const canvas = document.getElementById('myCanvas');
const context = canvas.getContext('2d');
const points = [
 {x: 100, y: 100},

Infra Test

WIP