Skip to content

Instantly share code, notes, and snippets.

@uptonking
uptonking / cm-enhanced-search-field.js
Created October 8, 2024 07:02 — forked from andy0130tw/cm-enhanced-search-field.js
CodeMirror with a search field that is another CodeMirror instance!
import { basicSetup, minimalSetup } from 'codemirror'
import { Prec } from '@codemirror/state'
import { EditorView, keymap, placeholder } from '@codemirror/view'
import { search, findNext, findPrevious } from '@codemirror/search'
const SearchPanel = (() => {
const searchConfigFacet = search({})[0].facet
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width"/>
</head>
<body style="height: 300vh">
<svg style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);"
width="655" height="209" viewBox="0 0 655 209" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M653 207V62C653 28.8629 626.228 2 593.091 2C519.318 2 391.639 2 292.675 2C270.583 2 252.717 19.9124 252.717 42.0038C252.717 63.5378 252.717 81.7221 252.717 81.7221C252.717 81.7221 252.717 81.7221 252.717 81.7221V167C252.717 189.091 234.808 207 212.717 207H2"
stroke="#EAECF0" stroke-width="4" stroke-linecap="round"/>
@uptonking
uptonking / javascript_engines_and_runtimes.md
Created March 29, 2024 12:26 — forked from guest271314/javascript_engines_and_runtimes.md
A list of JavaScript engines, runtimes, interpreters

V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. V8 can run standalone, or can be embedded into any C++ application.

SpiderMonkey is Mozilla’s JavaScript and WebAssembly Engine, used in Firefox, Servo and various other projects. It is written in C++, Rust and JavaScript. You can embed it into C++ and Rust projects, and it can be run as a stand-alone shell. It can also be [compiled](https://bytecodealliance.org/articles/making-javascript-run-fast-on

@uptonking
uptonking / hyperapp-reference.md
Created March 17, 2024 13:29 — forked from skanne/hyperapp-reference.md
A reference of Hyperapp 2 actions, effects and subscriptions and how they are declared and used.

Hyperapp 2 – Actions, Effects and Subscriptions

Learn about the function signatures of actions, effects, and subscriptions in Hyperapp 2 and how they are used in apps.

Actions

Actions:

  • Are declared as constant arrow functions (const ActionFunction = (s, p) => ns).
  • Should have names written in PascalCase .
@uptonking
uptonking / closure_table.md
Created October 23, 2023 12:49 — forked from kovid-rathee/closure_table.md
Persistent tree structure using closure table in MySQL

Using closure tables to manage hierarchical relations in MySQL

Create DB tables

Create a table to represent tree nodes.

CREATE TABLE `tree_node` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `data_body` text,

node_deleted datetime DEFAULT NULL,

@uptonking
uptonking / Basic API call (TypeScript).EXCEL.yaml
Created August 18, 2023 17:16
Performs a basic Excel API call using TypeScript.
name: Basic API call (TypeScript)
description: Performs a basic Excel API call using TypeScript.
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
import json1 from 'ot-json1'
const integerRegEx = /^\d+$/
function isInteger (v) {
return Boolean(v.match(integerRegEx))
}
export function patchAtomToOpAtom (patchOp) {
const { path, op, value } = patchOp
const pathArray = path.split('/').slice(1).map(pathItem => {
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@uptonking
uptonking / MarkdownField.ts
Created January 24, 2023 23:31 — forked from oranoran/MarkdownField.ts
Payload CMS - alternative rich text editor using rich-markdown-editor
import React, { useCallback, FunctionComponent } from 'react'
import { useField } from 'payload/components/forms'
import { Field } from 'payload/types'
import Editor from 'rich-markdown-editor'
// Make sure to never re-render the editor, since it tracks the value on its own.
const MemorizedEditor = React.memo(Editor, (prev, next) => prev.id === next.id)
type FieldWithPath = Field & { path?: string }
@uptonking
uptonking / proposal.jsx
Created January 2, 2023 11:11 — forked from jamesmfriedman/proposal.jsx
MDC Foundation Proposal
/**
* Current Adapter Example
* This is a simple adapter, some are extremely complex...
* It is not immediately obvious why some code lives in the adapter and some in the foundation
* The Select alone is over 700 lines of component logic...
**/
MDCCheckboxFoundation({
addClass: (className) => this.root_.classList.add(className),
removeClass: (className) => this.root_.classList.remove(className),
setNativeControlAttr: (attr, value) => this.nativeCb_.setAttribute(attr, value),