Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
hi-ogawa / Debug.tsx
Last active October 26, 2022 08:29
Quick-and-dirty UI debugging
// @ts-ignore
function Debug(props: { data: any } & JSX.IntrinsicElements["details"]) {
const { data, ...rest } = props;
return (
<details {...rest}>
<summary onClick={() => console.log("debug", data)}>debug</summary>
<pre>{JSON.stringify(data, null, 2)}</pre>
</details>
);
}
@hi-ogawa
hi-ogawa / match-and-replace-object-literal.ts
Last active January 12, 2024 11:27
jscodeshift example (object literal manipulation)
import type { API, FileInfo } from "jscodeshift";
//
// usage:
// npx jscodeshift --parser tsx --transform match-and-replace-object-literal.ts <files>
//
// { act: "SELL", prc: 0, dt?: null, ... } => { act: "LOSS", prc: 0, dt?: null, ... }
//
export default function transformer(file: FileInfo, api: API): string {
@hi-ogawa
hi-ogawa / README.md
Created October 13, 2022 04:47
youtube internal api used by yt-dlp
@hi-ogawa
hi-ogawa / sql-keywords-uppercase.py
Last active September 16, 2022 03:11
sql-keywords-uppercase.py
import sys
import re
# found in https://en.wikipedia.org/wiki/SQL_reserved_words
# console.log(JSON.stringify(Array.from(document.querySelectorAll("table > tbody > tr > th")).map(node => node.textContent.trim())))
KEYWORDS = ["ABORT","ABORTSESSION","ABS","ABSENT","ABSOLUTE","ACCESS","ACCESSIBLE","ACCESS_LOCK","ACCOUNT","ACOS","ACOSH","ACTION","ADD","ADD_MONTHS","ADMIN","AFTER","AGGREGATE","ALIAS","ALL","ALLOCATE","ALLOW","ALTER","ALTERAND","AMP","ANALYSE","ANALYZE","AND","ANSIDATE","ANY","ARE","ARRAY","ARRAY_AGG","ARRAY_EXISTS","ARRAY_MAX_CARDINALITY","AS","ASC","ASENSITIVE","ASIN","ASINH","ASSERTION","ASSOCIATE","ASUTIME","ASYMMETRIC","AT","ATAN","ATAN2","ATANH","ATOMIC","AUDIT","AUTHORIZATION","AUX","AUXILIARY","AVE","AVERAGE","AVG","BACKUP","BEFORE","BEGIN","BEGIN_FRAME","BEGIN_PARTITION","BETWEEN","BIGINT","BINARY","BIT","BLOB","BOOLEAN","BOTH","BREADTH","BREAK","BROWSE","BT","BUFFERPOOL","BULK","BUT","BY","BYTE","BYTEINT","BYTES","CALL","CALLED","CAPTURE","CARDINALITY","CASCADE","CASCADED","CASE","CA
@hi-ogawa
hi-ogawa / useIntersectionObserverEntry.ts
Created September 14, 2022 05:32
useIntersectionObserverEntry
// const ref = useIntersectionObserverEntry(entry => console.log(entry))
// return <div ref={ref}>...</div>
function useIntersectionObserverEntry(
callback: (value?: IntersectionObserverEntry) => void
): React.RefCallback<Element> {
const observerRef = React.useRef<IntersectionObserver>();
const callbackRef = React.useRef<typeof callback>(callback);
callbackRef.current = callback;
@hi-ogawa
hi-ogawa / useResizeObserverCallback.ts
Created August 29, 2022 07:50
useResizeObserverCallback.ts
function useResizeObserverCallback(callback: ResizeObserverCallback) {
const observerRef = React.useRef<ResizeObserver>();
const callbackStable = React.useRef(callback);
callbackStable.current = callback;
// return ref callback to setup/teardown the effect
return function refCallback(el: Element | null) {
let observer = observerRef.current;
@hi-ogawa
hi-ogawa / README.md
Created August 27, 2022 07:23
reading-vite

reading vite

  • default plugins packages/vite/src/node/plugins/index.ts
    • aliasPlugin (e.g. @vite/client (packages/vite/src/node/config.ts))
    • resolvePlugin
    • esbuildPlugin
    • buildHtmlPlugin
    • importAnalysisPlugin
      • update module node metadata by statically analyzing import statements and import.meta.hot
      • transform import "some-dep" to import "some-dep?t=${lastHMRTimestamp}" when some-dep is modified before
@hi-ogawa
hi-ogawa / github-pr-load-diff.js
Last active July 13, 2022 03:09
Github PR diff view auto loading
const PREFIX = "xxx";
for (const node of document.querySelectorAll('div[data-targets="diff-file-filter.diffEntries"]')) {
const file = node.getAttribute("data-tagsearch-path");
const button = node.querySelector("button.load-diff-button");
if (button && file.startsWith(PREFIX)) {
button.click();
}
}
@hi-ogawa
hi-ogawa / README.md
Last active August 26, 2022 03:52
reading-chromium

reading-chromium

todo

  • building
  • testing
    • unit tests
      • blink
      • content
  • web tests
@hi-ogawa
hi-ogawa / typescript-transformer-example.ts
Created May 29, 2022 13:26
typescript-transformer-api
/* eslint-disable no-console */
import * as fs from "fs";
import * as process from "process";
import * as ts from "typescript";
//
// analyze statements of the following forms:
//
// const someVariable = someFunction(someObjectLiteral)