Skip to content

Instantly share code, notes, and snippets.

@webbower
webbower / vim-cheatsheet.md
Last active July 30, 2024 18:45
Vim Learning

Vim Cheatsheet

Motions

Navigation

  • w: Move [] -> next word
  • W: Move [] -> next WORD
@webbower
webbower / ts-magic.ts
Created August 19, 2023 00:34
TypeScript Magic
/* Combined Union Type + Array of allowed values */
const ServerEnvironments = ['development', 'test', 'stage', 'production'] as const;
// equivalent to `type ServerEnvironments = 'development' | 'test' | 'stage' | 'production'
type ServerEnvironments = typeof ServerEnvironments[number];
const serverEnv: ServerEnvironments = 'development';
const isValidServerEnv = (env: string): env is ServerEnvironments => ServerEnvironments.include(env);
@webbower
webbower / module-directories.md
Last active June 5, 2023 18:38
General Coding Guidelines

Module Directories

@webbower
webbower / proto-boilerplate.js
Created March 14, 2023 23:46
JS Prototype boilerplate
const nodeCustomInspect = Symbol.for('nodejs.util.inspect.custom');
const denoCustomInspect = Symbol.for("Deno.customInspect");
const Ctor = () => ({});
Object.assign(Ctor, {
prototype: {
constructor: Ctor,
toString() {
@webbower
webbower / process-dot-env-types.ts
Created March 13, 2023 22:31
TypeScript boilerplate nonsense
export {};
/** @see https://bobbyhadz.com/blog/typescript-process-env-type */
declare global {
namespace NodeJS {
interface ProcessEnv {
// Added keys for process.env
}
}
}
@webbower
webbower / register.fn.ts
Last active October 11, 2024 15:04
Native JS extensions 😱
function before<A, B, C>(this: (a: A) => B, g: (b: B) => C): (a: A) => C {
const f = this;
return function (x) {
return g(f(x));
// return g.call(this, f.call(this, x));
};
};
function after<A, B, C>(this: (b: B) => C, g: (a: A) => B): (a: A) => C {
const f = this;
@webbower
webbower / react-hooks.test.ts
Last active July 9, 2022 00:45
Webbower Standard Library
import { describe } from 'src/utils/testing';
import { renderHook } from '@testing-library/react-hooks';
//////// useConstant.test.ts ////////
import useConstant from 'src/hooks/useConstant';
describe('useConstant()', async assert => {
const testStateValue = { value: 'abc' };
@webbower
webbower / MyComponent.d.ts
Last active November 20, 2024 23:59
Various simple utility types for improved codebase semantics
import type { FC } from 'react';
export type MyComponentProps = {
// prop types
};
const Step1: FC<MyComponentProps>;
export default MyComponent;
@webbower
webbower / combinators.js
Last active November 11, 2024 22:39
JS Utilities
/**
* Combinators
*
* @see https://en.wikipedia.org/wiki/SKI_combinator_calculus
* @see https://en.wikipedia.org/wiki/B,_C,_K,_W_system
* @see https://www.angelfire.com/tx4/cus/combinator/birds.html
* @see https://leanpub.com/combinators/read
* @see https://www.amazon.com/gp/product/B00A1P096Y
*/
@webbower
webbower / states_hash.json
Created September 11, 2021 23:22 — forked from mshafrir/states_hash.json
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",