Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
hi-ogawa / eas-cli+2.6.0.patch
Created October 31, 2022 08:13
patch-package eas-cli to test "eas build --local" without expo account
diff --git a/node_modules/eas-cli/build/commandUtils/context/DynamicProjectConfigContextField.js b/node_modules/eas-cli/build/commandUtils/context/DynamicProjectConfigContextField.js
index f59d57f..5c68793 100644
--- a/node_modules/eas-cli/build/commandUtils/context/DynamicProjectConfigContextField.js
+++ b/node_modules/eas-cli/build/commandUtils/context/DynamicProjectConfigContextField.js
@@ -11,6 +11,11 @@ class DynamicProjectConfigContextField extends ContextField_1.default {
return async (options) => {
const projectDir = await (0, findProjectDirAndVerifyProjectSetupAsync_1.findProjectDirAndVerifyProjectSetupAsync)();
const expBefore = (0, expoConfig_1.getExpoConfig)(projectDir, options);
+ return {
+ exp: expBefore,
@hi-ogawa
hi-ogawa / README.md
Last active October 27, 2022 03:07
replace star import with default import

to help migrating a code base when enabling esModuleInterop (https://www.typescriptlang.org/tsconfig#esModuleInterop)

# import * as path from "path"
#
# import path from "path"

git grep -z -l 'import \* as' | xargs -0 perl -pi -e 's/import \* as /import /g'

# only simple module name (e.g. "some-module" but not "./some-file")
@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();
}
}