This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useSyncExternalStore } from "react"; | |
type StoreContext<T extends object> = { | |
$set(update: Partial<T>): void; | |
$set(update: (prev: T) => Partial<T>): void; | |
}; | |
type InitialStore<T extends object> = T & ThisType<Readonly<T> & StoreContext<T>>; | |
type ListenerStore<T extends object> = (state: Readonly<T>, preview: Readonly<T>) => any; | |
type DisposeSubsribe = () => void; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Проверочка |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@description Небольшая тестовая задачка, для проверки редактора кода. | |
*/ | |
// CODE_START | |
function sum(a, b) { | |
return a + b; | |
} | |
// CODE_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createElement, forwardRef, useCallback, useLayoutEffect, useState } from "react"; | |
const URL = "https://jsonplaceholder.typicode.com/users"; | |
// Хук для работы с асинхронщиной | |
function useAsync<T>( | |
asyncFunc: () => T | Promise<T>, | |
deps: any[] = [] | |
): [ | |
data: T | null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ssh-keyscan github.com | while read line | |
do | |
grep -qxF "$line" ~/.ssh/known_hosts || echo "$line" >> ~/.ssh/known_hosts | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSignal } from "@preact/signals-react"; | |
import { runFrame, TFrameSub, useFrame } from "./useFrame"; | |
export const useCalc = <T extends TFrameSub>(calc: T) => { | |
const signal = useSignal<ReturnType<T>>(runFrame(calc)); | |
useFrame((dtime, time) => { | |
const result = calc(dtime, time); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useRef } from "react"; | |
export const useEvent = <T extends Function>(func: T) => { | |
const ref = useRef(func); | |
ref.current = func; | |
return useCallback<T>(((...args: any[]) => ref.current(...args)) as any, []); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useLayoutEffect } from "react"; | |
import { useEvent } from "./useEvent"; | |
export type TFrameSub = (dtime: number, time: number) => any; | |
const FRAME_SUBS = new Set<TFrameSub>(); | |
let lastTime = -1; | |
let lastDelta = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const isEqual = (a: any, b: any) => { | |
const toEqual: [any, any][] = [[a, b]]; | |
let iters = 0; | |
for (let j = 0; j < toEqual.length; j++) { | |
iters++; | |
const [a, b] = toEqual[j]; | |
if (a === b) continue; | |
if (a === null || b === null) |