Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
hi-ogawa / README.md
Created October 23, 2024 06:56
Delete ghost notification
@hi-ogawa
hi-ogawa / main.js
Last active October 17, 2024 09:06
generate a link to evanw's source-map-visualization
// https://github.com/oxc-project/oxc/blob/a6487482bc053797f7f1a42f5793fafbd9a47114/crates/oxc_codegen/examples/sourcemap.rs#L34-L44
function generate(code, mapJson) {
const hashRaw = `${code.length}\0${code}${mapJson.length}\0${mapJson}`;
// const hash = btoa(hashRaw);
const hash = Buffer.from(hashRaw, "utf-8").toString("base64");
return `https://evanw.github.io/source-map-visualization/#` + hash;
}
console.log(generate(result.code, JSON.stringify(result.map)))
@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" ||