Skip to content

Instantly share code, notes, and snippets.

View franky47's full-sized avatar

François Best franky47

View GitHub Profile
@franky47
franky47 / reduceTree.ts
Created November 29, 2021 15:24
Recursion-free, depth-first object traversal à la `reduce`.
/**
* Traverse a JSON object depth-first, in a `reduce` manner.
*
* License: MIT © 2021 François Best (https://francoisbest.com)
*
* @param input The root node to traverse
* @param callback A function to call on each visited node
* @param initialState Think of this as the last argument of `reduce`
*/
export function reduceTree<State>(
@franky47
franky47 / chakra-colors.json
Created April 21, 2021 16:30
ChakraUI Palette Mod - Increased Saturation & Luminosity
{
"colors": {
"green": {
"50": "#ECF8EF",
"100": "#CBECD2",
"200": "#A9DFB6",
"300": "#88D399",
"400": "#66C77C",
"500": "#45BA60",
"600": "#37954D",
@franky47
franky47 / list-tweet-urls.js
Created March 19, 2021 10:46
List all the Tweet URLs on the page
Array.from(
new Set(
// List all links on the page
Array.from(document.getElementsByTagName('a'))
.filter(a =>
// Only keep status URLs
a.href.match(/^https:\/\/twitter\.com\/(\w+)\/status\/(\d+)$/)
)
.map(a => a.href) // Keep only the link URL
) // new Set: remove duplicates
@franky47
franky47 / EmojiFavicon.tsx
Created February 16, 2021 14:16
Emoji Favicon with badge
import React from 'react'
export interface EmojiFaviconProps {
emoji: string
badgeEmoji?: string
}
export const EmojiFavicon: React.FC<EmojiFaviconProps> = ({ emoji, badgeEmoji }) => {
const inlineSvg = React.useMemo(() => {
return `
@franky47
franky47 / usePasteAnywhere.ts
Created February 10, 2021 07:17
usePasteAnywhere
import * as React from 'react'
export function usePasteAnywhere(callback: (text: string) => void) {
React.useEffect(() => {
const body = document.getElementsByTagName('body')[0]
const onPaste = (e: ClipboardEvent) => {
const data = e.clipboardData?.getData('text/plain')
if (data) {
callback(data)
}
@franky47
franky47 / feeds.md
Created May 30, 2020 12:27
My favourite tech blogs RSS feeds
@franky47
franky47 / typescriptreact.json
Last active December 9, 2020 07:52
VSCode Snippets for Next.js + ChakraUI components
{
"Create functional component": {
"prefix": "fct",
"body": [
"export interface ${1:Component}Props {",
"",
"}",
"",
"export const ${1:Component}: React.FC<${1:Component}Props> = ({ ...props }) => {",
" return (",
@franky47
franky47 / use100vh.js
Created January 11, 2020 07:44
React hook to fix the 100vh issue on mobile Chrome and Safari
import React from 'react';
import { useWindowSize } from 'react-use';
// 100vh is broken on mobile (Chrome, Safari):
// https://chanind.github.io/javascript/2019/09/28/avoid-100vh-on-mobile-web.html
export default function use100vh() {
const ref = React.useRef();
const { height } = useWindowSize();
@franky47
franky47 / rfc-styles.js
Created November 26, 2019 13:34
Make RFCs easier to read
document.querySelector('.content').setAttribute("style", "margin:0 auto;font-size:16px;line-height:1.4;color:#333")
@franky47
franky47 / useDerivedState.ts
Last active August 7, 2025 01:01
React useDerivedState hook
import React from 'react'
const useDerivedState = <T>(derive: () => T, deps: any[]): T => {
const [value, setValue] = React.useState<T>(derive)
React.useEffect(() => {
setValue(derive())
}, deps)
return value
}