Skip to content

Instantly share code, notes, and snippets.

View childrentime's full-sized avatar
🎯
Focusing

Berlin childrentime

🎯
Focusing
  • ShangHai
  • 15:18 (UTC +08:00)
View GitHub Profile

This demonstrates the implementation of full text search for documents in Indexed DB.

  • Word-breaking and stemming is used to create a list of terms for each document.
  • Document records are annotated with the list of terms when added to the database.
  • A multi-entry index on the list of terms is populated.
  • A query is similarly processed into a list of terms.
  • A join over the terms is implemented using multiple cursors on the index.

The necessity of annotating records with the word list to populate the index is a limitation of the current Indexed DB API. A feature request to support custom

@childrentime
childrentime / gist:d4d43672fad2a0bf3dda35fda290dbc1
Created October 30, 2023 09:45
Nodejs Thread Concurrency
import { fileURLToPath } from "node:url";
import { Worker, isMainThread, workerData } from "worker_threads";
const __filename = fileURLToPath(import.meta.url);
if (isMainThread) {
const sharedBuffer = new SharedArrayBuffer(1 * Int32Array.BYTES_PER_ELEMENT);
const sharedArray = new Int32Array(sharedBuffer);
const worker1 = new Worker(__filename, { workerData: sharedBuffer });
@childrentime
childrentime / index.ts
Created August 30, 2023 14:30
react useSyncExternalStore
import { useCallback, useRef, useSyncExternalStore } from "react";
const useThirdPartyStore = () => {
const symbolRef = useRef(Symbol());
const storeChangeRef = useRef<() => void>();
const subscribe = useCallback((storeChange: () => void) => {
storeChangeRef.current = storeChange;
return () => {
storeChangeRef.current = undefined;
const originState: unique symbol = Symbol.for("origin-state");
const arrayHandlers: ProxyHandler<
Array<any> & { [originState]: ObservableArray }
> = {
set(target, prop, value): boolean {
console.log("set exec");
const observableArray = target[originState];
const result = Reflect.set(target, prop, value);
/**