Skip to content

Instantly share code, notes, and snippets.

View franky47's full-sized avatar

François Best franky47

View GitHub Profile
@franky47
franky47 / sysex-queue.ino
Last active August 2, 2023 06:32
Message queue to print incoming SysEx
#include <MIDI.h>
#include <string.h>
MIDI_CREATE_DEFAULT_INSTANCE();
template<unsigned Size, typename DataType>
struct MessageQueue {
static constexpr unsigned sMask = Size - 1;
inline MessageQueue<Size, DataType>()
@franky47
franky47 / settings.json
Created February 17, 2022 01:15
VSCode experimental file nesting configuration
{
"explorer.experimental.fileNesting.enabled": true,
"explorer.experimental.fileNesting.patterns": {
"*.ts": "$(capture).js, $(capture).d.ts, $(capture).test.ts",
"*.js": "$(capture).js.map, $(capture).min.js, $(capture).d.ts, $(capture).test.js",
"*.jsx": "$(capture).js",
"*.tsx": "$(capture).ts, $(capture).*.ts, $(capture).*.tsx",
"tsconfig.json": "tsconfig.*.json",
"docker-compose.yml": "docker-compose.*.yml",
".env": ".env.*",
@franky47
franky47 / stripe-webhooks.ts
Created December 21, 2021 09:44
Strongly-typed webhook handlers for Stripe (Node.js)
import type { Stripe } from 'stripe'
export type StripeWebhookEventTypes =
Stripe.WebhookEndpointCreateParams.EnabledEvent
export type StripeWebhookEvent<
EventType extends StripeWebhookEventTypes,
Payload
> = {
eventType: EventType
@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 (",