Skip to content

Instantly share code, notes, and snippets.

View 8mist's full-sized avatar

Grégoire Ciles 8mist

View GitHub Profile
@8mist
8mist / spanify.js
Last active November 16, 2022 08:18
const createSpan = (text) => {
const node = document.createElement("span");
node.textContent = text;
return node;
};
const insertBetweenElementWhitespace = (elements) =>
elements.reduce((acc, span) => acc.concat(span, " "), []).slice(0, -1);
const spanifyText = text => {
export type RecursiveKeyOf<
TObj,
TPrefix extends string = ''
> = TObj extends Record<string, any>
? {
[K in keyof TObj & string]:
| `${TPrefix}${K}`
| RecursiveKeyOf<TObj[K], `${TPrefix}${K}.`>;
}[keyof TObj & string]
: never;
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;
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);
import React from 'react'
const IS_SERVER = typeof window === 'undefined'
export const useIsomorphicLayoutEffect = IS_SERVER
? React.useEffect
: React.useLayoutEffect
@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;
const debounceToNextFrame = <F extends (...args: any[]) => void>(
fn: F,
): ((...funcArgs: Parameters<F>) => void) & {
cancel: () => void;
} => {
let frameReference: number;
const cancel = (): void => {
cancelAnimationFrame(frameReference);
};
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)
@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]],
@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