Skip to content

Instantly share code, notes, and snippets.

View 8mist's full-sized avatar
🛹

8mist 8mist

🛹
  • Staays
View GitHub Profile
import {
forwardRef,
useCallback,
type ComponentPropsWithoutRef,
type ElementRef,
type MouseEventHandler,
} from 'react';
const PropagationStopper = forwardRef<ElementRef<'div'>, ComponentPropsWithoutRef<'div'>>(
({ children, ...props }, forwardedRef) => {
@8mist
8mist / smooth-scroll.js
Last active January 23, 2024 12:44
Natif smooth scroll
const lerp = (a, b, n) => (1 - n) * a + n * b;
class SmoothScroll {
constructor() {
this.DOM = {
main: document.querySelector('main'),
wrapper: document.querySelector('.site-container')
};
if (!this.DOM.main) throw new Error('Please provide a main element.');
@8mist
8mist / php-switch.sh
Created November 20, 2023 09:10
This script allows switching between different PHP versions on macOS using Homebrew.
#!/bin/bash
# This script allows switching between different PHP versions on macOS using Homebrew.
# Version 1.0.0
# Copyright (c) Grégoire Ciles
# Usage: ./switch-php.sh <version_number> (e.g., ./switch-php.sh 8.1)
function error() {
echo "Error: $1"
exit 1
@8mist
8mist / four_squares.js
Last active March 22, 2024 17:48
[1kyu] Codewars - Express number as sum of four squares
const ROBUST_TEST_SET = [
[2047n, [2n]],
[1373653n, [2n, 3n]],
[9080191n, [31n, 73n]],
[25326001n, [2n, 3n, 5n]],
[3215031751n, [2n, 3n, 5n, 7n]],
[4759123141n, [2n, 7n, 61n]],
[1122004669633n, [2n, 13n, 23n, 1662803n]],
[2152302898747n, [2n, 3n, 5n, 7n, 11n]],
[3474749660383n, [2n, 3n, 5n, 7n, 11n, 13n]],
const fs = require('node:fs')
const path = require('node:path')
const BUFFER_ENCODING = 'utf8'
const getFilePath = (filename) => path.resolve(__dirname, filename)
const format = (filename) => {
return fs
.readFileSync(getFilePath(filename), BUFFER_ENCODING)
const debounceToNextFrame = <F extends (...args: any[]) => void>(
fn: F,
): ((...funcArgs: Parameters<F>) => void) & {
cancel: () => void;
} => {
let frameReference: number;
const cancel = (): void => {
cancelAnimationFrame(frameReference);
};
@8mist
8mist / fragment.glsl
Created July 19, 2023 13:08
Create border-radius like CSS in Shader
precision highp float;
uniform float u_alpha;
uniform sampler2D t_map;
varying vec2 v_uv;
float fn_border_radius(vec2 position, vec2 half_size, float corner_radius) {
position = abs(position) - half_size + corner_radius;
return length(max(position, 0.)) + min(max(position.x, position.y), 0.) - corner_radius;
import React from 'react'
const IS_SERVER = typeof window === 'undefined'
export const useIsomorphicLayoutEffect = IS_SERVER
? React.useEffect
: React.useLayoutEffect
import { useEffect } from 'react';
export default function RealViewport() {
useEffect(() => {
function onWindowResize() {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
window.addEventListener('resize', onWindowResize, false);
export type Obj = Record<any, any>;
export const isArray = Array.isArray;
export const isObject = (val: unknown): val is Obj => {
return val !== null && typeof val === 'object';
};
export type StrapiAttributesObject = {
attributes: any;