Skip to content

Instantly share code, notes, and snippets.

@bigmistqke
bigmistqke / type-registry.ts
Created March 28, 2024 17:31
Monaco Auto Import Type Registry
import { Monaco } from '@monaco-editor/loader'
const regex = {
import:
/import\s+(?:type\s+)?(?:\{[^}]*\}|\* as [^\s]+|\w+\s*,\s*\{[^}]*\}|\w+)?\s+from\s*"(.+?)";?/gs,
export:
/export\s+(?:\{[^}]*\}|\* as [^\s]+|\*|\w+(?:,\s*\{[^}]*\})?|type \{[^}]*\})?\s+from\s*"(.+?)";?/gs,
require: /require\s*\(["']([^"']+)["']\)/g,
}
export class TypeRegistry {
@bigmistqke
bigmistqke / conditionals.ts
Last active September 26, 2024 13:20
utilities for conditionals in solid-js
import { Accessor } from 'solid-js'
/**
* Executes a callback with a value derived from an accessor if the value is truthy.
*
* @param accessor The value or function returning a value that is checked for truthiness.
* @param callback The callback function to be executed if the accessor's value is truthy.
* @returns The result of the callback if executed, otherwise undefined.
*/
export function when<
@bigmistqke
bigmistqke / process-props.tsx
Last active June 3, 2024 17:22
`processProps` and `defaultProps` utilities for solid-js
import { MergeProps, mergeProps, splitProps } from 'solid-js'
type KeyOfOptionals<T> = keyof {
[K in keyof T as T extends Record<K, T[K]> ? never : K]: T[K]
}
export function processProps<
TProps extends Record<string, any>,
TKey extends KeyOfOptionals<TProps>,
TSplit extends (keyof TProps)[],
@bigmistqke
bigmistqke / index.d.ts
Last active July 9, 2024 22:38
fixed solid-nativescript types
import { Style, ViewBase } from "@nativescript/core";
import {
Document,
DOMEvent,
HTMLElementTagNameMap,
Node,
NSComponentsMap,
NSCustomComponentsMap,
PseudoElementsMap,
} from "dominative";
@bigmistqke
bigmistqke / format.ts
Last active August 28, 2024 19:52
format logs
import { type JSX } from "solid-js";
const LOG_SYMBOL = Symbol("log");
type Log = [source: string, ...styles: string[]] & {
[LOG_SYMBOL]: true;
};
type ValidValue = [string, JSX.CSSProperties?] | Log;
function fragment(array: Log[]): Log {
@bigmistqke
bigmistqke / struct.ts
Created August 29, 2024 23:25
struct utility
const s = {
int64: <T extends string>(key: T) => [key, 8] as const,
uint64: <T extends string>(key: T) => [key, 8] as const,
float32: <T extends string>(key: T) => [key, 4] as const,
float64: <T extends string>(key: T) => [key, 8] as const,
int8: <T extends string>(key: T) => [key, 1] as const,
int16: <T extends string>(key: T) => [key, 2] as const,
int32: <T extends string>(key: T) => [key, 4] as const,
uint8: <T extends string>(key: T) => [key, 1] as const,
uint8clamped: <T extends string>(key: T) => [key, 1] as const,
@bigmistqke
bigmistqke / slots.tsx
Last active September 3, 2024 16:19
solid-slots
import {
children,
createRenderEffect,
type ParentProps,
onCleanup,
createMemo,
type JSX,
mergeProps,
} from "solid-js";
@bigmistqke
bigmistqke / source.tsx
Created September 25, 2024 12:06
repl @lume/element test
import { render } from "[email protected]/web"
import h from "[email protected]/h";
import { element, Element, stringAttribute } from "@lume/element"
import {createSignal} from "[email protected]"
@element("repls-repl")
class ReplElement extends Element {
@stringAttribute value = "null"
template = () => <>{this.value}</>
}
import { render } from "solid-js/web";
function format(source: string) {
if (source.endsWith("\n")) {
return source + "\n";
}
return source;
}
function unformat(source: string) {
if (source.endsWith("\n")) {
// Generated by dts-bundle-generator v9.5.1
declare class AudioSampleEntry extends SampleEntry {
channel_count: number;
samplesize: number;
samplerate: number;
constructor(type: string, size?: number);
parse(stream: MultiBufferStream): void;
/** @bundle box-codecs.js */
isAudio(): boolean;