Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
hi-ogawa / wrapConsoleTimeAsync.ts
Created November 28, 2023 08:27
wrapConsoleTimeAsync.ts
function wrapConsoleTimeAsync<F extends (...args: any[]) => any>(f: F) {
const wrapper = async function (this: any, ...args: any[]) {
const id = Math.random().toString(36).slice(2).padStart(12, "0");
const label = `${f.name}:${id}`;
globalThis.console.time(label);
try {
return await f.apply(this, args);
} finally {
globalThis.console.timeEnd(label);
}
@hi-ogawa
hi-ogawa / README.md
Last active November 14, 2023 04:23
remix development tips
@hi-ogawa
hi-ogawa / intl-extract.ts
Created August 22, 2023 06:57
intl-extract.ts by jscodeshift
/* eslint-disable no-console */
import type { API, FileInfo } from "jscodeshift";
import * as recast from "recast";
export default function transformer(file: FileInfo, api: API): string | undefined {
const j = api.jscodeshift;
const $j = j(file.source);
const result: {
@hi-ogawa
hi-ogawa / README.md
Last active June 14, 2023 00:18
worker with javascript data url
@hi-ogawa
hi-ogawa / README.md
Last active May 30, 2023 05:16
follow up after github squash merge

scenario

  • y: main
  • z: PR-1
  • w: PR-2 (based on PR-1)
x - y
  \ 
 z - w
@hi-ogawa
hi-ogawa / createReactQueryOptionsProxy.ts
Last active May 20, 2023 07:36
createReactQueryOptionsProxy.ts
//
// generate type-safe react-query options wrapper from a record of async functions
//
type FnRecord = Record<string, (input: unknown) => unknown>;
type FnInput<F extends (input: unknown) => unknown> = Parameters<F>[0];
type FnOutput<F extends (input: unknown) => unknown> = Awaited<ReturnType<F>>;
type ReactQueryOptionsProxy<T extends FnRecord> = {
[K in keyof T]: {
@hi-ogawa
hi-ogawa / README.md
Created May 11, 2023 13:18
prefers-color-scheme override cdp

Override prefers-color-scheme via CDP

let Main = await import('./entrypoints/main/main.js')
await Main.MainImpl.sendOverProtocol("Emulation.setEmulatedMedia", { features: [{ name: "prefers-color-scheme", value: "dark" }] })

references

@hi-ogawa
hi-ogawa / prop-path-map.ts
Created April 30, 2023 10:23
prop-path-map.ts
type PropKey = string | number;
type PropValue = null | undefined | number | boolean | string | Date;
export function toPropPathMap(input: unknown) {
const output = new Map<PropKey[], PropValue>();
function traverse(v: unknown, keys: PropKey[]) {
// prettier-ignore
if (
typeof v === "undefined" ||
@hi-ogawa
hi-ogawa / hangle-syllables.js
Last active February 28, 2023 10:39
List hangul syllables
/*
$ node hangle-syllables.js
가 : ㄱ ㅏ
각 : ㄱ ㅏ ㄱ
갂 : ㄱ ㅏ ㄲ
갃 : ㄱ ㅏ ㄳ
간 : ㄱ ㅏ ㄴ
갅 : ㄱ ㅏ ㄵ
갆 : ㄱ ㅏ ㄶ
@hi-ogawa
hi-ogawa / bin-gist.sh
Last active December 26, 2022 07:46
download shell script from gist and install it locally
#!/bin/bash
set -eu -o pipefail
#
# something similar to https://github.com/marcosnils/bin but for simple shell scripts on gist
#
# usage:
# bash bin-gist.sh https://gist.github.com/hi-ogawa/1e0b1a147e883aad41f97c68246f3c33 bin-gist.sh
# bash bin-gist.sh https://gist.github.com/hi-ogawa/bca49e90241f7808127a430f986d33ea passphrase.sh
#