Skip to content

Instantly share code, notes, and snippets.

View fnky's full-sized avatar
⚠️
TypeError: Cannot read property 'status' of undefined.

Christian Petersen fnky

⚠️
TypeError: Cannot read property 'status' of undefined.
View GitHub Profile
@fnky
fnky / ANSI.md
Last active December 7, 2023 04:51
ANSI Escape Codes
View ANSI.md

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@fnky
fnky / stripe-keys-and-ids.tsv
Last active December 2, 2023 21:31
Stripe keys and IDs
View stripe-keys-and-ids.tsv
Prefix Description Notes
ac_ Platform Client ID Identifier for an auth code/client id.
acct_ Account ID Identifier for an Account object.
aliacc_ Alipay Account ID Identifier for an Alipay account.
ba_ Bank Account ID Identifier for a Bank Account object.
btok_ Bank Token ID Identifier for a Bank Token object.
card_ Card ID Identifier for a Card object.
cbtxn_ Customer Balance Transaction ID Identifier for a Customer Balance Transaction object.
ch_ Charge ID Identifier for a Charge object.
cn_ Credit Note ID Identifier for a Credit Note object.
@fnky
fnky / react-web-resources.md
Last active November 24, 2023 15:04
Web/React Resources (Last updated Nov 3, 2022)
View react-web-resources.md
@fnky
fnky / promise-tuple.js
Last active November 18, 2023 10:32
Retrieve tuples from Promise results / async functions
View promise-tuple.js
/**
* Returns a Promise which resolves with a value in form of a tuple.
* @param promiseFn A Promise to resolve as a tuple.
* @returns Promise A Promise which resolves to a tuple of [error, ...results]
*/
export function tuple (promise) {
return promise
.then((...results) => [null, ...results])
.catch(error => [error])
}
@fnky
fnky / login.tsx
Last active November 12, 2023 11:11
Remix Form validation with zod
View login.tsx
import { json, ActionFunction, useActionData, Form } from "remix";
import { z } from "zod";
// This type infer errors from a ZodType, as produced by `flatten()` of a parsed schema.
type inferSafeParseErrors<T extends z.ZodType<any, any, any>, U = string> = {
formErrors: U[];
fieldErrors: {
[P in keyof z.infer<T>]?: U[];
};
};
@fnky
fnky / variable-fonts.md
Last active November 1, 2023 18:13
Awesome Variable Fonts
View variable-fonts.md

Awesome Variable Fonts

A list of open source and free* variable fonts.

* Some fonts may require a license to be used for commerical use.

Open Source

@fnky
fnky / hooks.js
Last active October 24, 2023 07:03
React Hooks: useReducer with actions and selectors (Redux-like)
View hooks.js
function useSelectors(reducer, mapStateToSelectors) {
const [state] = reducer;
const selectors = useMemo(() => mapStateToSelectors(state), [state]);
return selectors;
}
function useActions(reducer, mapDispatchToActions) {
const [, dispatch] = reducer;
const actions = useMemo(() => mapDispatchToActions(dispatch), [dispatch]);
return actions;
@fnky
fnky / README.md
Last active June 21, 2023 16:50
Activate the power chime sound effect. For MacBook Pro and MacBook Air
View README.md

Power Chime

To activate the sound effect

$ defaults write com.apple.PowerChime ChimeOnAllHardware -bool true; open /System/Library/CoreServices/PowerChime.app &

Do deactivate it, simply change the ChimeOnAllHardware boolean to false.

@fnky
fnky / news.ycombinator.com.css
Last active January 13, 2023 23:32
Stylus Dark theme for Hacker News
View news.ycombinator.com.css
:root {
--color-scale-black: hsl(0, 0%, 3.5%);
--color-scale-white: #ffffff;
--color-scale-gray-1: hsl(0, 0%, 8.5%);
--color-scale-gray-2: hsl(0, 0%, 11.0%);
--color-scale-gray-3: hsl(0, 0%, 13.6%);
--color-scale-gray-4: hsl(0, 0%, 15.8%);
--color-scale-gray-5: hsl(0, 0%, 17.9%);
--color-scale-gray-6: hsl(0, 0%, 20.5%);
--color-scale-gray-7: hsl(0, 0%, 24.3%);
@fnky
fnky / use-toggle.ts
Created May 13, 2022 12:29
Simple toggle hook using useReducer w/ types for reducer with optional action.
View use-toggle.ts
import React from "react";
type ReducerWithOptionalAction<S> = (prevState: S, action?: S) => S;
type ReducerStateWithOptionalAction<S> = React.ReducerState<ReducerWithOptionalAction<S>>;
type DispatchWithOptionalAction<S> = React.Dispatch<S> & React.DispatchWithoutAction;
type ReducerValueWithOptionalAction<S> = [
ReducerStateWithOptionalAction<S>,
React.DispatchWithOptionalAction<S>,
];