Skip to content

Instantly share code, notes, and snippets.

@ginpei
ginpei / filter.js
Created December 29, 2022 11:40
Dim off items without keywords in Amazon search result
View filter.js
var words = twotabsearchtextbox.value.split(" ");
[...document.querySelectorAll(".s-result-item")]
.filter((v) => !words.every((w) => v.textContent.toLowerCase().includes(w)))
.forEach((v) => v.style.opacity = "0.3")
@ginpei
ginpei / .js
Last active October 6, 2022 21:18
Measure Express.js middleware runtime performance
View .js
const app = express();
const _use = app.use;
let numUseCalls = 0;
app.use = function(...args) {
const fn = args[args.length - 1];
// except `express.static()`
if (fn && fn.name === 'serveStatic') {
_use.apply(this, args);
View NiceListBox.tsx
import { useFocusRing } from "@react-aria/focus";
import { useListBox, useOption } from "@react-aria/listbox";
import { mergeProps } from "@react-aria/utils";
import { ListProps, ListState, useListState } from "@react-stately/list";
import { Node } from "@react-types/shared";
import { useRef } from "react";
interface ListBoxProps<T> extends ListProps<T> {
label?: string;
}
View 2.ts
interface FruitMap {
'Apple': AppleFruit;
'Banana': BananaFruit;
}
type FruitName = keyof FruitMap;
type Fruit = FruitMap[FruitName]
interface FruitBase<Type extends FruitName> {
View .ts
type FruitTemplate<Type extends string, Props> ={ type: Type } & Props
type Fruit =
| AppleFruit
| BananaFruit
type AppleFruit = FruitTemplate<'Apple', {
sliced: boolean;
peeled: boolean;
}>
View draggable.tsx
import React, {
CSSProperties, useCallback, useEffect, useMemo, useState, useRef,
} from 'react';
import Head from 'next/head';
import { Pos } from '../models/Length';
const DraggablePage: React.FC = () => {
const [dragging, setDragging] = useState(false);
const [from, setFrom] = useState<Pos>({ x: 0, y: 0 });
const [pointerType, setPointerType] = useState('');
@ginpei
ginpei / CounterPage.tsx
Last active May 6, 2023 00:01
Use React context with reducer
View CounterPage.tsx
import React, {
createContext, useReducer, useContext, useCallback,
} from 'react';
type CounterState = { count: number }
type CounterAction =
| { type: 'increment'; data: { amount: number } }
| { type: 'reset' }
View typescript-mok-mok.md

「JavaScript のまま TypeScript を始める」 + TypeScriptもくもく

JSConf Japan 2019 のセッション「JavaScript のまま TypeScript を始める」をまたお話します。30分。

セッションの後はもくもく会です。TypeScript を知ってる方も知らない方もお越しください。(知ってる方、別にメンターのような役割をして頂かなくても大丈夫です。お気軽に。)

どちらかだけの参加も歓迎します。

JavaScript のまま TypeScript を始める

View setup-firestore-emulator.md
$ firebase setup:emulators:firestore
i  firestore: downloading cloud-firestore-emulator-v1.9.0.jar... 
Progress: ===================================================> (100% of 61MB