Skip to content

Instantly share code, notes, and snippets.

View slorber's full-sized avatar
🏠
Working from home

Sébastien Lorber slorber

🏠
Working from home
View GitHub Profile
@KristofferEriksson
KristofferEriksson / useTextSelection.ts
Last active September 25, 2024 22:14
A React Typescript hook that tracks user text selections & their screen positions
import { useEffect, useState } from "react";
type UseTextSelectionReturn = {
text: string;
rects: DOMRect[];
ranges: Range[];
selection: Selection | null;
};
const getRangesFromSelection = (selection: Selection): Range[] => {
@AndrewIngram
AndrewIngram / CurrentTime.tsx
Created November 21, 2023 00:04
Current time in React without hydration errors
import { Suspense } from "react";
import CurrentTimeClient from "./CurrentTimeClient";
export default function CurrentTime() {
const locale = "en-GB";
const dateConfig = {
hour: "numeric",
minute: "numeric",
second: "numeric",
import * as React from 'react';
const useIsFirstRender = (): boolean => {
const isFirst = React.useRef(true);
if (isFirst.current) {
isFirst.current = false;
return true;
} else {
@jacob-ebey
jacob-ebey / react-use.ts
Last active December 31, 2022 00:46
A very naive implementation of React's use() hook
// A very naive implementation of React's use() hook you can copy and paste into your app today
// to use with solutions such as remix's experimental `defer()` feature.
function use<T>(useable: Promise<T> | T) {
if (typeof useable != "object" || !useable || !("then" in useable)) {
return useable;
}
let promise = useable as Promise<T> & { _data?: T; _error?: unknown };
if ("_data" in promise) {
@abhigyantrips
abhigyantrips / docusaurus-css-variables.css
Last active November 14, 2024 22:43
This is a list of all CSS variables for Docusaurus (@docusaurus/preset-classic), which uses Infima (https://infima.dev/) as its styling framework.
/*
Docusaurus CSS Variables.
I'm making this since I wanted to customize my Docusaurus site theme, but couldn't find a proper list of all Infima CSS variables
the static site generator uses. Thus, I basically copied the root of my site's CSS (along with other vars I found), and made a list
of them that categorizes the vars.
TABLE OF CONTENTS:
@tkrotoff
tkrotoff / ReactNative-vs-Flutter.md
Last active November 13, 2024 08:27
React Native vs Flutter
@olee
olee / WebGlVideoProcessor.ts
Created April 17, 2021 00:49
remotion advanced video renderer
import { continueRender, delayRender, RemotionVideoProps } from 'remotion';
import { GlslVarType, setUniform } from './glUtils';
export interface VideoShaderOptions {
variables?: {
type: GlslVarType;
name: string;
}[];
}
@sindresorhus
sindresorhus / esm-package.md
Last active November 15, 2024 15:20
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@vedam
vedam / svelte-summit-2020-summary.md
Last active February 17, 2024 12:45
links and ressources from the svelte-summit-2020 talks

You'll find the talks here


Morgan Williams @mrgnw

The Zen of Svelte

Approaching frontend as a backend developer, Svelte feels surprisingly pythonic. Let's take a quick look at what's familiar, what's foreign, and how to explore the gap.

@brunolemos
brunolemos / linkedin-unfollow-everyone.js
Last active October 4, 2024 15:43
Unfollow everyone on Linkedin
(() => {
let count = 0;
function getAllButtons() {
return document.querySelectorAll('button.is-following') || [];
}
async function unfollowAll() {
const buttons = getAllButtons();