Skip to content

Instantly share code, notes, and snippets.

View ylyra's full-sized avatar
:shipit:
Working from home

Yan Lyra ylyra

:shipit:
Working from home
View GitHub Profile
@ylyra
ylyra / lucide-react.d.ts
Created April 30, 2025 13:24 — forked from dillionverma/lucide-react.d.ts
How to stop @radix-ui, next/router and lucide-react auto-imports
declare module 'lucide-react' {
export * from 'lucide-react/dist/lucide-react.suffixed'
}
@ylyra
ylyra / try-catch.ts
Created March 25, 2025 22:31 — forked from t3dotgg/try-catch.ts
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
useEffect(() => {
let previousUrl = ''
const observer = new MutationObserver((mutations) => {
if (window.location.href !== previousUrl) {
previousUrl = window.location.href
console.log(
`URL changed from ${previousUrl} to ${window.location.href}`,
)
}
})
@ylyra
ylyra / DOM3D.js
Created March 27, 2024 12:40 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@ylyra
ylyra / forward-ref.tsx
Created October 31, 2023 21:29
Polymorphic forward-ref
import React from "react";
type As<P = any> = React.ElementType<P>;
type PropsOf<C extends As> = React.ComponentProps<C>;
type RightJoin<C extends {}, P extends {}> = Omit<C, keyof P> & P;
type Props<C> = C extends ForwardRefComponent<any, infer P> ? P : {};
type IntrinsicElement<C> = C extends ForwardRefComponent<infer I, any>
? I
declare type As<P = any> = React.ElementType<P>;
declare type PropsOf<C extends As> = React.ComponentProps<C>;
declare type RightJoin<C extends {}, P extends {}> = Omit<C, keyof P> & P;
declare type Props<C> = C extends ForwardRefComponent<any, infer P> ? P : {};
declare type IntrinsicElement<C> = C extends ForwardRefComponent<infer I, any>
? I
: never;
@ylyra
ylyra / readme.md
Last active September 29, 2023 18:09

@ylyra
ylyra / test.ts
Last active September 29, 2023 15:53
const getTheValueForKey = <TObj extends Record<string, unknown>, TKey extends keyof TObj>(
obj: TObj,
objKey: TKey
) => {
return obj[objKey]
}
const keyForFirst = getTheValueForKey({
a: 1,
b: '2',
{
"editor.acceptSuggestionOnCommitCharacter": false,
"editor.accessibilitySupport": "off",
"editor.cursorBlinking": "smooth",
"editor.cursorSmoothCaretAnimation": "on",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.addMissingImports": "explicit",
"source.organizeImports": "explicit"
},
import { FlatList, Text, View } from "react-native";
const listOne = [
{
id: 1,
name: "John",
},
];
const listTwo = [